{"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/clipn-for-zero-shot-ood-detection-teaching","title":"CLIPN for Zero-Shot OOD Detection: Teaching CLIP to Say No","arxiv_id":"2308.12213","date":"2023-08-23","proceeding":"ICCV 2023 1","authors":["Hualiang Wang","Yi Li","Huifeng Yao","Xiaomeng Li"],"abstract":"Out-of-distribution (OOD) detection refers to training the model on an in-distribution (ID) dataset to classify whether the input images come from unknown classes. Considerable effort has been invested in designing various OOD detection methods based on either convolutional neural networks or transformers. However, zero-shot OOD detection methods driven by CLIP, which only require class names for ID, have received less attention. This paper presents a novel method, namely CLIP saying no (CLIPN), which empowers the logic of saying no within CLIP. Our key motivation is to equip CLIP with the capability of distinguishing OOD and ID samples using positive-semantic prompts and negation-semantic prompts. Specifically, we design a novel learnable no prompt and a no text encoder to capture negation semantics within images. Subsequently, we introduce two loss functions: the image-text binary-opposite loss and the text semantic-opposite loss, which we use to teach CLIPN to associate images with no prompts, thereby enabling it to identify unknown samples. Furthermore, we propose two threshold-free inference algorithms to perform OOD detection by utilizing negation semantics from no prompts and the text encoder. Experimental results on 9 benchmark datasets (3 ID datasets and 6 OOD datasets) for the OOD detection task demonstrate that CLIPN, based on ViT-B-16, outperforms 7 well-used algorithms by at least 2.34% and 11.64% in terms of AUROC and FPR95 for zero-shot OOD detection on ImageNet-1K. Our CLIPN can serve as a solid foundation for effectively leveraging CLIP in downstream OOD tasks. The code is available on https://github.com/xmed-lab/CLIPN.","url_abs":"https://arxiv.org/abs/2308.12213v2","url_pdf":"https://arxiv.org/pdf/2308.12213v2.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":"clipn-for-zero-shot-ood-detection-teaching","repo_url":"https://github.com/xmed-lab/clipn","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"negation","task_name":"Negation"},{"task_slug":"ood-detection","task_name":"Out of Distribution (OOD) Detection"},{"task_slug":"out-of-distribution-detection","task_name":"Out-of-Distribution Detection"}],"methods":[{"method_slug":"clip","method_name":"CLIP"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2308.12213","atlas_url":"https://app.syntology.ai/?focus=2308.12213","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2308.12213"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/xmed-lab/clipn","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/xmed-lab/CLIPN","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":8,"ran_draft_wrong":2,"unverified":6},"by_repo_kind":{"official":{"samples":16,"ran":10,"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":"398dd84d8c1a0c99","entry":"ClipLoss","repo":"xmed-lab/CLIPN","repo_kind":"official","path":"hand-crafted/src/open_clip/loss.py","file_url":"https://github.com/xmed-lab/CLIPN/blob/HEAD/hand-crafted/src/open_clip/loss.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"398dd84d8c1a0c99"}},{"code_sha256_prefix":"2d5d7a12d8de02b7","entry":"cosine_lr","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/tuning_util.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/tuning_util.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2d5d7a12d8de02b7"}},{"code_sha256_prefix":"77aa71bc99c32b88","entry":"energy_score","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/zero_shot_infer.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/zero_shot_infer.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"77aa71bc99c32b88"}},{"code_sha256_prefix":"570302e9d15c6b9b","entry":"energy_score","repo":"xmed-lab/clipn","repo_kind":"official","path":"hand-crafted/src/zero_shot_infer.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/hand-crafted/src/zero_shot_infer.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"570302e9d15c6b9b"}},{"code_sha256_prefix":"5e42380894ae9205","entry":"load_state_dict","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/open_clip/factory.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/open_clip/factory.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5e42380894ae9205"}},{"code_sha256_prefix":"72166ecea4b59f55","entry":"load_state_dict_local","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/open_clip/factory.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/open_clip/factory.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"72166ecea4b59f55"}},{"code_sha256_prefix":"6ae44ac0f19069aa","entry":"max_logit_score","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/zero_shot_infer.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/zero_shot_infer.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6ae44ac0f19069aa"}},{"code_sha256_prefix":"b1e9e0d3d7d7e615","entry":"maybe_dictionarize","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/tuning_util.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/tuning_util.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b1e9e0d3d7d7e615"}},{"code_sha256_prefix":"be2496a325c68b28","entry":"msp_score","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/zero_shot_infer.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/zero_shot_infer.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"be2496a325c68b28"}},{"code_sha256_prefix":"8e95157106d1df8c","entry":"trace_model","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/open_clip/model.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/open_clip/model.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8e95157106d1df8c"}},{"code_sha256_prefix":"aafcff3ad1ccef6e","entry":"accuracy","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/tuning_util.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/tuning_util.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"aafcff3ad1ccef6e"}},{"code_sha256_prefix":"630cd10269e63c8c","entry":"build_model_from_openai_state_dict","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/open_clip/model.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/open_clip/model.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"630cd10269e63c8c"}},{"code_sha256_prefix":"61c4ca21dc698a56","entry":"gather_features","repo":"xmed-lab/CLIPN","repo_kind":"official","path":"hand-crafted/src/open_clip/loss.py","file_url":"https://github.com/xmed-lab/CLIPN/blob/HEAD/hand-crafted/src/open_clip/loss.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"61c4ca21dc698a56"}},{"code_sha256_prefix":"69e67ef52fe6fde8","entry":"load_checkpoint","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/open_clip/factory.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/open_clip/factory.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"69e67ef52fe6fde8"}},{"code_sha256_prefix":"ce3d74d26643c4c1","entry":"load_openai_model","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/open_clip/openai.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/open_clip/openai.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ce3d74d26643c4c1"}},{"code_sha256_prefix":"2235e9caabb77a27","entry":"torch_load","repo":"xmed-lab/clipn","repo_kind":"official","path":"src/classification.py","file_url":"https://github.com/xmed-lab/clipn/blob/HEAD/src/classification.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2235e9caabb77a27"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}