Decode string back into tuple of predictions

(Henry Dashwood) #1

I’ve been trying to deploy a model as an endpoint on Sagemaker. Currently the endpoint returns my model’s predictions as a string in this format.

'(ImagePoints (320, 320), tensor([[-0.4128,  0.1322],\n        [-0.7365,  0.1464],\n        [-0.6189,  0.2665],\n        [-0.7248,  0.4663],\n        [-0.4005,  0.3247],\n        [-0.2695,  0.2497],\n        [-0.3914,  0.2126],\n        [-0.4023,  0.3228],\n        [-0.2775,  0.2574],\n        [-0.2962,  0.2582],\n        [-0.2722,  0.2691]]), tensor([-0.4128,  0.1322, -0.7365,  0.1464, -0.6189,  0.2665, -0.7248,  0.4663,\n        -0.4005,  0.3247, -0.2695,  0.2497, -0.3914,  0.2126, -0.4023,  0.3228,\n        -0.2775,  0.2574, -0.2962,  0.2582, -0.2722,  0.2691]))'

Does anyone know a way to decode the string back into the tuple of ImagePoints and tensors that it should be in?



Instead of sending a string representation of your object, you should try and serialize it. For the tensor part, it is quite easy as pytorch implements it (look at applied to a buffer object, should work for object sending). However I do not now what information is encoded in an ImagePoints so can’t really help you on this one. If it stores a tensor or something like it, just serialize the tensor and reconstruct the ImagePoints after message is received.