{"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/locoop-few-shot-out-of-distribution-detection-1","title":"LoCoOp: Few-Shot Out-of-Distribution Detection via Prompt Learning","arxiv_id":"2306.01293","date":"2023-06-02","proceeding":"NeurIPS 2023 11","authors":["Atsuyuki Miyai","Qing Yu","Go Irie","Kiyoharu Aizawa"],"abstract":"We present a novel vision-language prompt learning approach for few-shot out-of-distribution (OOD) detection. Few-shot OOD detection aims to detect OOD images from classes that are unseen during training using only a few labeled in-distribution (ID) images. While prompt learning methods such as CoOp have shown effectiveness and efficiency in few-shot ID classification, they still face limitations in OOD detection due to the potential presence of ID-irrelevant information in text embeddings. To address this issue, we introduce a new approach called Local regularized Context Optimization (LoCoOp), which performs OOD regularization that utilizes the portions of CLIP local features as OOD features during training. CLIP's local features have a lot of ID-irrelevant nuisances (e.g., backgrounds), and by learning to push them away from the ID class text embeddings, we can remove the nuisances in the ID class text embeddings and enhance the separation between ID and OOD. Experiments on the large-scale ImageNet OOD detection benchmarks demonstrate the superiority of our LoCoOp over zero-shot, fully supervised detection methods and prompt learning methods. Notably, even in a one-shot setting -- just one label per class, LoCoOp outperforms existing zero-shot and fully supervised detection methods. The code will be available via https://github.com/AtsuMiyai/LoCoOp.","url_abs":"https://arxiv.org/abs/2306.01293v3","url_pdf":"https://arxiv.org/pdf/2306.01293v3.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":"locoop-few-shot-out-of-distribution-detection-1","repo_url":"https://github.com/atsumiyai/locoop","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"locoop-few-shot-out-of-distribution-detection-1","repo_url":"https://github.com/haiv-lab/ospcoop_imagenet-bg","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"ood-detection","task_name":"Out of Distribution (OOD) Detection"},{"task_slug":"out-of-distribution-detection","task_name":"Out-of-Distribution Detection"},{"task_slug":"prompt-learning","task_name":"Prompt Learning"}],"methods":[{"method_slug":"clip","method_name":"CLIP"},{"method_slug":"coop","method_name":"CoOp"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2306.01293","atlas_url":"https://app.syntology.ai/?focus=2306.01293","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2306.01293"}},"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":"deterministic:regex_extraction","url":"https://github.com/openai/CLIP","reach":{"status":"unanswered"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/AtsuMiyai/LoCoOp","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/deeplearning-wisc/large_scale_ood","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/atsumiyai/locoop","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/haiv-lab/ospcoop_imagenet-bg","reach":{"status":"ok"}}],"summary":{"ran_draft_wrong":3,"ran_fixture":1,"ran_honours":1,"unverified":7},"by_repo_kind":{"official":{"samples":12,"ran":5,"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":"98f385d847636a3e","entry":"basic_clean","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"clip_w_local/simple_tokenizer.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/clip_w_local/simple_tokenizer.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"98f385d847636a3e"}},{"code_sha256_prefix":"3853ecdb6fc74451","entry":"fpr_and_fdr_at_recall","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"utils/detection_util.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/utils/detection_util.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3853ecdb6fc74451"}},{"code_sha256_prefix":"d919ae32e5e4e616","entry":"get_pairs","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"clip_w_local/simple_tokenizer.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/clip_w_local/simple_tokenizer.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":"d919ae32e5e4e616"}},{"code_sha256_prefix":"d4acb3120a027622","entry":"stable_cumsum","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"utils/detection_util.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/utils/detection_util.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d4acb3120a027622"}},{"code_sha256_prefix":"9542161e9640b858","entry":"whitespace_clean","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"clip_w_local/simple_tokenizer.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/clip_w_local/simple_tokenizer.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9542161e9640b858"}},{"code_sha256_prefix":"dbbf313e1d3a69ba","entry":"build_model","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"clip_w_local/model.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/clip_w_local/model.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":"dbbf313e1d3a69ba"}},{"code_sha256_prefix":"65319c2dbd4ac5e8","entry":"entropy_select_topk","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"trainers/locoop.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/trainers/locoop.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":"65319c2dbd4ac5e8"}},{"code_sha256_prefix":"24570af601666d85","entry":"get_measures","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"utils/detection_util.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/utils/detection_util.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":"24570af601666d85"}},{"code_sha256_prefix":"fbf8c0143d9c48e3","entry":"load","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"clip_w_local/clip.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/clip_w_local/clip.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":"fbf8c0143d9c48e3"}},{"code_sha256_prefix":"f8757a034583434b","entry":"load_resize_image","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"demo_visualization.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/demo_visualization.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":"f8757a034583434b"}},{"code_sha256_prefix":"eb7800d0c58c4a14","entry":"set_ood_loader_ImageNet","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"utils/train_eval_util.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/utils/train_eval_util.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":"eb7800d0c58c4a14"}},{"code_sha256_prefix":"eb2c2fac20121ca2","entry":"set_val_loader","repo":"AtsuMiyai/LoCoOp","repo_kind":"official","path":"utils/train_eval_util.py","file_url":"https://github.com/AtsuMiyai/LoCoOp/blob/HEAD/utils/train_eval_util.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":"eb2c2fac20121ca2"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}