yolact
yolact copied to clipboard
How to calculate the area of the masked image
Hello, is there a way to calculate the area / contour of the masked image? Thanks.
@barryluke96 Some thing like this
Image of the mask
with timer.env('Postprocess'):
save = cfg.rescore_bbox
cfg.rescore_bbox = True
classes, scores, boxes, masks = postprocess(dets_out, w, h, visualize_lincomb = args.display_lincomb,
crop_masks = args.crop,
score_threshold = args.score_threshold)
cfg.rescore_bbox = save
# mask :1 -> 255 -> then copy to cpu -> then convert from tensor into numpy
masks_np = (masks* 255).byte().cpu().numpy()
# Find the contour of first mask
mask0_np = masks_np[0, :, :]
contours,hierarchy = cv2.findContours(mask0_np, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
plt.imshow(cv2.cvtColor(mask1_np, cv2.COLOR_GRAY2RGB))
Note : This code will copy entire mask images from gpu to cpu.
@barryluke96 Some thing like this
Image of the mask
with timer.env('Postprocess'): save = cfg.rescore_bbox cfg.rescore_bbox = True classes, scores, boxes, masks = postprocess(dets_out, w, h, visualize_lincomb = args.display_lincomb, crop_masks = args.crop, score_threshold = args.score_threshold) cfg.rescore_bbox = save # mask :1 -> 255 -> then copy to cpu -> then convert from tensor into numpy masks_np = (masks* 255).byte().cpu().numpy() # Find the contour of first mask mask0_np = masks_np[0, :, :] contours,hierarchy = cv2.findContours(mask0_np, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) plt.imshow(cv2.cvtColor(mask1_np, cv2.COLOR_GRAY2RGB))
Note : This code will copy entire mask images from gpu to cpu.
it work for me, thank :)
Im late, but is there a way to calculate this on gpu? Copying every mask on cpu will slow process enormously