{"id":117,"date":"2022-07-21T19:24:16","date_gmt":"2022-07-21T18:24:16","guid":{"rendered":"https:\/\/wp.coventry.domains\/e2edu\/?page_id=117"},"modified":"2022-08-23T17:55:07","modified_gmt":"2022-08-23T16:55:07","slug":"generative-adversarial-network","status":"publish","type":"page","link":"https:\/\/wp.coventry.domains\/e2edu\/generative-adversarial-network\/","title":{"rendered":"Generative Adversarial Network"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Generative Adversarial Networks (GANs) have become famous also among a general people for their capability to generate photorealistic images, for instance of human faces. The following article introduces GANs that generate images. Nevertheless, many aspects described here also apply for GANs that generate different types of data. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"320\" src=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GANFaces.jpeg\" alt=\"\" class=\"wp-image-710\" srcset=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GANFaces.jpeg 640w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GANFaces-300x150.jpeg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption>Synthetic Images of Human Faces Generated by a GAN. \u00a9Tanaka and Aranha 2019<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Generator and Discriminator Model<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">GANs consist of two models, one named Generator and the other named Discriminator. The Generator takes as input a vector of random values and produces as output a synthetic image. The Discriminator takes as input an image and produces as output a label. The input image can either be produced by the Generator or be taken from a dataset of real images. The label indicates whether the Discriminator identifies the input image as fake (produced by the Generator) or as real (an image from the dataset). Both the Generator and the Discriminator are typically implemented as neural networks. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"374\" src=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Discriminator-1024x374.png\" alt=\"\" class=\"wp-image-717\" srcset=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Discriminator-1024x374.png 1024w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Discriminator-300x110.png 300w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Discriminator-768x281.png 768w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Discriminator-788x288.png 788w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Discriminator.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Data Processing by a Generator and Discriminator Model. \u00a9Pankaj Kishore<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Network Architecture<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For the application of image synthesis, the Generator and Discriminator networks are implemented as convolutional neural networks. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The arrangement of layers in a Discriminator is identically to that of a model used for image classification. The layers conduct a series of convolution operations to successively decrease the resolution and increase the number of channels of feature maps. The last feature map is then flattened into a one-dimensional vector. This vector is then processed by layers of a conventional artificial neuronal network before a class label is finally predicted. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"396\" src=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Discriminator_Convolutions-1024x396.jpeg\" alt=\"\" class=\"wp-image-758\" srcset=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Discriminator_Convolutions-1024x396.jpeg 1024w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Discriminator_Convolutions-300x116.jpeg 300w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Discriminator_Convolutions-768x297.jpeg 768w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Discriminator_Convolutions-1536x593.jpeg 1536w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Discriminator_Convolutions-788x304.jpeg 788w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Discriminator_Convolutions.jpeg 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Neural Network Layers in a Discriminator. Data is processed from left to right.  \u00a9Donna Corriveau<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">The arrangement of layers in a Generator more or less mirrors that of a Discriminator. Here, the first part consists of a conventional neural network. The second part consists of a convolutional neural network  whose layers conduct a series of deconvolution operations to successively increase the resolution and decrease the number of channels of feature maps until they match those of the images in the dataset. For data to pass from the conventional neural network into the convolutional neural network, it needs to be un-flattened. Un-flattening is the opposite operation to flattening, i.e. a one-dimensional vector is converted into a two-dimensional feature map. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"433\" src=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Deconvolution-1024x433.png\" alt=\"\" class=\"wp-image-757\" srcset=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Deconvolution-1024x433.png 1024w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Deconvolution-300x127.png 300w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Deconvolution-768x325.png 768w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Deconvolution-1536x650.png 1536w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Deconvolution-788x333.png 788w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Generator_Deconvolution.png 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Neural Network Layers in a Generator. Data is processed from left to right.  \u00a9Donna Corriveau<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Deconvolution<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Deconvolution represents the opposite of convolution. In convolution, a dot product is calculated between a kernel and an region of a feature map with the result a single scalar value. In deconvolution, a kernel is employed to convert a single scalar value into a region of a feature map. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"395\" height=\"449\" src=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/Deconvolution.gif\" alt=\"\" class=\"wp-image-769\" \/><figcaption>Deconvolution Operation. \u00a9Codicals<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Similarly inverted versions also exist for other types of layers that are typically used in convolutional neural networks such as pooling layers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Competition<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">During training, these two models compete with each other. The Generator tries to fool the Discriminator into &#8220;believing&#8221; that the generated synthetic images represent real images. In order to succeed in this, the Generator has to learn the statistical distribution of images so that it becomes better at generating synthetic images that are indistinguishable for the Discriminator from real images. The Discriminator on the other hand tries to identify the images generated by the Generator as fake and those from the dataset as real. In order to succeed in this, the Discriminator has to learn a classification task. This situation resembles a typical case used in <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Game_theory\" target=\"_blank\">Game Theory<\/a>, in that the Discriminator and Generator can be understood as rational agents that compete with each other, each trying to come up with a strategy to beat the other agent. By adjusting their respective strategies the agents eventually reach a <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Nash_equilibrium\" target=\"_blank\">Nash Equilibrium<\/a>. At this point, the agents consider their strategies optimal and no longer change them. In the case of a GAN, a Nash Equilibrium is reached, when the Generator always succeeds in fooling the Discriminator no matter how good the Discriminator has become in distinguishing between real and fake images.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Training<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">During training, the Discriminator and Generator take turns in updating their trainable parameters.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When training the Discriminator, the trainable parameters of the Generator are fixed. The Discriminator is provided with images that are either real or synthetic alongside the corresponding labels. During training, the Discriminator tries to minimise the error that it makes in predicting these labels. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"585\" src=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Discriminator-1024x585.png\" alt=\"\" class=\"wp-image-729\" srcset=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Discriminator-1024x585.png 1024w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Discriminator-300x171.png 300w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Discriminator-768x439.png 768w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Discriminator-788x450.png 788w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Discriminator.png 1090w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Training Step for the Discriminator. \u00a9Pankaj Kishore<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">When training the Generator, the trainable parameters of the Discriminator are fixed. The Generator is provided with vectors containing random values. It generates synthetic images from these vectors and passes these images as input to the Discriminator which in turn labels them as either real or fake. During training, the Generator tries to maximise the error that the Discriminator makes in predicting these labels. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"556\" src=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Generator-1024x556.png\" alt=\"\" class=\"wp-image-730\" srcset=\"https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Generator-1024x556.png 1024w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Generator-300x163.png 300w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Generator-768x417.png 768w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Generator-788x427.png 788w, https:\/\/wp.coventry.domains\/e2edu\/wp-content\/uploads\/sites\/3486\/2022\/08\/GAN_Training_Generator.png 1141w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Training Step for the Generator. \u00a9Pankaj Kishore<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Latent Vector<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The vector containing random numbers that is provided as input to the Generator for generating synthetic images plays an important role. This vector plays represents an encoding for a synthetic image. An encoding can also be thought of as a latent code for a synthetic image. Latent codes represent the most interesting aspect of GANs, since conventional vector arithmetic can be conducted on them to create new synthetic images. This topic will be further elaborated in the article on <a href=\"https:\/\/wp.coventry.domains\/e2edu\/autoencoder\/\" target=\"_blank\" rel=\"noreferrer noopener\">Autoencoders<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Generative Adversarial Networks (GANs) have become famous also among a general people for their capability to generate photorealistic images, for instance of human faces. The following article introduces GANs that generate images. Nevertheless, many aspects described here also apply for GANs that generate different types of data. Generator and Discriminator Model GANs consist of two [&hellip;]<\/p>\n","protected":false},"author":2154,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"class_list":["post-117","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/pages\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/users\/2154"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":48,"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/pages\/117\/revisions"}],"predecessor-version":[{"id":3035,"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/pages\/117\/revisions\/3035"}],"wp:attachment":[{"href":"https:\/\/wp.coventry.domains\/e2edu\/wp-json\/wp\/v2\/media?parent=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}