serving icon indicating copy to clipboard operation
serving copied to clipboard

GetModelMetaData and automatic configuration of tf.example input nodes

Open bknl opened this issue 9 years ago • 5 comments

My apologies if this is not the right venue, I have crossposted my problem on StackOverflow here. am writing a TensorFlow Serving client in C++ that sits inside a database server and makes TensorFlow models available as database procedures. The whole machinery autoconfigures the data types and necessary conversions between database tables and inputa and output tensors based on the responses it retrieves from TensorFlow Serving modelservers via the GetModelMetaData request/response mechanism.

So far I have used "raw" input tensors to talk to various models (Inception_v3, various regression models). By "raw" I mean that the values for the input tensors are the plain datatypes requested by the model in contrast to values wrapped as tf.example records.

For illustration, looking at the "half_plus_two" model from the TensorFlow Serving examples section. It expects an "x" float input and returns a "y" float output. It features both a "raw" input mode in the "serving_default" signature, as well as a "wrapped" one in the "classify_x_to_y" signature:

(Excerpt from the GetModelMetaData response: GetModelMetaDataResponse.txt )

While I can automatically deduce what tensor to create for the explicitly specified "raw" tensor (i.e. a vector of floats), I have no good way to figure out what to put into the serialized tf.example record that the "classify_x_to_y" signature wants (reading the textual description I know of course that it wants a tf.example with a float value under the key 'x', the question is, how is one supposed to automatically deduce that from the GetModelMetaDataResponse above ?

bknl avatar Jul 13 '17 12:07 bknl

GetModelMetaDataResponse does not include sufficient information to determine how to construct a valid tf.Example input. (GetModelMetaData was never designed for that purpose.) Unfortunately I don't think there's an easy+general way of extending it for that use-case. You may need to look into other metadata you can associate with models in the database itself.

chrisolston avatar Jul 13 '17 20:07 chrisolston

Ok, thanks Chris,

I figured as much. So, generally speaking, the overall feeling I have is that the whole tf.Example machinery is mostly geared towards file based input to TensorFlow during training, where you want to keep related data items, not all of which are strictly necessary for a given task together and just have TensorFlow "pick" its stuff (typically in training), while the "raw" tensor inputs (for which there is enough information in GetModelMetaData, at least for my purposes) are for "lean" calls, particularly during inference ?

I ask because this means I'll have to "fix" this mostly in documentation for the data scientists/programmers preparing the models and their metadata so that I can give them guidance. Sorry for expanding the scope of the question so broadly, but you seem to have quite a bit of history with the project....

bknl avatar Jul 14 '17 06:07 bknl

No, tf.Example is used extensively (although not exclusively) for both training and serving. For inference you can use either tf.Example (with the Classify or Regress API) or raw tensors (with the Predict API). Of course even with raw tensors you need to know things like what datatype to use (is it a tensor of floats or ??) and how many dimensions are expected, etc. If, in your use-case, your users are giving you Tensors then you could just ignore those issues, assume the Tensors are well-formed, and use the Predict API (see PredictRequest/PredictResponse).

chrisolston avatar Jul 14 '17 12:07 chrisolston

Thanks for the background information (and it cleared up something that we were wondering about when staring at the Classify and Regress APIs). In my case I cannot just assume that my users are giving me Tensors but rather the problem is exactly that I have to give them means to convert from their data world (SQL tables and datatypes in a relational database) to Tensors (and back).

As the information about what is expected for the tf.example cases can not be gleaned from GetModelMetaData but only from the code of the model itself, we'll try to work from there.

bknl avatar Jul 18 '17 11:07 bknl

Closing due to staleness. If this is still an issue, please file a new updated issue with current steps to reproduce the bug. If this is a question, please ask it on:

https://stackoverflow.com/questions/tagged/tensorflow-serving

Thanks!

gautamvasudevan avatar Aug 03 '18 20:08 gautamvasudevan