Linked Questions

Popular Questions

Please help me to calculate IoU for Polygon Segmentation of images segmented by yolov8 segment module.

I have a predicted mask that is segmented by yolov8 and a ground truth mask.

The ground truth mask has been obtained after converting json file to mask (using shape_to_mask() utility function). The JSON file is the annotated pixel coordinates file. Annotation has been done using the labelme tool.

Here is what I have tried:

pred_mask=(rs[0].masks.masks[0].numpy()*255).astype("uint8")

#some code ommitted here

    
with open(pt_json,"r",encoding="utf-8") as f:
    dj=json.load(f)
grount_truth_mask=labelme.utils.shape_to_mask((dj['imageHeight'],dj['imageWidth']),dj['shapes'][0]['points'],shape_type=None,line_width=1,point_size=1)

pred_area=st.resize(pred_area,(640,480),order=0,preserve_range=True,anti_aliasing=False)
mask_area=st.resize(mask_area,(640,480),order=0,preserve_range=True,anti_aliasing=False)


pred_area=pred_area.ravel().copy()
mask_area=mask_area.ravel().copy()

pred_area=pred_area==1
mask_area=mask_area==1


intersection = np.sum(pred_area*mask_area)
union=pred_area.sum()+mask_area.sum()-intersection
iou=np.mean(intersection/union)

I am getting IoU=0.0 for all images.

Related Questions