{"id":36393,"date":"2024-11-01T09:48:08","date_gmt":"2024-11-01T09:48:08","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36393"},"modified":"2024-11-01T11:00:06","modified_gmt":"2024-11-01T11:00:06","slug":"using-pytorch-for-gan-deep-learning-first-cyclegan","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36393\/","title":{"rendered":"Using PyTorch for GAN Deep Learning, First CycleGAN"},"content":{"rendered":"<p>One of the innovative advancements in artificial intelligence is the emergence of Generative Adversarial Networks (GANs). GAN consists of a structure where two neural networks compete with each other, comprising a Generator and a Discriminator. This article will explore a variant of GAN called CycleGAN and provide a detailed explanation of how to implement it using PyTorch.<\/p>\n<h2>1. Basic Concept of GAN<\/h2>\n<p>GAN is a model proposed by Ian Goodfellow in 2014 that operates by having two networks learn adversarially. The generator creates data, while the discriminator determines whether the data is real or fake. In this process, the generator progressively improves to produce data that can deceive the discriminator.<\/p>\n<h2>2. Introduction to CycleGAN<\/h2>\n<p>CycleGAN is a variant of GAN that learns image transformation between two domains. For example, it can perform tasks such as converting summer landscape images into winter landscape images. CycleGAN has a significant advantage in that it can learn mappings between two domains without paired training data.<\/p>\n<p>The main feature is its structure, which consists of two generators and two discriminators. In this structure, the generator transforms images from one domain to another, maintaining cycle consistency by transforming the generated image back to the original domain.<\/p>\n<h2>3. Basic Idea of CycleGAN<\/h2>\n<p>The basic idea of CycleGAN is as follows:<\/p>\n<ul>\n<li>Assume there are two domains, A and B, each containing images with different characteristics.<\/li>\n<li>Generator G transforms images from domain A to domain B.<\/li>\n<li>Generator F transforms images from domain B to domain A.<\/li>\n<li>To maintain cycle consistency, when an image from A is transformed to B and back to A, it should be similar to the original image. This principle is referred to as &#8220;Cycle Consistency Loss&#8221;.<\/li>\n<\/ul>\n<h2>4. Loss Function for CycleGAN<\/h2>\n<p>The loss function for CycleGAN is structured as follows:<\/p>\n<ul>\n<li>Main Loss\n<ul>\n<li>Adversarial Loss: A loss used to determine whether the generated image is real or fake.<\/li>\n<li>Cycle Consistency Loss: A loss used to verify if the transformed image can return to the original image.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Using the generators and discriminators for the two domains, the loss function is calculated. The final loss function is defined as a weighted sum of Adversarial Loss and Cycle Consistency Loss.<\/p>\n<h2>5. Implementing CycleGAN: PyTorch Example<\/h2>\n<p>Now, let&#8217;s implement CycleGAN using PyTorch. The project structure will be organized as follows:<\/p>\n<ul>\n<li>data\/\n<ul>\n<li>trainA\/ (Images from domain A)<\/li>\n<li>trainB\/ (Images from domain B)<\/li>\n<\/ul>\n<\/li>\n<li>models.py<\/li>\n<li>train.py<\/li>\n<li>utils.py<\/li>\n<\/ul>\n<h3>5.1 Data Loading<\/h3>\n<p>To train CycleGAN, we will first write the code to load the data. We will prepare the data using PyTorch&#8217;s Dataset and DataLoader.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the innovative advancements in artificial intelligence is the emergence of Generative Adversarial Networks (GANs). GAN consists of a structure where two neural networks compete with each other, comprising a Generator and a Discriminator. This article will explore a variant of GAN called CycleGAN and provide a detailed explanation of how to implement it &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36393\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Using PyTorch for GAN Deep Learning, First CycleGAN&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[113],"tags":[],"class_list":["post-36393","post","type-post","status-publish","format-standard","hentry","category-gan-deep-learning-course"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using PyTorch for GAN Deep Learning, First CycleGAN - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/36393\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using PyTorch for GAN Deep Learning, First CycleGAN - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"One of the innovative advancements in artificial intelligence is the emergence of Generative Adversarial Networks (GANs). GAN consists of a structure where two neural networks compete with each other, comprising a Generator and a Discriminator. This article will explore a variant of GAN called CycleGAN and provide a detailed explanation of how to implement it &hellip; \ub354 \ubcf4\uae30 &quot;Using PyTorch for GAN Deep Learning, First CycleGAN&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36393\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:48:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:00:06+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36393\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36393\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Using PyTorch for GAN Deep Learning, First CycleGAN\",\"datePublished\":\"2024-11-01T09:48:08+00:00\",\"dateModified\":\"2024-11-01T11:00:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36393\/\"},\"wordCount\":426,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"GAN deep learning course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36393\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36393\/\",\"name\":\"Using PyTorch for GAN Deep Learning, First CycleGAN - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:48:08+00:00\",\"dateModified\":\"2024-11-01T11:00:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36393\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36393\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36393\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using PyTorch for GAN Deep Learning, First CycleGAN\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using PyTorch for GAN Deep Learning, First CycleGAN - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/36393\/","og_locale":"ko_KR","og_type":"article","og_title":"Using PyTorch for GAN Deep Learning, First CycleGAN - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"One of the innovative advancements in artificial intelligence is the emergence of Generative Adversarial Networks (GANs). GAN consists of a structure where two neural networks compete with each other, comprising a Generator and a Discriminator. This article will explore a variant of GAN called CycleGAN and provide a detailed explanation of how to implement it &hellip; \ub354 \ubcf4\uae30 \"Using PyTorch for GAN Deep Learning, First CycleGAN\"","og_url":"https:\/\/atmokpo.com\/w\/36393\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:48:08+00:00","article_modified_time":"2024-11-01T11:00:06+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36393\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36393\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Using PyTorch for GAN Deep Learning, First CycleGAN","datePublished":"2024-11-01T09:48:08+00:00","dateModified":"2024-11-01T11:00:06+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36393\/"},"wordCount":426,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["GAN deep learning course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36393\/","url":"https:\/\/atmokpo.com\/w\/36393\/","name":"Using PyTorch for GAN Deep Learning, First CycleGAN - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:48:08+00:00","dateModified":"2024-11-01T11:00:06+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36393\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36393\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36393\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Using PyTorch for GAN Deep Learning, First CycleGAN"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=36393"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36393\/revisions"}],"predecessor-version":[{"id":36394,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36393\/revisions\/36394"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}