Hi,
Starting from a comment in issue https://github.com/tensorflow/serving/issues/1248#issuecomment-501891571 I had a look at defining a custom signature to "serve" some model metadata. I'm using TF2.2 (Python 3.7) and TF serving 2.2 (docker image).
One could export the model like that:
features = ['a', 'b']
m = tf.Module()
m.features = tf.function(lambda: features, input_signature=())
tf.saved_model.save(m, r'c:\temp\model\0', signatures={'get_features': m.features})
expose it via tf serving and query it via the rest API:
curl -d '{"signature_name": "get_features"}' \
-X POST http://localhost:8501/v1/models/model:predict
The request however fails:
{
"error": "Failed to get input map for signature: get_features"
}
It turns out this happens because the input_signature is empty and tf serving throws when this happens (see here).
If using a dummy input variable, the request succeeds:
features = ['a', 'b']
m = tf.Module()
m.features = tf.function(lambda x: features, input_signature=[tensor_spec.TensorSpec([])])
tf.saved_model.save(m, r'c:\temp\model\0', signatures={'get_features': m.features})
```bash
curl -d '{"signature_name": "get_features", "inputs": {"x": []}}' \
-X POST http://localhost:8501/v1/models/model:predict
yields:
```json
{
"outputs": {
"output_0": "a",
"output_1": "b"
}
}
I believe that adding a dummy input to the signature is confusing, what about allowing empty input signatures instead? Is there any other way to make the requests succeed without having to add a dummy input?
Best Regards,
Marco
The input_signature should not be empty, it should be a sequence of tf.TensorSpec objects specifying the shapes and dtypes of the Tensors that will be supplied to this function (see https://www.tensorflow.org/api_docs/python/tf/function#args_1).
@marcoadurno Closing this issue as it has been resolved. Please add additional comments to open this issue again. Thanks!
I also agree that having to supply a dummy argument is at very best clunky. Is there any way to export a function that has no arguments to its input signature?