<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mujtaba Hussain on Medium]]></title>
        <description><![CDATA[Stories by Mujtaba Hussain on Medium]]></description>
        <link>https://medium.com/@mujtabahussain_95364?source=rss-8c4a4f000472------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yYtm0cEoEX45zfVd</url>
            <title>Stories by Mujtaba Hussain on Medium</title>
            <link>https://medium.com/@mujtabahussain_95364?source=rss-8c4a4f000472------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 21:29:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mujtabahussain_95364/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Everything you ever wanted to know about Generative Adversarial Networks (GANs)]]></title>
            <link>https://medium.com/@mujtabahussain_95364/everything-you-ever-wanted-to-know-about-generative-adversarial-networks-gans-c900cdee62b1?source=rss-8c4a4f000472------2</link>
            <guid isPermaLink="false">https://medium.com/p/c900cdee62b1</guid>
            <dc:creator><![CDATA[Mujtaba Hussain]]></dc:creator>
            <pubDate>Mon, 28 Mar 2022 18:13:48 GMT</pubDate>
            <atom:updated>2022-04-03T01:28:55.486Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Everything you ever wanted to know about Generative Adversarial Networks (GANs)</strong></p><blockquote>“The most interesting idea in the last ten years in ML”</blockquote><blockquote>- Yann LeCun, Facebook AI Research Director</blockquote><p>Generative Adversarial Networks were designed by Ian Goodfellow and his colleagues in June 2014.</p><p>Generative Adversarial Networks (GANs) are powerful machine learning models which act as frameworks for estimating generative models. This method uses two models which are trained simultaneously : i. a generative model that captures the data distribution, ii. a discriminative model which estimates the probability that a sample came from training data rather than from the generative model.</p><p>Statistically, GANs are represented with the below formula :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*RNO6BKiDn51nG3JRg60pfQ.png" /><figcaption>GANs Loss Function</figcaption></figure><p>where:</p><p>G = generator</p><p>D = discriminator</p><p>Pdata (x) = distribution of real data</p><p>P(z) = distribution of generator</p><p>x = sample from Pdata (x)</p><p>z = sample from Zdata(x)</p><p>D(x) = discriminator network</p><p>G(z) = generator network</p><p>The two models are set up against each other with opposite goals :</p><p>i. Generator model is trained to maximize the final classification error (between true and generated data)</p><p>ii. Discriminator model is trained to minimize the final classification error</p><p>The generative model’s objective is to increase the error rate of the discriminative network. The generator trains based on whether it succeeds in fooling the discriminator.</p><p>Whereas, the discriminative model’s objective is to identify which outputs are synthetic from the outputs it receives from the generator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*6EZQWeZzebmr2_kwhGDTLw.png" /></figure><p><strong><em>Applications of GANs :</em></strong></p><p>GANs have some very interesting uses, some of which have been mentioned below:</p><p>a. Generate examples for image datasets</p><p>b. Generate photographs of human faces</p><p>c. Generate realistic photographs</p><p>d. Generate cartoon characters</p><p>e. Filling images from an outline</p><p>Other miscellaneous applications include:</p><p>a. Fashion, art and advertising</p><p>b. Science</p><p>c. Video games</p><p>d. GANs can also be used to detect glaucomatous images, photorealistic images, 3d models of objects from images, data augmentation, inpaint missing features in maps, etc.</p><p><strong><em>Some impressive GAN Libraries :</em></strong></p><p>a. TF-GAN — This is a lightweight library for training and evaluating GANs. It can be installed with pip using pip install tensorflow-gan, and used with import tensorflow_gan as tfgan.</p><p>b. Torch-GAN — This is a PyTorch based framework for designing and developing GANs. This framework has been designed to provide building blocks for popular GANs and also to allow customization for cutting edge research.</p><p>c. Mimicry — This is a lightweight PyTorch library aimed towards the reproducibility of GAN research.</p><p>d. IBM GAN Toolkit — The aim of this toolkit is to provide a highly flexible, no-code way of implementing GANs. By providing the details of a GAN model, in an intuitive config file or as command line arguments, the code could be generated for training the GAN model.</p><p>e. Keras-GAN — This includes a collection of Keras implementations of GANs suggested in research papers.</p><p>f. PyTorch-GAN — PyTorch is a leading open source deep learning framework. While PyTorch does not provide a built-in implementation of a GAN network, it provides primitives that allows you to build GAN networks, including fully connected neural network layers, convolutional layers, and training functions.</p><p>g. Py-GAN — This is a Python library which is useful in designing Generative models based on statistical machine learning problems for different types of GANs.</p><p><strong><em>Different types of GANs:</em></strong></p><p>a. Vanilla GANs — Vanilla GANs has two networks called generator network and a discriminator network. Both the networks are trained at the same time and compete or battle against each other in a minimax play.</p><p>b. Conditional GAN (CGAN) — Conditional GAN is a GAN variant in which both the generator and the discriminator are conditioned on auxiliary data such as a class label during training.</p><p>c. Deep Convolutional GAN (DCGAN) — DCGAN is one of the popular and a successful network design for GAN. It mainly composes of convolution layers without max pooling or fully connected layers. It uses convolutional stride and transposed convolution for downsampling and upsampling.</p><p>d. Laplacian Pyramid GAN (LAPGAN) — LAPGAN combines the CGAN model with a Laplacian pyramid representation.</p><p>e. Super Resolution GAN (SRGAN) — SRGAN applies a deep network in combination with an adversary network to produce high resolution images.</p><p><strong><em>Sample Python code for GAN using MNIST dataset:</em></strong></p><p># importing the necessary libraries and the MNIST dataset<br>import tensorflow as tf<br>import numpy as np<br>import matplotlib.pyplot as plt<br>from tensorflow.examples.tutorials.mnist import input_data</p><p>mnist = input_data.read_data_sets(“MNIST_data”)</p><p># defining functions for the two networks.<br># Both the networks have two hidden layers<br># and an output layer which are densely or<br># fully connected layers defining the<br># Generator network function<br>def generator(z, reuse = None):<br> with tf.variable_scope(‘gen’, reuse = reuse):<br> hidden1 = tf.layers.dense(inputs = z, units = 128,<br> activation = tf.nn.leaky_relu)<br> <br> hidden2 = tf.layers.dense(inputs = hidden1,<br> units = 128, activation = tf.nn.leaky_relu)<br> <br> output = tf.layers.dense(inputs = hidden2,<br> units = 784, activation = tf.nn.tanh)<br> <br> return output</p><p># defining the Discriminator network function<br>def discriminator(X, reuse = None):<br> with tf.variable_scope(‘dis’, reuse = reuse):<br> hidden1 = tf.layers.dense(inputs = X, units = 128,<br> activation = tf.nn.leaky_relu)<br> <br> hidden2 = tf.layers.dense(inputs = hidden1,<br> units = 128, activation = tf.nn.leaky_relu)<br> <br> logits = tf.layers.dense(hidden2, units = 1)<br> output = tf.sigmoid(logits)<br> <br> return output, logits</p><p># creating placeholders for the outputs<br>tf.reset_default_graph()</p><p>real_images = tf.placeholder(tf.float32, shape =[None, 784])<br>z = tf.placeholder(tf.float32, shape =[None, 100])</p><p>G = generator(z)<br>D_output_real, D_logits_real = discriminator(real_images)<br>D_output_fake, D_logits_fake = discriminator(G, reuse = True)</p><p># defining the loss function<br>def loss_func(logits_in, labels_in):<br> return tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(<br> logits = logits_in, labels = labels_in))</p><p># Smoothing for generalization<br>D_real_loss = loss_func(D_logits_real, tf.ones_like(D_logits_real)*0.9)<br>D_fake_loss = loss_func(D_logits_fake, tf.zeros_like(D_logits_real))<br>D_loss = D_real_loss + D_fake_loss</p><p>G_loss = loss_func(D_logits_fake, tf.ones_like(D_logits_fake))</p><p># defining the learning rate, batch size,<br># number of epochs and using the Adam optimizer<br>lr = 0.001 # learning rate</p><p># Do this when multiple networks<br># interact with each other</p><p># returns all variables created(the two<br># variable scopes) and makes trainable true<br>tvars = tf.trainable_variables()<br>d_vars =[var for var in tvars if ‘dis’ in var.name]<br>g_vars =[var for var in tvars if ‘gen’ in var.name]</p><p>D_trainer = tf.train.AdamOptimizer(lr).minimize(D_loss, var_list = d_vars)<br>G_trainer = tf.train.AdamOptimizer(lr).minimize(G_loss, var_list = g_vars)</p><p>batch_size = 100 # batch size<br>epochs = 500 # number of epochs. The higher the better the result<br>init = tf.global_variables_initializer()</p><p># creating a session to train the networks<br>samples =[] # generator examples</p><p>with tf.Session() as sess:<br> sess.run(init)<br> for epoch in range(epochs):<br> num_batches = mnist.train.num_examples//batch_size<br> <br> for i in range(num_batches):<br> batch = mnist.train.next_batch(batch_size)<br> batch_images = batch[0].reshape((batch_size, 784))<br> batch_images = batch_images * 2–1<br> batch_z = np.random.uniform(-1, 1, size =(batch_size, 100))<br> _= sess.run(D_trainer, feed_dict ={real_images:batch_images, z:batch_z})<br> _= sess.run(G_trainer, feed_dict ={z:batch_z})<br> <br> print(“on epoch{}”.format(epoch))<br> <br> sample_z = np.random.uniform(-1, 1, size =(1, 100))<br> gen_sample = sess.run(generator(z, reuse = True),<br> feed_dict ={z:sample_z})<br> <br> samples.append(gen_sample)</p><p># result after 0th epoch<br>plt.imshow(samples[0].reshape(28, 28))</p><p># result after 499th epoch<br>plt.imshow(samples[49].reshape(28, 28))</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*v36Wp6OGN0D8RAoN3bfhqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*z9IyJ4UDSbZWT_yDUETyXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*z949hPdf777gNFxVemdVJA.png" /></figure><p>In conclusion, I would like to say that GANs are still being researched and continues to be an exciting topic for machine learning enthusiasts to explore! In this blog, I have discussed interesting details about GANs. Please use the following link : <a href="https://www.ml-concepts.com/machine-learning-models/"><strong><em>https://www.ml-concepts.com/machine-learning-models/</em></strong></a> for more interesting articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c900cdee62b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>