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

Jpcbertoldo/mvtec ad loco #538

Closed

Conversation

jpcbertoldo
Copy link
Contributor

@jpcbertoldo jpcbertoldo commented Sep 2, 2022

Disclaimer

I am creating this just to keep track of the branch, please ignore the PR for the moment.


Description

Create a new dataset: MVTec LOCO Anomaly Detection.

"LOCO" stands for "LOgical COnstraints"

I based myself on anomalib/data/mvtec.py.

imread_strategy

The dataset supports an option imread_strategy which allows the user how to choose when the images are loaded:

  • onthefly: behaviour I found in mvtec.py, the images are loaded upon demand during the training;
  • preload: all the images are cached in the memory (RAM, not GPU) when the dataset is being initialized.

anotype and super_anotype

Besides providing the binary label, I also create the dataset with two other categorical values:

  • super_anotype: is it a logical or structural anomaly? (or a normal?)
  • anotype: "what is the problem with the image?", mvtec ad also has different types of anomalies for each category but this is particularly more interesting here because there are many types of logical violations possible.

I specifically included this because I am interested in evaluating separately by those types but I will later create an issue for that feature.

mask vs. masks

MVTec LOCO's logical anomalies may include several anoamlies in a single image and to properly evaluate them one needs to consider them separately so they are segmented in different mask files in the ground truth.

Since the rest of library expects a tensor mask (SINGULAR), I merge them all into a single binary maks (with loss information because they cannot be separated anymore).

In order to later peform proper evaluation there is a second tensor masks (PLURAL) which encodes each anomalous region with a different value (0 is a normal pixel, and 1, 2, ..., N are anomalous pixels).

things in MVTecAD but not in MVTecLOCO

1) self.transform_config_val = self.transform_config_train

        if self.transform_config_train is not None and self.transform_config_val is None:
            self.transform_config_val = self.transform_config_train

Is there a good reason for assuming this?

For me it could make sense that self.transform_config_val could have light data augmentations (say, tiny brightness changes) but that should not be repeated in the validation set.

2) split_normal_images_in_train_set(samples, split_ratio, seed)

MVTec LOCO already defines fixed validation sets so i did not include the option of doing it dinamically like in MVTec AD.


Checklists

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which refactors the code base)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the pre-commit style and check guidelines of this project.
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • [] New and existing tests pass locally with my changes

@github-actions github-actions bot added the Data label Sep 2, 2022
@jpcbertoldo
Copy link
Contributor Author

yet something i dont understand in anomalib.data.mvtec

# in MVTecLOCODataset.__getitem__
pre_processed = self.pre_process(image=image, mask=mask)

how this works?

does the transform re-apply the last call when mask is not None?

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@jpcbertoldo
Copy link
Contributor Author

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.

Powered by ReviewNB

@samet-akcay is this some sort of integratin in the project?

@samet-akcay
Copy link
Contributor

Check out this pull request on  ReviewNB
See visual diffs & provide feedback on Jupyter Notebooks.
Powered by ReviewNB

@samet-akcay is this some sort of integratin in the project?

We use ReviewNB for notebook reviews. It's not so easy to review jupyter notebooks on GitHub. ReviewNB makes it significantly easier.

category: str,
task: str = TASK_SEGMENTATION,
imread_strategy: str = IMREAD_STRATEGY_PRELOAD,
image_size: Optional[Union[int, Tuple[int, int]]] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The images in this dataset are not squared.
The ratio of widh/height can end up too different than the original image when the image size is given as an int.

Maybe we should add a warning here?

"mask_paths": str(self.samples.iloc[index]["mask_paths"]),
# TODO CHECK IF THE DOUBLE CALL TO PREPROCESS WILL WORK WITH ALBUMENTATIONS
"masks": self.pre_process(image=image, mask=mask_dict["masks"])["mask"],
"mask": self.pre_process(image=image, mask=mask_dict["mask"])["mask"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.pre_process is being called for the 3rd time here, will that create any problems?

I'm thinking that maybe the random transforms will apply the same transform every two times (for the image and for the mask).

@jpcbertoldo
Copy link
Contributor Author

i messed some git commands, i'm closing this one and openning another one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for MVTEC LOCO AD
6 participants