How to post processing for inference time

#1
by hungtooc - opened

thanks for great model and good result!
I'm stuck at post processing code for this original code:

from transformers import DetrFeatureExtractor, DetrForSegmentation
from PIL import Image
import requests

url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)

feature_extractor = DetrFeatureExtractor.from_pretrained('facebook/detr-resnet-101-panoptic')
model = DetrForSegmentation.from_pretrained('facebook/detr-resnet-101-panoptic')

inputs = feature_extractor(images=image, return_tensors="pt")
outputs = model(**inputs)
# model predicts COCO classes, bounding boxes, and masks
logits = outputs.logits
bboxes = outputs.pred_boxes
masks = outputs.pred_masks

how to get the final mask and label? thanks.

(off topic, but if you want Python syntax coloring @hungtooc , you can specify python right after your code fence, like on GitHub)

@hungtooc You can directly use the pipelines like below to get final mask and label

model = pipeline("image-segmentation", model="facebook/detr-resnet-101-panoptic")
outputs = model("3.png")
for i in range(len(outputs)):
outputs[i]["mask"].save("output/mask_" + outputs[i]["label"] + ".png")

Sign up or log in to comment