tfds-defect-detection 1.0.0
TensorFlow Datasets for Defect Detection

.. figure:: tfds_defect_detection/assets/images/logo.png
   :align: center
   :alt:
   :scale: 50 %


.. image:: https://readthedocs.org/projects/tfds-defect-detection/badge/?version=latest
    :target: https://tfds-defect-detection.readthedocs.io/en/latest/README.html
    :alt: Documentation Status
.. image:: https://img.shields.io/pypi/v/tfds_defect_detection
   :target: https://pypi.org/project/tfds-defect-detection/
.. image:: https://img.shields.io/pypi/pyversions/tfds_defect_detection
   :alt: PyPI - Python Version

========================================
TensorFlow Datasets for Defect Detection
========================================

To directly jump into the code look at the sample notebook

.. class:: center

|Open in Colab|

.. |Open in Colab| image:: https://img.shields.io/badge/Open%20In-Colab-orange?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAUCAYAAACaq43EAAAACXBIWXMAAAdiAAAHYgE4epnbAAAEg2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSfvu78nIGlkPSdXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQnPz4KPHg6eG1wbWV0YSB4bWxuczp4PSdhZG9iZTpuczptZXRhLyc+CjxyZGY6UkRGIHhtbG5zOnJkZj0naHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyc+CgogPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9JycKICB4bWxuczpBdHRyaWI9J2h0dHA6Ly9ucy5hdHRyaWJ1dGlvbi5jb20vYWRzLzEuMC8nPgogIDxBdHRyaWI6QWRzPgogICA8cmRmOlNlcT4KICAgIDxyZGY6bGkgcmRmOnBhcnNlVHlwZT0nUmVzb3VyY2UnPgogICAgIDxBdHRyaWI6Q3JlYXRlZD4yMDIyLTExLTA4PC9BdHRyaWI6Q3JlYXRlZD4KICAgICA8QXR0cmliOkV4dElkPjdiZTBlMWY0LTU3YTUtNDBhMi05ZjIzLTM2N2Q1YzU1OGYyNjwvQXR0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ee5VgHQl5seti1nGdB93ahd9ny0UBLczXQAxKZmendwwNTn2wmq1fnmpaNEjDquPscLZaDTVIJo3Nh/8rx3s7BmXJEVgKy8Mj2Jku/AK5W24wlcBH7cPzS7vIcZpvEzblW059t6vHX13PpJB/yiB5iCtgJfALxU4QwjwJ3qSDXS7q4eqKaDSX3qfAUYkLmeqT3S/oR6GapfYztCH6YEH6ms/f3CaVnnMNfqplm68RcPSS3VHlZQyC1TWSzO0T21Bf0gdVnqjWnMKbgDR6/JN8qNZ3THnAS51tA54tqNkU3ehE1d45fVz9OZsYmSwy59HNwl24DfYnv9qa5Y+mpasZJuxXA1miD3zu/qVsL2wXwH+w7kc4DIYzOxxT6jqHvv6ngLc4c7OpX2fQ6xwXtvg+sYh5f/G310uBkfDfy920ncA9cYUfsaLvXzQCed867ut6ISLnITSCO1ykPFBU55cxdtOx0N/Amm5mu+Z7HPAn80vCvxeN9gjzoh3x/Tt4nca+ttwJbOwQsgJ/GPErQE13eQ5sJocEjrywIQcLu0FaXUAzpYRwK6g7PWIT+PeSznxtTHEM5OUtCV06QLqxUAJwdjuLWMdsGBZEzpiVdkfkfodOPwQgKJiAAAAAASUVORK5CYII=
   :target: https://colab.research.google.com/drive/1_0diKQAHBX2q8iCEI7bmv0TnnmaWZR1M?usp=sharing

.. admonition:: Features

    - tensorflow.data.Dataset builder for defect segmentation
    - Comes with unsupervised / self-supervised SotA datasets
        - MVTEC
        - VISA
    - Artificial defect generator
    - Evaluation data with hand labelled images


Install
-------

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

.. code-block:: bash

    pip install tfds_defect_detection



Examples
-----------

.. code-block:: python

    import tfds_defect_detection as tfd
    tfd.load()




Usage
-----------

All parmeters

.. code-block:: python

    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
    )


.. figure:: tfds_defect_detection/assets/images/example.png
   :align: center
   :alt:
   :scale: 50 %



.. admonition:: Docs

    FOR API Reference see

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


.. admonition:: 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. https://github.com/thetoby9944/tfds_defect_detection.


    .. code-block:: latex

        @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}},
        }