{"id":23377517,"url":"https://github.com/narcissusex/hetmm","last_synced_at":"2025-04-10T19:32:52.378Z","repository":{"id":267212007,"uuid":"897716101","full_name":"NarcissusEx/HETMM","owner":"NarcissusEx","description":"[IJCV 2024] Hard-normal Example-aware Template Mutual Matching for Industrial Anomaly Detection","archived":false,"fork":false,"pushed_at":"2025-01-01T17:45:37.000Z","size":407,"stargazers_count":15,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T17:11:21.232Z","etag":null,"topics":["anomaly-detection","anomaly-localization","ijcv","pytorch","training-free","unsupervised"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NarcissusEx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-12-03T05:36:44.000Z","updated_at":"2025-03-23T13:13:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"4b49a4af-f429-4a34-bb0b-bc9b92bace63","html_url":"https://github.com/NarcissusEx/HETMM","commit_stats":null,"previous_names":["narcissusex/hetmm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NarcissusEx%2FHETMM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NarcissusEx%2FHETMM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NarcissusEx%2FHETMM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NarcissusEx%2FHETMM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NarcissusEx","download_url":"https://codeload.github.com/NarcissusEx/HETMM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281415,"owners_count":21077423,"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":["anomaly-detection","anomaly-localization","ijcv","pytorch","training-free","unsupervised"],"created_at":"2024-12-21T18:14:56.968Z","updated_at":"2025-04-10T19:32:52.369Z","avatar_url":"https://github.com/NarcissusEx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hard-normal Example-aware Template Mutual Matching for Industrial Anomaly Detection\n\n[Zixuan Chen](https://narcissusex.github.io), [Xiaohua Xie](https://cse.sysu.edu.cn/content/2478), [Lingxiao Yang](https://zjjconan.github.io/), [Jian-Huang Lai](https://cse.sysu.edu.cn/content/2498),\n\n*International Journal of Computer Vision (**IJCV**)*, 2024.\n\n**TL;DR:** HETMM is a simple yet effective framework for industrial anomaly detection based on template matching, which can accurately detect and locate unknown anomalies in a training-free manner.\n\n---\n[![Paper](https://img.shields.io/badge/Paper-1?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAADIAAAAuCAYAAABqK0pRAAAKAElEQVRo3u1aWW8b1xlNkfahQG0nLlwg6IIW%2FQnuH%2Bjv6PbsN%2F8Bo08BGsBLU%2BexNYq2iW35wW%2FKQ2HXjrWLnBmSM9xFiqS4WItJStRCUvLXc747Q116QUPJdRIgA1zM8M72Leec77sjvfPOt9u329drE5Fzg8HgV%2F3%2B8MN%2Bv%2F%2Fv%2Ff39eYy5%2F8c4ODiwfh%2Fo7z28r1Zb%2BytM%2Be6Xsfc7luHvDYfDD4%2BOjq5h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X%2FmH9Gaz%2BaNer%2Feo0%2Bn43W439bYG33f%2F%2Fv3fXb58%2BYNLly79NBrnz7%2FG0C%2FzTwEXLlz4wblz597HeO8tjvfx7u%2B9qf%2FE%2BC%2FkEJZILUQcyQAAAABJRU5ErkJggg%3D%3D\u0026label=IJCV)](https://link.springer.com/article/10.1007/s11263-024-02323-0)\n[![ArXiv](https://img.shields.io/badge/cs.CV-2303.16191-b31b1b?logo=arxiv\u0026logoColor=red)](https://arxiv.org/abs/2303.16191)\n[![Google Drive](https://img.shields.io/badge/Material-1?logo=googledrive\u0026label=Google%20Drive)](https://drive.google.com/drive/folders/1c4XvmugX-ryP168bDMFcScdiYWgYktlu?usp=drive_link)\n[![Baidu Cloud](https://img.shields.io/badge/Materials-ryP168bDMFcScdiYWgYktlu%3Fusp%3Ddrive_link?logo=Baidu\u0026label=Baidu%20Cloud)](https://pan.baidu.com/s/1HH_3FQo1K72HbUvZpfylxw?pwd=eeg9)\n\n\t\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/hard-nominal-example-aware-template-mutual/anomaly-detection-on-mvtec-ad)](https://paperswithcode.com/sota/anomaly-detection-on-mvtec-ad?p=hard-nominal-example-aware-template-mutual)\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/hard-nominal-example-aware-template-mutual/anomaly-detection-on-visa)](https://paperswithcode.com/sota/anomaly-detection-on-visa?p=hard-nominal-example-aware-template-mutual)\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/hard-nominal-example-aware-template-mutual/anomaly-detection-on-surface-defect-saliency)](https://paperswithcode.com/sota/anomaly-detection-on-surface-defect-saliency?p=hard-nominal-example-aware-template-mutual)\n\n## Motivation\n\u003cdiv align=center\u003e\n\u003cimg width=\"1148\" alt=\"framework\" src=\"assets/hetmm.png\"\u003e\n\u003c/div\u003e\n\n\u003cb\u003eVisualization of training data (ball) and queries (cube) via t-SNE\u003c/b\u003e. Visually, existing methods' decision boundaries are dominated by the overwhelming number of easy-normal examples (\u003cb\u003e\u003cfont style=\"color:#3288A0\"\u003eblue balls\u003c/font\u003e\u003c/b\u003e). Hence, the normal queries (\u003cb\u003e\u003cfont style=\"color:#6DA945\"\u003egreen cubes\u003c/font\u003e\u003c/b\u003e) near the hard-normal examples (\u003cb\u003e\u003cfont style=\"color:#EB720E\"\u003eorange balls\u003c/font\u003e\u003c/b\u003e) are prone to be erroneously identified as anomalies (\u003cb\u003e\u003cfont style=\"color:#B477FD\"\u003epurple cubes\u003c/font\u003e\u003c/b\u003e), resulting in a high false-positive or missed-detection rate. To address this issue, we propose \u003cb\u003eHETMM\u003c/b\u003e to construct a robust prototype-based decision boundary, which can accurately distinguish hard-normal examples from anomalies.\n\n## Framework\n\u003cdiv align=center\u003e\n\u003cimg width=\"1148\" alt=\"framework\" src=\"assets/framework.png\"\u003e\n\u003c/div\u003e\n\n\u003cb\u003eThe overall framework of our methods.\u003c/b\u003e In \u003cb\u003estage I\u003c/b\u003e, the original template set $\\mathcal{T}^{(j)}$ is the aggregation of the features extracted by feeding $N$ collected normal images $\\mathcal{Z}$ into the pre-trained backbone $\\Phi$ with $M$ layers, where each color on $\\mathcal{T}^{(j)}$ denotes that the feature is extracted from different normal images. To streamline $\\mathcal{T}^{(j)}$ into a tiny set $\\mathcal{T}^{(j)K}$ with $K$ sheets ($N\\ge K$), \u003cb\u003ePTS\u003c/b\u003e selects $K$ significant prototypes from $\\mathcal{T}^{(j)}$ at each pixel coordinate through the sliding windows. In \u003cb\u003estage II\u003c/b\u003e, given a query image $q$, we first extract its features by the same pre-trained backbone $\\Phi$ and then employ \u003cb\u003eATMM\u003c/b\u003e to obtain hierarchical anomaly maps $S^{(j)}$, where each $S^{(j)}$ is generated at the $j$-th layer. $S^\\dagger$ is obtained as the final outputs.\n\n## Code Usage\n### 1) Get start\n\n* Python 3.9.x\n* CUDA 11.1 or *higher*\n* NVIDIA RTX 3090\n* Torch 1.8.0 or *higher*\n\n**Create a python env using conda**\n```bash\nconda create -n hetmm python=3.9 -y\nconda activate hetmm\n```\n\n**Install the required libraries**\n```bash\nbash setup.sh\n```\n\n### 2) Template Generation\n**Original template set on MVTec AD:**\n```bash\npython run.py --mode temp --ttype ALL --dataset MVTec_AD --datapath \u003cdata_path\u003e\n```\n**Tiny set formed by PTS (60 sheets) on MVTec AD:**\n```bash\npython run.py --mode temp --ttype PTS --tsize 60 --dataset MVTec_AD --datapath \u003cdata_path\u003e\n```\nSince generating pixel-level OPTICS clusters is time-consuming, you can download the \"*template*\" folder from [Google Drive](https://drive.google.com/drive/folders/1c4XvmugX-ryP168bDMFcScdiYWgYktlu?usp=drive_link) / [Baidu Cloud](https://pan.baidu.com/s/1HH_3FQo1K72HbUvZpfylxw?pwd=eeg9) and copy it into our main folder as:\n```\nHETMM/\n    ├── configs/\n    ├── template/\n    ├── src/\n    ├── run.py\n    └── ...\n```\n\n### 3) Anomaly Prediction\n**Original template set on MVTec AD:**\n```bash\npython run.py --mode test --ttype ALL --dataset MVTec_AD --datapath \u003cdata_path\u003e\n```\n**Tiny set formed by PTS (60 sheets) on MVTec AD:**\n```bash\npython run.py --mode test --ttype PTS --tsize 60 --dataset MVTec_AD --datapath \u003cdata_path\u003e\n```\nPlease see \"*run.sh*\" and \"*run.py*\" for more details.\n\n## Citation\n\n```tex\n@article{Chen_2024_hetmm,\n    author    = {Chen, Zixuan and Xie, Xiaohua and Yang, Lingxiao and Lai, Jianhuang},\n    title     = {Hard-normal Example-aware Template Mutual Matching for Industrial Anomaly Detection},\n    journal   = {International Journal of Computer Vision (IJCV)},\n    publisher = {Springer},\n    year      = {2024},\n    doi       = {10.1007/s11263-024-02323-0},\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarcissusex%2Fhetmm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarcissusex%2Fhetmm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarcissusex%2Fhetmm/lists"}