Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task]: Anomaly heat map not generated correctly for DFM model in classification #1521

Open
JakeNail opened this issue Dec 4, 2023 · 1 comment

Comments

@JakeNail
Copy link

JakeNail commented Dec 4, 2023

What is the motivation for this task?

When running inference on a custom dataset for a DFM model with the classification task I found out that the anomaly heatmaps were not generated properly, they are just empty. I reproduced this problem with the MVtec dataset using the default config.yaml file for the model only changing task from segmentation to classification and save_images to True. Here are two examples.
Screenshot 2023-12-04 153208
Screenshot 2023-12-04 153307

Describe the solution you'd like

However when using the task segmentation the anomaly heatmaps are generated as expected. Would it be possible to have them for the classification task for the DFM model instead of empty ones? Just like it is the case for other models in anomalib. Here are the two corresponding images using segmentation.
Screenshot 2023-12-04 154305
Screenshot 2023-12-04 154243

Additional context

No response

@JakeNail JakeNail added the Task label Dec 4, 2023
@blaz-r
Copy link
Contributor

blaz-r commented Dec 4, 2023

There is some work in progress in #1378 to also add classification score to segmentation visualization.

The mask is still displayed in visualizer, so that's not a bug. But I identified the reason for mask being all zeros in case of classification. It is because of these lines:

if "mask" in outputs[0].keys() and "anomaly_maps" in outputs[0].keys():
self.pixel_threshold.compute()
else:
self.pixel_threshold.value = self.image_threshold.value

Since mask is not added to batch in classification, mask threshold is set to same value as image threshold, which is completely wrong. So when normalization happens, all masks become 0.
I think a solution would be to add mask to dataset even in case of classification here:

if self.task == TaskType.CLASSIFICATION:
transformed = self.transform(image=image)
item["image"] = transformed["image"]

skipping the separate if branch and loading mask for all types.

@samet-akcay I'm not sure what to do about this, we could include mask even in classification, since visualizer displays the heat map?

@samet-akcay samet-akcay removed the Task label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants