1 回答

TA貢獻1752條經驗 獲得超4個贊
來自掩碼 R-CNN 的預測具有以下結構:
在推理過程中,模型只需要輸入張量,并將后處理的預測作為 ,每個輸入圖像返回一個。的字段如下:List[Dict[Tensor]]Dict
boxes (FloatTensor[N, 4]): the predicted boxes in [x1, y1, x2, y2] format, with values between 0 and H and 0 and W
labels (Int64Tensor[N]): the predicted labels for each image
scores (Tensor[N]): the scores or each prediction
masks (UInt8Tensor[N, 1, H, W]): the predicted masks for each instance, in 0-1 range.
您可以使用 OpenCV 和函數來繪制蒙版,如下所示:findContoursdrawContours
img_cv = cv2.imread('input.jpg', cv2.COLOR_BGR2RGB)
for i in range(len(prediction[0]['masks'])):
# iterate over masks
mask = prediction[0]['masks'][i, 0]
mask = mask.mul(255).byte().cpu().numpy()
contours, _ = cv2.findContours(
mask.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(img_cv, contours, -1, (255, 0, 0), 2, cv2.LINE_AA)
cv2.imshow('img output', img_cv)
添加回答
舉報