Detectron2-條件過濾顯示物件

圖片預測完後會得到Instance,可透過條件式來取得特定的偵測物件,最後在由此Instance做視覺化即可過濾部分不要的物件,範例程式碼寫了部分條件過濾供參考。

outputs = predictor(frame)

#特定類別
outputs["instances"] = outputs["instances"][outputs["instances"].pred_classes == 3]
#分數大於0.9
outputs["instances"] = outputs["instances"][outputs["instances"].scores > 0.9]
#boxes X1的座標值大於100
outputs["instances"] = outputs["instances"][np.where(outputs["instances"].pred_boxes.tensor.cpu().numpy()[:,0]>100)]


v = Visualizer(frame[:, :, ::-1], metadata=mydata_metadata,  scale=1, instance_mode=ColorMode.SEGMENTATION)
                v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
                Image.fromarray(v.get_image()[:, :, ::-1])
                cv2.imwrite('tmpfile/prediction_d_' + j + '.jpg', v.get_image()[:, :, ::-1])

留言

這個網誌中的熱門文章

Python-相關係數矩陣實作(python-correlation matrix )

ASP.NET-後端將值傳給javascript

ASP.NET-FileUpload上傳後自動觸發button click(FileUpload upload auto trigger button click)