{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/a-unified-model-for-multi-class-anomaly","title":"A Unified Model for Multi-class Anomaly Detection","arxiv_id":"2206.03687","date":"2022-06-08","proceeding":null,"authors":["Zhiyuan You","Lei Cui","Yujun Shen","Kai Yang","Xin Lu","Yu Zheng","Xinyi Le"],"abstract":"Despite the rapid advance of unsupervised anomaly detection, existing methods require to train separate models for different objects. In this work, we present UniAD that accomplishes anomaly detection for multiple classes with a unified framework. Under such a challenging setting, popular reconstruction networks may fall into an \"identical shortcut\", where both normal and anomalous samples can be well recovered, and hence fail to spot outliers. To tackle this obstacle, we make three improvements. First, we revisit the formulations of fully-connected layer, convolutional layer, as well as attention layer, and confirm the important role of query embedding (i.e., within attention layer) in preventing the network from learning the shortcut. We therefore come up with a layer-wise query decoder to help model the multi-class distribution. Second, we employ a neighbor masked attention module to further avoid the information leak from the input feature to the reconstructed output feature. Third, we propose a feature jittering strategy that urges the model to recover the correct message even with noisy inputs. We evaluate our algorithm on MVTec-AD and CIFAR-10 datasets, where we surpass the state-of-the-art alternatives by a sufficiently large margin. For example, when learning a unified model for 15 categories in MVTec-AD, we surpass the second competitor on the tasks of both anomaly detection (from 88.1% to 96.5%) and anomaly localization (from 89.5% to 96.8%). Code is available at https://github.com/zhiyuanyou/UniAD.","url_abs":"https://arxiv.org/abs/2206.03687v3","url_pdf":"https://arxiv.org/pdf/2206.03687v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"a-unified-model-for-multi-class-anomaly","repo_url":"https://github.com/zhiyuanyou/uniad","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"anomaly-detection","task_name":"Anomaly Detection"},{"task_slug":"anomaly-localization","task_name":"Anomaly Localization"},{"task_slug":"multi-class-anomaly-detection","task_name":"Multi-class Anomaly Detection"},{"task_slug":"unsupervised-anomaly-detection","task_name":"Unsupervised Anomaly Detection"},{"task_slug":"model","task_name":"model"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/multi-class-anomaly-detection-on-mvtec-ad","task":"Multi-class Anomaly Detection","dataset":"MVTec AD","model":"UniAD","rank_in_archive_order":13,"of":13,"metrics":{"Detection AUROC":"96.5","Segmentation AUROC":"96.8"},"uses_additional_data":false}],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2206.03687","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2206.03687"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/zhiyuanyou/UniAD","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/zhiyuanyou/uniad","reach":null}],"summary":{"ran":6,"ran_fixture":2,"unverified":7},"by_repo_kind":{"official":{"samples":15,"ran":8,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"09b9c17fbe0d29e4","entry":"PositionEmbeddingLearned","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"09b9c17fbe0d29e4"}},{"code_sha256_prefix":"c74afaad75da67ca","entry":"PositionEmbeddingSine","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c74afaad75da67ca"}},{"code_sha256_prefix":"2e15a94ae3c582d9","entry":"TransformerDecoder","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"2e15a94ae3c582d9"}},{"code_sha256_prefix":"d32327f0af382e01","entry":"TransformerDecoderLayer","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d32327f0af382e01"}},{"code_sha256_prefix":"ff5b931728384843","entry":"TransformerEncoder","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ff5b931728384843"}},{"code_sha256_prefix":"4b270121cf640133","entry":"TransformerEncoderLayer","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4b270121cf640133"}},{"code_sha256_prefix":"d5b20d47c0675398","entry":"build_position_embedding","repo":"zhiyuanyou/UniAD","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/UniAD/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d5b20d47c0675398"}},{"code_sha256_prefix":"0c617154b24e553f","entry":"build_position_embedding","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0c617154b24e553f"}},{"code_sha256_prefix":"d93d5baaaf4faa9b","entry":"Transformer","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d93d5baaaf4faa9b"}},{"code_sha256_prefix":"b78aca6c49077d11","entry":"UniAD","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b78aca6c49077d11"}},{"code_sha256_prefix":"5b5f3715b5e5582a","entry":"init_weights_msra","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5b5f3715b5e5582a"}},{"code_sha256_prefix":"05bee06c0fc81a84","entry":"init_weights_normal","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"05bee06c0fc81a84"}},{"code_sha256_prefix":"240526ea95ba0d0c","entry":"init_weights_xavier","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"240526ea95ba0d0c"}},{"code_sha256_prefix":"9599fed324e3b1f2","entry":"initialize","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"9599fed324e3b1f2"}},{"code_sha256_prefix":"0d7628c3c2441737","entry":"initialize_from_cfg","repo":"zhiyuanyou/uniad","repo_kind":"official","path":"models/reconstructions/uniad.py","file_url":"https://github.com/zhiyuanyou/uniad/blob/HEAD/models/reconstructions/uniad.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0d7628c3c2441737"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}