YoungGod / DFR

Project: Unsupervised Anomaly Segmentation via Deep Feature Reconstruction
90 stars 25 forks source link

Bug in evaluation code #2

Closed bezilla5 closed 3 years ago

bezilla5 commented 3 years ago

Thanks for your open source!

I found a bug in the evaluation of Per Region Overlap. https://github.com/YoungGod/DFR/blob/b6195304389441f20d2bb1def71c2d2540996012/DFR-source/anoseg_dfr.py#L654-L660

When cropped_mask gets multiple regions as in the output below, intersection can return over 1. image

Therefore, it needs to get only the center region of the crop area. I think it will work correctly by changing cropped_mask to prop.filled_image.

Please check it out.

YoungGod commented 3 years ago

Thanks a lot for point out this bug. You are right. It should be prop.filled_image.

props = measure.regionprops(label_map) 
 for prop in props: 
     x_min, y_min, x_max, y_max = prop.bbox    # find the bounding box of an anomaly region  
     cropped_pred_label = binary_score_maps[i][x_min:x_max, y_min:y_max] 
     cropped_mask = prop.filled_image    # corrected!
     intersection = np.logical_and(cropped_pred_label, cropped_mask).astype(np.float32).sum() 
     pro.append(intersection / prop.area)