{"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/contrasting-deepfakes-diffusion-via","title":"Contrasting Deepfakes Diffusion via Contrastive Learning and Global-Local Similarities","arxiv_id":"2407.20337","date":"2024-07-29","proceeding":null,"authors":["Federico Cocchi","Marcella Cornia","Lorenzo Baraldi","Alessandro Nicolosi","Rita Cucchiara"],"abstract":"Discerning between authentic content and that generated by advanced AI methods has become increasingly challenging. While previous research primarily addresses the detection of fake faces, the identification of generated natural images has only recently surfaced. This prompted the recent exploration of solutions that employ foundation vision-and-language models, like CLIP. However, the CLIP embedding space is optimized for global image-to-text alignment and is not inherently designed for deepfake detection, neglecting the potential benefits of tailored training and local image features. In this study, we propose CoDE (Contrastive Deepfake Embeddings), a novel embedding space specifically designed for deepfake detection. CoDE is trained via contrastive learning by additionally enforcing global-local similarities. To sustain the training of our model, we generate a comprehensive dataset that focuses on images generated by diffusion models and encompasses a collection of 9.2 million images produced by using four different generators. Experimental results demonstrate that CoDE achieves state-of-the-art accuracy on the newly collected dataset, while also showing excellent generalization capabilities to unseen image generators. Our source code, trained models, and collected dataset are publicly available at: https://github.com/aimagelab/CoDE.","url_abs":"https://arxiv.org/abs/2407.20337v1","url_pdf":"https://arxiv.org/pdf/2407.20337v1.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":"contrasting-deepfakes-diffusion-via","repo_url":"https://github.com/aimagelab/code","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"contrastive-learning","task_name":"Contrastive Learning"},{"task_slug":"deepfake-detection","task_name":"DeepFake Detection"},{"task_slug":"face-swapping","task_name":"Face Swapping"},{"task_slug":"image-to-text","task_name":"Image to text"}],"methods":[{"method_slug":"clip","method_name":"CLIP"},{"method_slug":"contrastive-learning","method_name":"Contrastive Learning"},{"method_slug":"diffusion","method_name":"Diffusion"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2407.20337","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2407.20337"}},"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/aimagelab/code","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":7,"unverified":1},"by_repo_kind":{"official":{"samples":8,"ran":7,"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":"76293afb49fb8256","entry":"custom_range","repo":"aimagelab/code","repo_kind":"official","path":"src/dataset/CustomTransform.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/dataset/CustomTransform.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":"76293afb49fb8256"}},{"code_sha256_prefix":"86961d87fd5fab69","entry":"cv2_jpg","repo":"aimagelab/code","repo_kind":"official","path":"src/dataset/standardtransform.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/dataset/standardtransform.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"86961d87fd5fab69"}},{"code_sha256_prefix":"2d3091c8c8848b77","entry":"load_all_dictionary","repo":"aimagelab/code","repo_kind":"official","path":"src/data_download/download_elsa_v2.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/data_download/download_elsa_v2.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":"2d3091c8c8848b77"}},{"code_sha256_prefix":"ca7e7f75bdff0684","entry":"load_faulty_parquet","repo":"aimagelab/code","repo_kind":"official","path":"src/data_download/download_elsa_v2.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/data_download/download_elsa_v2.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":"ca7e7f75bdff0684"}},{"code_sha256_prefix":"5113cb3c7498031a","entry":"np_images","repo":"aimagelab/code","repo_kind":"official","path":"src/data_download/wds_creation.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/data_download/wds_creation.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":"5113cb3c7498031a"}},{"code_sha256_prefix":"5632d030545bf59a","entry":"pil_jpg","repo":"aimagelab/code","repo_kind":"official","path":"src/dataset/standardtransform.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/dataset/standardtransform.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":"5632d030545bf59a"}},{"code_sha256_prefix":"e3287363e619218a","entry":"sample_discrete","repo":"aimagelab/code","repo_kind":"official","path":"src/dataset/standardtransform.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/dataset/standardtransform.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e3287363e619218a"}},{"code_sha256_prefix":"e151f6cecae4a02d","entry":"tar_creation","repo":"aimagelab/code","repo_kind":"official","path":"src/data_download/wds_creation.py","file_url":"https://github.com/aimagelab/code/blob/HEAD/src/data_download/wds_creation.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":"e151f6cecae4a02d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}