I am running a prediction on a tensorflow-serving model, and I get back this PredictResponse
object as output:
Result:
result["outputs"].float_val
should be a python list
You generally want to recover a tensor, with a shape (not just a long list of floats). Here's how:
outputs_tensor_proto = result.outputs["outputs"]
shape = tf.TensorShape(outputs_tensor_proto.tensor_shape)
outputs = tf.constant(outputs_tensor_proto.float_val, shape=shape)
If you prefer to get a NumPy array, then just replace the last line:
outputs = np.array(outputs_tensor_proto.float_val).reshape(shape.as_list())
If you don't want to depend on the TensorFlow library at all, for some reason:
outputs_tensor_proto = result.outputs["outputs"]
shape = [dim.size for dim in outputs_tensor_proto.tensor_shape.dim]
outputs = np.array(outputs_tensor_proto.float_val).reshape(shape)
If you would like to convert the entire PredictResponse to a numpy array (including its dimentions)
<script src="https://gist.github.com/eavidan/22ad044f909e5739ceca9ff9e6feaa43.js"></script>
The answer is:
floats = result.outputs['outputs'].float_val
This answer is for tensorflow-serving-api-python3 1.8.0
result.outputs['your key name'].float_val #key name in your case is outputs
This will return a repeated scalar container object. Which can be passed to python list() or np.array() etc