1

I have a log of grpc messages for a TensorflowServing system looking like this:

model_spec:{name:"model_name"}  inputs:{key:"args_0"  value:{dtype:DT_STRING  tensor_shape:{dim:{size:1}}  string_val:"example input"}}  inputs:{key:"args_1"  value:{dtype:DT_STRING  tensor_shape:{dim:{size:1}}  string_val:"another example input"}}  inputs:{key:"args_3"  value:{dtype:DT_FLOAT  tensor_shape:{dim:{size:1}}  float_val:374969}}

I suspect this is a protobuf format string (but I might be wrong) and I would like to turn it into a python dictionary (something like this but I am flexible):

{
  "model_spec":{"name":"model_name"},
  "inputs":{
    "args_0": "example input",
    "args_1": "another example input",
    "args_3": 374969
  }
}

Are there any libraries that can help me here? My problem is that I don't have any schema for this message (as required in this stackoverflow question). I tried parsing this with regular expressions but I hope there might be a better way.

mrzo
  • 2,002
  • 1
  • 14
  • 26
  • 1
    I'm entirely unfamiliar with Tensorflow (Serving) but, your example looks to be a [`PredictRequest`](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/apis/predict.proto) (that's the schema). You'll need to have an instance of the Protobuf `message` and should then be able to `json_format.MessageToJson(message)` it. You don't need the schema if you can get an instance of the Python Protobuf `message`. – DazWilkin Jun 07 '23 at 17:37

0 Answers0