Classification signature with multiple inputs
Is there a way to specify multiple tensors into the Classification signature?
Eg, today you can do,
signature = exporter.classification_signature(input_tensor=model.input,
scores_tensor=model.output)
but not
signature = exporter.classification_signature(input_tensor=[model.input, my_other_tensor],
scores_tensor=model.output)
I did see there's a generic_signature function which can be used like
named_tensor_bindings = {"logical_input_A": v0,
"logical_input_B": v1}
signatures = {
"generic": exporter.generic_signature(named_tensor_bindings)}
But this seems to be useful only when a single input is used for multiple outputs. I realize that in a classification system, only one tensor is used - but what if I wanted to have two tensors that are eventually concatenated using a graph model?
Secondly.
When exporter.init() is run with sess.graph.as_graph_def() and signature as params - is the model now only capable of being invoked using this signature?
For instance, what if my model can take multiple inputs, and I export it via Serving - am I now constrained by what the classification_signature can take?
Hi viksit@, Think of the signatures as annotations on the graph used for serving. They don't modify or constrain the graph in any way, so you can use it however you like. Although there is only one default signature, you can also have arbitrarily many named signatures. This can help if, for example, you want to experiment by taking outputs from different layers of a graph, but keep your code that runs inference the same.
For concatenating tensors, I think you would need to create a tensor in the graph that does the concatenation, and then reference that new single tensor, to get the behavior (I think) you are looking for in the first question.
Hope this helps. Thanks! Noah
Thanks, @nfiedel. Makes sense.
But to reiterate - there's no way to actually change the signature to use two or more input tensors right now (not output)? Given everything is around "Classification"?
Hi viksit@, That's right (for now). If you have different input/output patterns, you can easily use the generic_signature to capture named inputs & outputs.
Related to the multiple input question would be how to deal with passing in an is_training value (presumably to False) in order to disable dropout, etc. When training validating, I use the feed dict to set this.
is there a new solution to this problem? Generic_signature is deprecated
Yes. You can use a Predict SignatureDef with the Predict API. See https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/signature_defs.md for more details.
@kirilg With the predict API, using multiple inputs does not work. I constructed a toy example similar to this with a simple operation.. When I only have one input, things work fine, but if I construct the graph such that it accepts 2 placeholders following a concat operation, with the appropriate output. I get an error that I must feed a placeholder value.
$saved_model_cli run --dir /tmp/saved_model_dir --tag_set serve
--signature_def x1_x2_to_y --inputs x1=/tmp/my_data1.npy;x2=/tmp/my_data2.npy
--outdir /tmp/out
Let's follow up on the saved_model_cli issue in the other issue you filed (https://github.com/tensorflow/serving/issues/702 for posterity).