Closed reubenwenisch closed 3 years ago
@reubenwenisch: The DefaultPredictor
model returns object of type Instances
and not a JSON/python dictionary.
Want the dictionary contents via api.
I assume you are looking for boxes
and classes
. You can extract these from the model output as follows :
outputs = model(image)
print(outputs['instances'].pred_boxes)
print(outputs['instances'].pred_classes)
Right. Even this pred_boxes
is of type detectron2.structures.boxes
. Even this cannot be json serializable right? So what is the recommended way to send the output and convert back in the case of a segmentation algorithm? Currently, I am converting to a list is that the recommended way?
@reubenwenisch: As documented by detectron2, detectron2.structures.boxes
stores a list
of boxes as an Nx4 torch.Tensor.
So what is the recommended way to send the output and convert back in the case of a segmentation algorithm TorchServe handler should return a list of output. You can return any type of data like Tensor, Boxes, Classes, or a segmented image (in binary format). What you want to return from the handler will depend on your use-case at the client end.
You can refer to the following google-colab jupyter notebook which demonstrates running inference on the DefaultPredictor
https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5#scrollTo=7d3KxiHO_0gb
You can also refer to the post-processing of TorchServe's default image-segmenter handler
Context
I am trying to serve a detectron2 model with torch serve using a custom handler. I get the following error "TypeError: Object of type Instances is not JSON serializable" after I convert the dictionary output of the model to a list.
Custom Handler Code
Expected Behavior
Want the dictionary contents via api.
Current Behavior
raise TypeError(f'Object of type {o.class.name} ' TypeError: Object of type Instances is not JSON serializable