0

I ran the example tutorial (link below) for creating a tfx pipeline using native keras based on the iris data set. I was able to create and save a Tensorflow model.

https://github.com/tensorflow/tfx/blob/master/tfx/examples/iris/iris_pipeline_native_keras.py

I'm trying to query the trained model using the predict API Tensorflow serving with Docker. I can't figure out the post API request for it.

I tried following command but it didn't work.

curl -d '{"instances": [7.7,3.0,6.1,2.3]}' \
    -X POST http://localhost:8501/v1/models/iris_example:predict

The model's metadata is as follows

{
    "model_spec": {
        "name": "iris_cpu",
        "signature_name": "",
        "version": "1595575737"
    },
    "metadata": {
        "signature_def": {
            "signature_def": {
                "serving_default": {
                    "inputs": {
                        "examples": {
                            "dtype": "DT_STRING",
                            "tensor_shape": {
                                "dim": [],
                                "unknown_rank": true
                            },
                            "name": "serving_default_examples:0"
                        }
                    },
                    "outputs": {
                        "output_0": {
                            "dtype": "DT_FLOAT",
                            "tensor_shape": {
                                "dim": [
                                    {
                                        "size": "-1",
                                        "name": ""
                                    },
                                    {
                                        "size": "3",
                                        "name": ""
                                    }
                                ],
                                "unknown_rank": false
                            },
                            "name": "StatefulPartitionedCall:0"
                        }
                    },
                    "method_name": "tensorflow/serving/predict"
                },
                "__saved_model_init_op": {
                    "inputs": {},
                    "outputs": {
                        "__saved_model_init_op": {
                            "dtype": "DT_INVALID",
                            "tensor_shape": {
                                "dim": [],
                                "unknown_rank": true
                            },
                            "name": "NoOp"
                        }
                    },
                    "method_name": ""
                }
            }
        }
    }
}

output from running saved_model_cli command

!saved_model_cli show --dir {export_path} --all

output:

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['__saved_model_init_op']:
  The given SavedModel SignatureDef contains the following input(s):
  The given SavedModel SignatureDef contains the following output(s):
    outputs['__saved_model_init_op'] tensor_info:
        dtype: DT_INVALID
        shape: unknown_rank
        name: NoOp
  Method name is: 

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['examples'] tensor_info:
        dtype: DT_STRING
        shape: (-1)
        name: serving_default_examples:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['output_0'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 3)
        name: StatefulPartitionedCall:0
  Method name is: tensorflow/serving/predict
WARNING:tensorflow:From /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:1817: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2020-07-24 13:41:05.819053: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-07-24 13:41:05.836906: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fac87ae5560 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-24 13:41:05.836934: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version

Defined Functions:
  Function Name: '__call__'
    Option #1
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_width_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_width_xf')]
        Argument #2
          DType: bool
          Value: False
        Argument #3
          DType: NoneType
          Value: None
    Option #2
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/0'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/1'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/2'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/3')]
        Argument #2
          DType: bool
          Value: False
        Argument #3
          DType: NoneType
          Value: None
    Option #3
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_width_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_width_xf')]
        Argument #2
          DType: bool
          Value: True
        Argument #3
          DType: NoneType
          Value: None
    Option #4
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/0'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/1'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/2'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/3')]
        Argument #2
          DType: bool
          Value: True
        Argument #3
          DType: NoneType
          Value: None

  Function Name: '_default_save_signature'
    Option #1
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_width_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_width_xf')]

  Function Name: 'call_and_return_all_conditional_losses'
    Option #1
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/0'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/1'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/2'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/3')]
        Argument #2
          DType: bool
          Value: True
        Argument #3
          DType: NoneType
          Value: None
    Option #2
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_width_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_width_xf')]
        Argument #2
          DType: bool
          Value: False
        Argument #3
          DType: NoneType
          Value: None
    Option #3
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='sepal_width_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_length_xf'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='petal_width_xf')]
        Argument #2
          DType: bool
          Value: True
        Argument #3
          DType: NoneType
          Value: None
    Option #4
      Callable with:
        Argument #1
          DType: list
          Value: [TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/0'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/1'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/2'), TensorSpec(shape=(None, 1), dtype=tf.float32, name='inputs/3')]
        Argument #2
          DType: bool
          Value: False
        Argument #3
          DType: NoneType
          Value: None
!saved_model_cli show --dir {export_path} --tag_set serve --signature_def serving_default

output:

The given SavedModel SignatureDef contains the following input(s):
  inputs['examples'] tensor_info:
      dtype: DT_STRING
      shape: (-1)
      name: serving_default_examples:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['output_0'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 3)
      name: StatefulPartitionedCall:0
Method name is: tensorflow/serving/predict

What is the correct POST API call to get the predictions from this model?

Thank you in advance

  • Correction, I tried (but it didn't work): curl -d '{"instances": [7.7,3.0,6.1,2.3]}' \ -X POST localhost:8501/v1/models/iris_cpu:predict – A_j_a_y Jul 25 '20 at 01:28
  • Could you please post the error you are getting? The format seems correct. –  Feb 22 '21 at 12:18

0 Answers0