{"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/ecinn-efficient-counterfactuals-from","title":"ECINN: Efficient Counterfactuals from Invertible Neural Networks","arxiv_id":"2103.13701","date":"2021-03-25","proceeding":null,"authors":["Frederik Hvilshøj","Alexandros Iosifidis","Ira Assent"],"abstract":"Counterfactual examples identify how inputs can be altered to change the predicted class of a classifier, thus opening up the black-box nature of, e.g., deep neural networks. We propose a method, ECINN, that utilizes the generative capacities of invertible neural networks for image classification to generate counterfactual examples efficiently. In contrast to competing methods that sometimes need a thousand evaluations or more of the classifier, ECINN has a closed-form expression and generates a counterfactual in the time of only two evaluations. Arguably, the main challenge of generating counterfactual examples is to alter only input features that affect the predicted outcome, i.e., class-dependent features. Our experiments demonstrate how ECINN alters class-dependent image regions to change the perceptual and predicted class of the counterfactuals. Additionally, we extend ECINN to also produce heatmaps (ECINNh) for easy inspection of, e.g., pairwise class-dependent changes in the generated counterfactual examples. Experimentally, we find that ECINNh outperforms established methods that generate heatmap-based explanations.","url_abs":"https://arxiv.org/abs/2103.13701v2","url_pdf":"https://arxiv.org/pdf/2103.13701v2.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":"ecinn-efficient-counterfactuals-from","repo_url":"https://github.com/fhvilshoj/ecinn","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"image-classification","task_name":"Image Classification"},{"task_slug":null,"task_name":"counterfactual"},{"task_slug":"image-classification","task_name":"image-classification"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2103.13701","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2103.13701"}},"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/fhvilshoj/ecinn","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":6},"by_repo_kind":{"listed":{"samples":6,"ran":0,"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":"36b06b5a75621b75","entry":"find_alpha","repo":"fhvilshoj/ecinn","repo_kind":"listed","path":"counterfactual/compute_and_store.py","file_url":"https://github.com/fhvilshoj/ecinn/blob/HEAD/counterfactual/compute_and_store.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":"36b06b5a75621b75"}},{"code_sha256_prefix":"72efcbcd9f4adb20","entry":"get_samples","repo":"fhvilshoj/ecinn","repo_kind":"listed","path":"counterfactual/cf_utils.py","file_url":"https://github.com/fhvilshoj/ecinn/blob/HEAD/counterfactual/cf_utils.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":"72efcbcd9f4adb20"}},{"code_sha256_prefix":"642a01173a04514f","entry":"mean_embeddings","repo":"fhvilshoj/ecinn","repo_kind":"listed","path":"counterfactual/counterfactuals.py","file_url":"https://github.com/fhvilshoj/ecinn/blob/HEAD/counterfactual/counterfactuals.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":"642a01173a04514f"}},{"code_sha256_prefix":"eb78cf906deee8f7","entry":"one_hot","repo":"fhvilshoj/ecinn","repo_kind":"listed","path":"counterfactual/cf_utils.py","file_url":"https://github.com/fhvilshoj/ecinn/blob/HEAD/counterfactual/cf_utils.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":"eb78cf906deee8f7"}},{"code_sha256_prefix":"8897e58ddd7109e8","entry":"pairwise_distances","repo":"fhvilshoj/ecinn","repo_kind":"listed","path":"counterfactual/distances.py","file_url":"https://github.com/fhvilshoj/ecinn/blob/HEAD/counterfactual/distances.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":"8897e58ddd7109e8"}},{"code_sha256_prefix":"6d50aae469813486","entry":"posterior","repo":"fhvilshoj/ecinn","repo_kind":"listed","path":"counterfactual/counterfactuals.py","file_url":"https://github.com/fhvilshoj/ecinn/blob/HEAD/counterfactual/counterfactuals.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":"6d50aae469813486"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}