PaDiM-Anomaly-Detection-Localization-master icon indicating copy to clipboard operation
PaDiM-Anomaly-Detection-Localization-master copied to clipboard

Apply PaDiM to another domain.

Open sangkyuleeKOR opened this issue 4 years ago • 8 comments

Hi I'm sangkyu from south korea.

I am trying to apply PaDiM to another domain.

Several issues arose during application.

I want to do anomaly detection with an image of size 80x160x3. The score distribution of the normal image tends to be higher than that of the abnormal image. I know that PaDiM is sensitive to the location, and the background was also erased with contours to minimize the background effect. However, the distribution of normal scores is still high. Can you leave any comments on this?

abnormal normal

sangkyuleeKOR avatar Mar 22 '21 09:03 sangkyuleeKOR

I applied on another domain, was fine, can you increase the resolution: make your image size: 160 x160

DeepKnowledge1 avatar Mar 22 '21 11:03 DeepKnowledge1

I applied on another domain, was fine, can you increase the resolution: make your image size: 160 x160

I've already tried to make image resolution as 160x160 by padding. but it didn't work properly. Are you talking about to make images to 160x160 by resizing????

sangkyuleeKOR avatar Mar 23 '21 01:03 sangkyuleeKOR

Heat maps are relative to the image data. example) nomal data = 0,0,0,1,2(red),1,1,4(red),2(red),1,... anomaly data = 0,0,0,1,2,1,1,14(red),2,1,16(red),... Are you check threshold? need gt mask

I'm taking about heatmap result. i think normal data has to be covered by blue but it has abnormal points which is colored by red. I don't need gt masks because I'm gonna shift threshold by circumstances.

sangkyuleeKOR avatar Mar 23 '21 02:03 sangkyuleeKOR

In the case of normal image, even if there is little data deviation, it is expressed red in the heat map. This is because heat maps make data normalize. You'd better check it a score map.

Thanks for replying! I modified the code a lot. heat map is in range 0 to 1, and score map 0 to 1 has proper value.. and I compared normal and abnormal image's distribution. I found nothing wrong with normalize.

sangkyuleeKOR avatar Mar 23 '21 04:03 sangkyuleeKOR

because of this code norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax)

if you change ax = ax_img[2].imshow(heat_map, cmap='jet', norm=None)

You will see the range of color bar range changing.

However, because heat maps are relative to the data, the high data will still look red.

easy to trick heatmap

heat_map = scores[i] * 255 <--below this code heat_map[0] = vmax <-- write

dhkdnduq avatar Mar 23 '21 06:03 dhkdnduq

because of this code norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax)

if you change ax = ax_img[2].imshow(heat_map, cmap='jet', norm=None)

You will see the range of color bar range changing.

However, because heat maps are relative to the data, the high data will still look red.

easy to trick heatmap

heat_map = scores[i] * 255 <--below this code heat_map[0] = vmax <-- write

like I said, I checked score maps of normal and abnormal data, it was not heat map range problem. I fixed heat map range with static number

sangkyuleeKOR avatar Mar 25 '21 12:03 sangkyuleeKOR

It doesn't mean anything to fix the heat map range.

This is because when displaying image data in matplot, scale up to range.

The scale should be prevented by putting the max value into the image data.

Have you tested it like below?

  • heat_map[0] = vmax

I'm sorry if it wasn't the answer you wanted.

dhkdnduq avatar Mar 25 '21 13:03 dhkdnduq

Try to swap this lines: mask[mask > threshold] = 1 mask[mask <= threshold] = 0 like this: mask[mask <= threshold] = 0 mask[mask > threshold] = 1

If threshold is too high (>1), then some mask values become 1 then all mask values become 0 (as all values will be under threshold)

SixK avatar Mar 27 '21 23:03 SixK