YoungGod / DFR

Project: Unsupervised Anomaly Segmentation via Deep Feature Reconstruction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in evaluation code

bezilla5 opened this issue · comments

Thanks for your open source!

I found a bug in the evaluation of Per Region Overlap.

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 = masks[i][x_min:x_max, y_min:y_max]
intersection = np.logical_and(cropped_pred_label, cropped_mask).astype(np.float32).sum()
pro.append(intersection / prop.area)

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.

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)