{"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/egc-image-generation-and-classification-via-a","title":"EGC: Image Generation and Classification via a Diffusion Energy-Based Model","arxiv_id":"2304.02012","date":"2023-04-04","proceeding":"ICCV 2023 1","authors":["Qiushan Guo","Chuofan Ma","Yi Jiang","Zehuan Yuan","Yizhou Yu","Ping Luo"],"abstract":"Learning image classification and image generation using the same set of network parameters is a challenging problem. Recent advanced approaches perform well in one task often exhibit poor performance in the other. This work introduces an energy-based classifier and generator, namely EGC, which can achieve superior performance in both tasks using a single neural network. Unlike a conventional classifier that outputs a label given an image (i.e., a conditional distribution $p(y|\\mathbf{x})$), the forward pass in EGC is a classifier that outputs a joint distribution $p(\\mathbf{x},y)$, enabling an image generator in its backward pass by marginalizing out the label $y$. This is done by estimating the energy and classification probability given a noisy image in the forward pass, while denoising it using the score function estimated in the backward pass. EGC achieves competitive generation results compared with state-of-the-art approaches on ImageNet-1k, CelebA-HQ and LSUN Church, while achieving superior classification accuracy and robustness against adversarial attacks on CIFAR-10. This work represents the first successful attempt to simultaneously excel in both tasks using a single set of network parameters. We believe that EGC bridges the gap between discriminative and generative learning.","url_abs":"https://arxiv.org/abs/2304.02012v3","url_pdf":"https://arxiv.org/pdf/2304.02012v3.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":"egc-image-generation-and-classification-via-a","repo_url":"https://github.com/guoqiushan/egc","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"denoising","task_name":"Denoising"},{"task_slug":"image-classification","task_name":"Image Classification"},{"task_slug":"image-generation","task_name":"Image Generation"},{"task_slug":"image-classification","task_name":"image-classification"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2304.02012","atlas_url":"https://app.syntology.ai/?focus=2304.02012","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2304.02012"}},"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/guoqiushan/egc","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/GuoQiushan/EGC","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":4,"unverified":4},"by_repo_kind":{"official":{"samples":8,"ran":4,"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":"5eab1eccceac91bf","entry":"AttentionPool2d","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"5eab1eccceac91bf"}},{"code_sha256_prefix":"9e0b6eeb542371a5","entry":"BasicTransformerBlock","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"9e0b6eeb542371a5"}},{"code_sha256_prefix":"351f5f1606153b33","entry":"CrossAttention","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"351f5f1606153b33"}},{"code_sha256_prefix":"86185c77f09e88ae","entry":"SimpleAttentionPool2d","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"86185c77f09e88ae"}},{"code_sha256_prefix":"5a301ab7b2e327ed","entry":"AttentionBlock","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"5a301ab7b2e327ed"}},{"code_sha256_prefix":"76ab12cf164568c7","entry":"EBMUNetModel","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"76ab12cf164568c7"}},{"code_sha256_prefix":"d126370ebe777d9d","entry":"SpatialTransformer","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"d126370ebe777d9d"}},{"code_sha256_prefix":"0a27379d61f545ac","entry":"TimestepEmbedSequential","repo":"GuoQiushan/EGC","repo_kind":"official","path":"guided_diffusion/unet.py","file_url":"https://github.com/GuoQiushan/EGC/blob/HEAD/guided_diffusion/unet.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":"0a27379d61f545ac"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}