Search code examples
pythontensorflowtensorflow-servingtensorflow-estimator

TensorFlow: How to format JSON for SavedModel expecting 3 ints in string format?


I'm having trouble using Postman to send a correct predict POST request to my model running at a distance on with TensorFlow Serving in a Docker container.

The model responds to a GET request so I know it works and is responding. The algorithm requires 3 int ID values being processed as categories to function but the SignatureDef requires a string on input, looking like this:

The given SavedModel SignatureDef contains the following input(s):
  inputs['inputs'] tensor_info:
      dtype: DT_STRING
      shape: (-1)
      name: input_example_tensor:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['classes'] tensor_info:
      dtype: DT_STRING
      shape: (-1, 2166)
      name: linear/head/Tile:0
  outputs['scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 2166)
      name: linear/head/predictions/probabilities:0
Method name is: tensorflow/serving/classify

I've tried following the JSON formatting shown on the RESTful API tutorial here: https://www.tensorflow.org/tfx/serving/api_rest#example But can't get anything to send me back anything but error responses that don't help me much in knowing the right syntax. In any case it'd need to be something like this:

{
 "inputs": ['int1': 1, 'int2': 2, 'int3': 3]
}

I'm expecting it to send me back something like shown in the tutorial:

    "predictions": [3.5, 4.0, 5.5]

Instead I get "error": whatever it doesn't like about what I sent it this time. Any help would be appreciated


Solution

  • After consulting several other people, we managed to find the solution. It was expecting a list of strings, each string containing the relevant dictionary items, escaping the quotes where necessary for the tags.

    {
        "instances": 
            ["\"int1\": [1] , \"int2\" : [2], \"int3\":[3]"]
    
    }