{"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/linear-semantics-in-generative-adversarial","title":"Linear Semantics in Generative Adversarial Networks","arxiv_id":"2104.00487","date":"2021-04-01","proceeding":"CVPR 2021 1","authors":["Jianjin Xu","Changxi Zheng"],"abstract":"Generative Adversarial Networks (GANs) are able to generate high-quality images, but it remains difficult to explicitly specify the semantics of synthesized images. In this work, we aim to better understand the semantic representation of GANs, and thereby enable semantic control in GAN's generation process. Interestingly, we find that a well-trained GAN encodes image semantics in its internal feature maps in a surprisingly simple way: a linear transformation of feature maps suffices to extract the generated image semantics. To verify this simplicity, we conduct extensive experiments on various GANs and datasets; and thanks to this simplicity, we are able to learn a semantic segmentation model for a trained GAN from a small number (e.g., 8) of labeled images. Last but not least, leveraging our findings, we propose two few-shot image editing approaches, namely Semantic-Conditional Sampling and Semantic Image Editing. Given a trained GAN and as few as eight semantic annotations, the user is able to generate diverse images subject to a user-provided semantic layout, and control the synthesized image semantics. We have made the code publicly available.","url_abs":"https://arxiv.org/abs/2104.00487v1","url_pdf":"https://arxiv.org/pdf/2104.00487v1.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":"linear-semantics-in-generative-adversarial","repo_url":"https://github.com/AtlantixJJ/LinearGAN","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"semantic-segmentation","task_name":"Semantic Segmentation"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2104.00487","atlas_url":"https://app.syntology.ai/?focus=2104.00487","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2104.00487"}},"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/AtlantixJJ/LinearGAN","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":12,"unverified":3},"by_repo_kind":{"official":{"samples":15,"ran":12,"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":"bc4b2e8dd74b03fe","entry":"aggregate_iou","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"evaluate.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/evaluate.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":"bc4b2e8dd74b03fe"}},{"code_sha256_prefix":"5dd080ab390953df","entry":"formal_name","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"figure/layer_plot.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/figure/layer_plot.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":"5dd080ab390953df"}},{"code_sha256_prefix":"fd34493454efc92f","entry":"gaussian_func","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/op.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/op.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":"fd34493454efc92f"}},{"code_sha256_prefix":"18a135c1c6e8a12e","entry":"get_label_color","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/visualizer.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/visualizer.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":"18a135c1c6e8a12e"}},{"code_sha256_prefix":"6d654ffc5a2f11c6","entry":"int2onehot","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/op.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/op.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":"6d654ffc5a2f11c6"}},{"code_sha256_prefix":"51c0c1703f9f7417","entry":"lerp","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/op.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/op.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":"51c0c1703f9f7417"}},{"code_sha256_prefix":"7c24cc243ee9ccfb","entry":"mask_cross_entropy_loss","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/loss.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/loss.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":"7c24cc243ee9ccfb"}},{"code_sha256_prefix":"b4015457d599aa2b","entry":"mask_focal_loss","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/loss.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/loss.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":"b4015457d599aa2b"}},{"code_sha256_prefix":"eee4b2def7c9d062","entry":"read_ade20k_labels","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/misc.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/misc.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":"eee4b2def7c9d062"}},{"code_sha256_prefix":"a4df817ebb088365","entry":"read_results","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"evaluate.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/evaluate.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":"a4df817ebb088365"}},{"code_sha256_prefix":"1a392f9ca44359d5","entry":"read_selected_labels","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/misc.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/misc.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":"1a392f9ca44359d5"}},{"code_sha256_prefix":"0214a8f261e7bb84","entry":"set_cuda_devices","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"lib/misc.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/lib/misc.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":"0214a8f261e7bb84"}},{"code_sha256_prefix":"2d79fedbd2e3646f","entry":"G_from_SE","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"evaluate.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/evaluate.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":"2d79fedbd2e3646f"}},{"code_sha256_prefix":"fb61c14dfdff06f2","entry":"get_classes","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"figure/layer_plot.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/figure/layer_plot.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":"fb61c14dfdff06f2"}},{"code_sha256_prefix":"a3f50a610e7c3cd8","entry":"get_text","repo":"AtlantixJJ/LinearGAN","repo_kind":"official","path":"figure/layer_plot.py","file_url":"https://github.com/AtlantixJJ/LinearGAN/blob/HEAD/figure/layer_plot.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":"a3f50a610e7c3cd8"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}