Documentation Status https://img.shields.io/pypi/v/tfds_defect_detection PyPI - Python Version

TensorFlow Datasets for Defect Detection#

To directly jump into the code look at the sample notebook

class center#

Open in Colab

Features

  • tensorflow.data.Dataset builder for defect segmentation

  • Comes with unsupervised / self-supervised SotA datasets

  • Artificial defect generator

  • Evaluation data with hand labelled images

Provides a tf.data.Dataset loader for#

Dataset

Licence

Copyright

MVTEC

CC BY-NC-SA 4.0

MVTEC.com, All rights reserved

VisA

CC BY 4.0

Amazon.com, Inc. or its affiliates. All Rights Reserved.

Dataset Links

MVTEC: https://www.mvtec.com/company/research/datasets/mvtec-ad VisA: amazon-science/spot-diff

Install#

Create a new python=3.9 env and install tfds_defect_detection from pip

pip install tfds_defect_detection

Examples#

import tfds_defect_detection as tfd
tfd.load()

Usage#

All parmeters

import tfds_defect_detection as tfd
impor albumentations as A

ds = tfd.load(
    names = ("mvtec", "visa"),
    data_dir=Path("."),
    pairing_mode = "result_with_contrastive_pair",  # "result_only", "result_with_original"
    create_artificial_anomalies=True,
    validation_split=0.2,
    subset_mode = "training",                       # "validation", "test", "holdout", None
    drop_masks=False,
    width=256,
    height=256,
    repeat=True,
    anomaly_size = None,

    global_transform=A.Compose([
      A.RandomBrightnessContrast(),
      A.HueSaturationValue(),
    ]),

    process_deviation=A.Compose([
      A.ShiftScaleRotate(
        shift_limit=0.01,
        scale_limit=0.0,
        rotate_limit=1.5,
        p=1
      ),
      A.Blur(blur_limit=3),
      A.RandomBrightnessContrast(),
      A.RandomGamma(),
      A.HueSaturationValue(),
    ]),

    anomaly_composition=A.Compose([
      A.RandomRotate90(),
      A.Transpose(),
      A.ShiftScaleRotate(
        shift_limit=0.0625,
        scale_limit=0.50,
        rotate_limit=45, p=1
      ),
      A.RandomGamma(),
      A.OpticalDistortion(),
      A.GridDistortion(),
      A.RandomContrast(0.5, p=1),
    ]),

    batch_size=9,
    seed=123,
    shuffle=True,
    peek=True,
    image_validation=False,
    delete_tmp=True,
    crop_to_aspect_ratio=True
)

Docs#

FOR API Reference see

https://tfds-defect-detection.readthedocs.io/en/latest/autoapi/tfds_defect_detection/index.html

Cite#

If this project helped you during your work: Until a publication is available, please cite as

Tobias Schiele. (2022). TFDS DD - Datasets for Defect Detection. thetoby9944/tfds_defect_detection.

@misc{Schiele2019,
    author = {Tobias Schiele},
    title = {TFDS DD - Datasets for Defect Detection},
    year = {2022},
    publisher = {GitHub},
    journal = {GitHub repository},
    howpublished = {\url{https://github.com/thetoby9944/tfds_defect_detection}},
}

If you use one of the datasets, include these citations:

MVTEC#

Paul Bergmann, Kilian Batzner, Michael Fauser, David Sattlegger, Carsten Steger: The MVTec Anomaly Detection Dataset: A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection; in: International Journal of Computer Vision 129(4):1038-1059, 2021, DOI: 10.1007/s11263-020-01400-4.

Paul Bergmann, Michael Fauser, David Sattlegger, Carsten Steger: MVTec AD — A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection; in: IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 9584-9592, 2019, DOI: 10.1109/CVPR.2019.00982.

VisA#

@article{zou2022spot,
  title={SPot-the-Difference Self-Supervised Pre-training for Anomaly Detection and Segmentation},
  author={Zou, Yang and Jeong, Jongheon and Pemula, Latha and Zhang, Dongqing and Dabeer, Onkar},
  journal={arXiv preprint arXiv:2207.14315},
  year={2022}
}