{"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/on-the-use-of-mahalanobis-distance-for-out-of","title":"On the use of Mahalanobis distance for out-of-distribution detection with neural networks for medical imaging","arxiv_id":"2309.01488","date":"2023-09-04","proceeding":null,"authors":["Harry Anthony","Konstantinos Kamnitsas"],"abstract":"Implementing neural networks for clinical use in medical applications necessitates the ability for the network to detect when input data differs significantly from the training data, with the aim of preventing unreliable predictions. The community has developed several methods for out-of-distribution (OOD) detection, within which distance-based approaches - such as Mahalanobis distance - have shown potential. This paper challenges the prevailing community understanding that there is an optimal layer, or combination of layers, of a neural network for applying Mahalanobis distance for detection of any OOD pattern. Using synthetic artefacts to emulate OOD patterns, this paper shows the optimum layer to apply Mahalanobis distance changes with the type of OOD pattern, showing there is no one-fits-all solution. This paper also shows that separating this OOD detector into multiple detectors at different depths of the network can enhance the robustness for detecting different OOD patterns. These insights were validated on real-world OOD tasks, training models on CheXpert chest X-rays with no support devices, then using scans with unseen pacemakers (we manually labelled 50% of CheXpert for this research) and unseen sex as OOD cases. The results inform best-practices for the use of Mahalanobis distance for OOD detection. The manually annotated pacemaker labels and the project's code are available at: https://github.com/HarryAnthony/Mahalanobis-OOD-detection.","url_abs":"https://arxiv.org/abs/2309.01488v1","url_pdf":"https://arxiv.org/pdf/2309.01488v1.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":"on-the-use-of-mahalanobis-distance-for-out-of","repo_url":"https://github.com/harryanthony/mahalanobis-ood-detection","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"ood-detection","task_name":"Out of Distribution (OOD) Detection"},{"task_slug":"out-of-distribution-detection","task_name":"Out-of-Distribution Detection"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2309.01488","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2309.01488"}},"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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/harryanthony/mahalanobis-ood-detection","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_draft_wrong":1,"ran":2,"unverified":2},"by_repo_kind":{"official":{"samples":5,"ran":3,"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":"00e569acd6b45ef0","entry":"conv3x3","repo":"harryanthony/mahalanobis-ood-detection","repo_kind":"official","path":"source/models/wide_resnet.py","file_url":"https://github.com/harryanthony/mahalanobis-ood-detection/blob/HEAD/source/models/wide_resnet.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":"00e569acd6b45ef0"}},{"code_sha256_prefix":"02c257fc8aa0c3f2","entry":"enable_dropout","repo":"harryanthony/mahalanobis-ood-detection","repo_kind":"official","path":"source/methods/mcdp.py","file_url":"https://github.com/harryanthony/mahalanobis-ood-detection/blob/HEAD/source/methods/mcdp.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":"02c257fc8aa0c3f2"}},{"code_sha256_prefix":"b263e7f1e434932f","entry":"modify_transforms","repo":"harryanthony/mahalanobis-ood-detection","repo_kind":"official","path":"make_synthetic_artefacts.py","file_url":"https://github.com/harryanthony/mahalanobis-ood-detection/blob/HEAD/make_synthetic_artefacts.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":"b263e7f1e434932f"}},{"code_sha256_prefix":"1417b57e38ebb740","entry":"check_net_exists","repo":"harryanthony/mahalanobis-ood-detection","repo_kind":"official","path":"source/util/evaluate_network_utils.py","file_url":"https://github.com/harryanthony/mahalanobis-ood-detection/blob/HEAD/source/util/evaluate_network_utils.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":"1417b57e38ebb740"}},{"code_sha256_prefix":"0b7d5a15b3b0f516","entry":"perturb_x","repo":"harryanthony/mahalanobis-ood-detection","repo_kind":"official","path":"source/methods/odin.py","file_url":"https://github.com/harryanthony/mahalanobis-ood-detection/blob/HEAD/source/methods/odin.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":"0b7d5a15b3b0f516"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}