{"id":21490021,"url":"https://github.com/aimaster-dev/multi-class-anomaly-detection","last_synced_at":"2025-04-23T10:26:01.659Z","repository":{"id":254044674,"uuid":"845321327","full_name":"aimaster-dev/multi-class-anomaly-detection","owner":"aimaster-dev","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-21T02:56:56.000Z","size":1083,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T23:22:07.377Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aimaster-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-21T02:55:09.000Z","updated_at":"2024-09-17T13:04:24.000Z","dependencies_parsed_at":"2024-08-21T04:06:11.569Z","dependency_job_id":null,"html_url":"https://github.com/aimaster-dev/multi-class-anomaly-detection","commit_stats":null,"previous_names":["aimaster-dev/multi-class-anomaly-detection"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimaster-dev%2Fmulti-class-anomaly-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimaster-dev%2Fmulti-class-anomaly-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimaster-dev%2Fmulti-class-anomaly-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimaster-dev%2Fmulti-class-anomaly-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aimaster-dev","download_url":"https://codeload.github.com/aimaster-dev/multi-class-anomaly-detection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250414475,"owners_count":21426595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T14:29:51.755Z","updated_at":"2025-04-23T10:26:01.638Z","avatar_url":"https://github.com/aimaster-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anomaly Detection System\nOfficial PyTorch Implementation of [A Unified Model for Multi-class Anomaly Detection], Accepted by NeurIPS 2022 Spotlight.\n\n![Image text](docs/setting.jpg)\n![Image text](docs/res_mvtec.jpg)\n\n## 1. Quick Start\n\n### 1.1 MVTec-AD\n\n- **Create the MVTec-AD dataset directory**. Download the MVTec-AD dataset from [here](https://www.mvtec.com/company/research/datasets/mvtec-ad). Unzip the file and move some to `./data/MVTec-AD/`. The MVTec-AD dataset directory should be as follows. \n\n```\n|-- data\n    |-- MVTec-AD\n        |-- mvtec_anomaly_detection\n        |-- json_vis_decoder\n        |-- train.json\n        |-- test.json\n```\n\n- **cd the experiment directory** by running `cd ./experiments/MVTec-AD/`. \n\n- **Train or eval** by running: \n\n    (1) For slurm group:  `sh train.sh #NUM_GPUS #PARTITION` or `sh eval.sh #NUM_GPUS #PARTITION`.\n\n    (2) For torch.distributed.launch:  `sh train_torch.sh #NUM_GPUS #GPU_IDS` or `sh eval_torch.sh #NUM_GPUS #GPU_IDS`, *e.g.*, train with GPUs 1,3,4,6 (4 GPUs in total): `sh train_torch.sh 4 1,3,4,6`.\n\n    **Note**: During eval, please *set config.saver.load_path* to load the checkpoints. \n\n- **Results and checkpoints**. \n\n| Platform | GPU | Detection AUROC | Localization AUROC | Checkpoints | Note |\n| ------ | ------ | ------ | ------ | ------ | ------ | \n| slurm group | 8 GPUs (NVIDIA Tesla V100 16GB)|  96.7 | 96.8 | [here](https://drive.google.com/file/d/1q03ysv_5VJATlDN-A-c9zvcTuyEeaQHG/view?usp=sharing) | ***A unified model for all categories*** |\n| torch.distributed.launch | 1 GPU (NVIDIA GeForce GTX 1080 Ti 11 GB)|  97.6 | 97.0 | [here](https://drive.google.com/file/d/1v282ZlibC-b0H9sjLUlOSCFNzEv-TIuh/view?usp=sharing) | ***A unified model for all categories*** |\n\n\n### 1.2 CIFAR-10\n\n- **Create the CIFAR-10 dataset directory**. Download the CIFAR-10 dataset from [here](http://www.cs.toronto.edu/~kriz/cifar.html). Unzip the file and move some to `./data/CIFAR-10/`. The CIFAR-10 dataset directory should be as follows. \n\n```\n|-- data\n    |-- CIFAR-10\n        |-- cifar-10-batches-py\n```\n\n- **cd the experiment directory** by running `cd ./experiments/CIFAR-10/01234/`. Here we take class 0,1,2,3,4 as normal samples, and other settings are similar.\n\n- **Train or eval** by running: \n\n    (1) For slurm group:  `sh train.sh #NUM_GPUS #PARTITION` or `sh eval.sh #NUM_GPUS #PARTITION`.\n\n    (2) For torch.distributed.launch:  `sh train_torch.sh #NUM_GPUS #GPU_IDS` or `sh eval_torch.sh #NUM_GPUS #GPU_IDS`.\n\n    **Note**: During eval, please *set config.saver.load_path* to load the checkpoints. \n\n- **Results and checkpoints**. Training on 8 GPUs (NVIDIA Tesla V100 16GB) results in following performance.\n\n| Normal Samples | {01234} | {56789} | {02468} | {13579} | Mean |\n| ------ | ------ | ------ | ------ | ------ | ------ |\n| AUROC | 84.4 | 79.6 | 93.0 | 89.1 | 86.5 |\n\n\n## 2. Visualize Reconstructed Features\n\nWe **highly recommend** to visualize reconstructed features, since this could directly prove that our UniAD *reconstructs anomalies to their corresponding normal samples*. \n\n### 2.1 Train Decoders for Visualization\n\n- **cd the experiment directory** by running `cd ./experiments/train_vis_decoder/`. \n\n- **Train** by running: \n\n    (1) For slurm group:  `sh train.sh #NUM_GPUS #PARTITION`.\n\n    (2) For torch.distributed.launch: `sh train_torch.sh #NUM_GPUS #GPU_IDS #CLASS_NAME`.\n\n    **Note**: for torch.distributed.launch, you should *train one vis_decoder for a specific class for one time*. \n\n### 2.2 Visualize Reconstructed Features\n\n- **cd the experiment directory** by running `cd ./experiments/vis_recon/`. \n\n- **Visualize** by running (only support 1 GPU): \n\n    (1) For slurm group:  `sh vis_recon.sh #PARTITION`.\n\n    (2) For torch.distributed.launch:  `sh vis_recon_torch.sh #CLASS_NAME`.\n\n    **Note**: for torch.distributed.launch, you should *visualize a specific class for one time*. \n\n## 3. Questions\n\n### 3.1 Explanation of Evaluation Results\n\nThe first line of the evaluation results are shown as follows. \n\n|  clsname   |   pixel  |   mean   |   max    |   std    |\n|:----------:|:--------:|:--------:|:--------:|:--------:|\n\nThe *pixel* means anomaly localization results. \n\nThe *mean*, *max*, and *std* mean **post-processing methods** for anomaly detection. That is to say, the anomaly localization result is an anomaly map with the shape of *H x W*. We need to *convert this map to a scalar* as the anomaly score for this whole image. For this convert, you have 3 options: \n\n- use the *mean* value of the anomaly map.\n- use the *max* value of the (averagely pooled) anomaly map.\n- use the *std* value of the anomaly map.\n\nIn our paper, we use *max* for MVTec-AD and *mean* for CIFAR-10. \n\n### 3.2 Visualize Learned Query Embedding\n\nIf you have finished the training of the main model and decoders (used for visualization) for MVTec-AD, you could also choose to visualize the learned query embedding in the main model. \n\n- **cd the experiment directory** by running `cd ./experiments/vis_query/`. \n\n- **Visualize** by running (only support 1 GPU): \n\n    (1) For slurm group:  `sh vis_query.sh #PARTITION`.\n\n    (2) For torch.distributed.launch:  `sh vis_query_torch.sh #CLASS_NAME`.\n\n    **Note**: for torch.distributed.launch, you should *visualize a specific class for one time*. \n\nSome results are very interesting. The learned query embedding partly contains some features of normal samples. However, we ***did not*** fully figure out this and this part ***was not*** included in our paper. \n\n![Image text](docs/query_bottle.jpg)\n![Image text](docs/query_capsule.jpg)\n\n## Acknowledgement\n\nWe use some codes from repositories including [detr](https://github.com/facebookresearch/detr) and [efficientnet](https://github.com/lukemelas/EfficientNet-PyTorch). \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faimaster-dev%2Fmulti-class-anomaly-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faimaster-dev%2Fmulti-class-anomaly-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faimaster-dev%2Fmulti-class-anomaly-detection/lists"}