Skip to content

Project for <SPot-the-Difference Self-Supervised Pre-training for Anomaly Detection and Segmentation> (ECCV 2022)

License

Apache-2.0, CC-BY-4.0 licenses found

Licenses found

Apache-2.0
LICENSE
CC-BY-4.0
LICENSE-DATASET
Notifications You must be signed in to change notification settings

amazon-science/spot-diff

SPot-the-Difference Self-Supervised Pre-training for Anomaly Detection and Segmentation

Yang Zou, Jongheon Jeong, Latha Pemula, Dongqing Zhang, Onkar Dabeer.

Table of Contents

Introduction

This repository contains the resources for our ECCV-2022 paper "SPot-the-Difference Self-Supervised Pre-training for Anomaly Detection and Segmentation". Currently we release the Visual Anomaly (VisA) dataset.

Data description

The VisA dataset contains 12 subsets corresponding to 12 different objects as shown in the above figure. There are 10,821 images with 9,621 normal and 1,200 anomalous samples. Four subsets are different types of printed circuit boards (PCB) with relatively complex structures containing transistors, capacitors, chips, etc. For the case of multiple instances in a view, we collect four subsets: Capsules, Candles, Macaroni1 and Macaroni2. Instances in Capsules and Macaroni2 largely differ in locations and poses. Moreover, we collect four subsets including Cashew, Chewing gum, Fryum and Pipe fryum, where objects are roughly aligned. The anomalous images contain various flaws, including surface defects such as scratches, dents, color spots or crack, and structural defects like misplacement or missing parts.

Object # normal samples # anomaly samples # anomaly classes object type
PCB1 1,004 100 4 Complex structure
PCB2 1,001 100 4 Complex structure
PCB3 1,006 100 4 Complex structure
PCB4 1,005 100 7 Complex structure
Capsules 602 100 5 Multiple instances
Candles 1,000 100 8 Multiple instances
Macaronis1 1,000 100 7 Multiple instances
Macaronis2 1,000 100 7 Multiple instances
Cashew 500 100 9 Single instance
Chewing gum 503 100 6 Single instance
Fryum 500 100 8 Single instance
Pipe fryum 500 100 9 Single instance

Data download

We host the VisA dataset in AWS S3 and you can download it by this URL.

The data tree of the downloaded data is as follows.

VisA
|-- candle
|-----|--- Data
|-----|-----|----- Images
|-----|-----|--------|------ Anomaly 
|-----|-----|--------|------ Normal 
|-----|-----|----- Masks
|-----|-----|--------|------ Anomaly 
|-----|--- image_anno.csv
|-- capsules
|-----|----- ...

image_annot.csv gives image-level label and pixel-level annotation mask for each image. The id2class map functions for multi-class masks can be found in ./utils/id2class.py Here the masks for normal images are not stored to save space.

Data preparation

To prepare the 1-class, 2-class-highshot, 2-class-fewshot setups described in the original paper, we use the ./utils/prepare_data.py to reorganize data following the data splitting files in "./split_csv/". We give a sample command line for 1-class setup preparation as follows.

python ./utils/prepare_data.py --split-type 1cls --data-folder ./VisA --save-folder ./VisA_pytorch --split-file ./split_csv/1cls.csv

The data tree of the reorganized 1-class setup is as follows.

VisA_pytorch
|-- 1cls
|-----|--- candle
|-----|-----|----- ground_truth
|-----|-----|----- test
|-----|-----|-------|------- good 
|-----|-----|-------|------- bad 
|-----|-----|----- train
|-----|-----|-------|------- good
|-----|--- capsules
|-----|--- ...

Specifically, the reorganized data for 1-class setup follows the data tree of MVTec-AD. For each object, the data has three folders:

  • 'train', which includes the normal training images
  • 'test', which includes the normal and anomalous test images
  • 'ground_truth', which includes the pixel-level annotations of anomalous images

Note that the multi-class ground-truth segmentation masks in the original dataset are reindexed to binary masks where 0 indicates normality and 255 indicates anomaly.

In addition, the 2-class setups can be prepared in a similar way by changing the arguments of prepare_data.py.

Metrics computation

To compute classification and segmentation metrics, please refer to ./utils/metrics.py. Note that we take the normal samples into account when computing the localization metrics. This is different from some of the other works disregarding the normal samples in localization.

Citation

Please cite the following paper if this dataset helps your project:

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

License

The data is released under the CC BY 4.0 license.

About

Project for <SPot-the-Difference Self-Supervised Pre-training for Anomaly Detection and Segmentation> (ECCV 2022)

Resources

License

Apache-2.0, CC-BY-4.0 licenses found

Licenses found

Apache-2.0
LICENSE
CC-BY-4.0
LICENSE-DATASET

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages