{"id":24523594,"url":"https://github.com/anshchoudhary/gan-implementation","last_synced_at":"2026-04-25T11:35:59.201Z","repository":{"id":271892959,"uuid":"914901577","full_name":"AnshChoudhary/GAN-Implementation","owner":"AnshChoudhary","description":"This repository was created as a comprehensive guide to GAN architectures and their implementations.","archived":false,"fork":false,"pushed_at":"2025-01-20T07:21:03.000Z","size":2716,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T14:12:36.589Z","etag":null,"topics":["dcgan-pytorch","gan","generative-adversarial-network","mnist","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnshChoudhary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-10T14:44:00.000Z","updated_at":"2025-01-20T07:21:05.000Z","dependencies_parsed_at":"2025-01-10T15:44:21.199Z","dependency_job_id":"7440e607-cd2b-4fed-b55f-301064683c9e","html_url":"https://github.com/AnshChoudhary/GAN-Implementation","commit_stats":null,"previous_names":["anshchoudhary/gan-implementation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshChoudhary%2FGAN-Implementation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshChoudhary%2FGAN-Implementation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshChoudhary%2FGAN-Implementation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnshChoudhary%2FGAN-Implementation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnshChoudhary","download_url":"https://codeload.github.com/AnshChoudhary/GAN-Implementation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243738980,"owners_count":20340002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dcgan-pytorch","gan","generative-adversarial-network","mnist","pytorch"],"created_at":"2025-01-22T04:15:57.160Z","updated_at":"2026-04-25T11:35:54.146Z","avatar_url":"https://github.com/AnshChoudhary.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Generative Adversarial Networks (GANs) Implementation\n\n## Overview\n\nGenerative Adversarial Networks (GANs) are a class of machine learning frameworks designed to generate synthetic data that mimics real data. Introduced by Ian Goodfellow et al. in 2014, GANs consist of two neural networks:\n\n1. **Generator (G):** The generator creates synthetic data samples.\n2. **Discriminator (D):** The discriminator evaluates whether the samples are real or generated.\n\nThe two networks compete in a zero-sum game:\n- The generator tries to fool the discriminator into classifying its outputs as real.\n- The discriminator learns to distinguish real samples from fake ones.\n\nThis adversarial process helps the generator improve over time, creating highly realistic data.\n\n---\n\n## Repository Structure\nThis repository contains implementations of three types of GAN architectures:\n\n1. **Vanilla GAN**\n2. **Deep Convolutional GAN (DCGAN)**\n3. **Conditional GAN (CGAN)**\n4. **Wasserstain GAN (WGAN)**\n5. **Wasserstein GAN with Gradient Penalty (WGAN-GP)**\n6. **Information Maximizing GAN (InfoGAN)**\n\nEach implementation is provided in a separate Jupyter Notebook:\n\n- **VanillaGAN.ipynb:** Basic implementation of a GAN.  \n- **DCGAN.ipynb:** Implementation of a convolutional GAN for generating high-quality images.  \n- **Conditional-GAN.ipynb:** GAN conditioned on labels for controlled data generation.  \n- **W-GAN.ipynb:** Implementation of Wasserstein GAN.  \n- **WGAN-GP.ipynb:** Wasserstein GAN with Gradient Penalty for improved training stability.  \n- **InfoGAN.ipynb:** Information Maximizing GAN for interpretable and disentangled representations.\n\n\n---\n\n## What are GANs?\nGANs are built upon the idea of training two networks in opposition. The generator's objective is to create data that resembles the training data, while the discriminator's goal is to identify fake samples. The adversarial training dynamic pushes both networks to improve until the generator produces data indistinguishable from real samples.\n\n**Mathematical Objective:**  \nThe GAN framework is optimized using the following minimax game:\n\n\\[\n\\min_G \\max_D \\mathbb{E}_{x \\sim p_{\\text{data}}(x)}[\\log D(x)] + \\mathbb{E}_{z \\sim p_z(z)}[\\log(1 - D(G(z)))]\n\\]\n\nWhere:  \n- \\( x \\): Real data sample  \n- \\( z \\): Random noise sampled from a prior distribution  \n- \\( G(z) \\): Generated data sample  \n- \\( D(x) \\): Probability that \\( x \\) is real  \n\n---\n\n## Types of GAN Architectures\n\n### 1. **Vanilla GAN**\nThe basic GAN architecture consists of fully connected layers in both the generator and discriminator. \n\n**Key Features:**\n- Suitable for low-dimensional data.\n- Can suffer from issues like mode collapse, where the generator produces limited diversity in outputs.\n\n[View Implementation](./VanillaGAN.ipynb)\n\n---\n\n### 2. **Deep Convolutional GAN (DCGAN)**\nDCGANs introduce convolutional layers into GANs, enabling them to handle high-dimensional data such as images.\n\n**Key Features:**\n- Use of convolutional layers in both the generator and discriminator.\n- Batch normalization to stabilize training.\n- ReLU activation in the generator and Leaky ReLU in the discriminator.\n- Produces higher quality images compared to Vanilla GAN.\n\n[View Implementation](./DCGAN.ipynb)\n\n---\n\n### 3. **Conditional GAN (CGAN)**\nCGANs extend the GAN framework by conditioning the generation process on auxiliary information (e.g., class labels).\n\n**Key Features:**\n- Generator and discriminator receive both noise and class labels as inputs.\n- Enables controlled generation of samples corresponding to specific labels.\n- Widely used for tasks like image-to-image translation and text-to-image synthesis.\n\n[View Implementation](./Conditional-GAN.ipynb)\n\n---\n\n### 4. **Wasserstein GAN (WGAN)**  \nWasserstein GANs improve upon the original GAN framework by addressing issues like mode collapse and training instability using the Wasserstein distance as a new loss function.\n\n**Key Features:**  \n- Replaces the standard GAN loss with the Wasserstein loss, which provides a more meaningful measure of the distance between the real and generated data distributions.  \n- Does not require the discriminator to output probabilities; instead, it outputs a critic score.  \n- Uses weight clipping or gradient penalty (in WGAN-GP) to enforce the Lipschitz constraint.  \n- Improves training stability and makes convergence easier to interpret.\n\n[View Implementation](./W-GAN.ipynb)\n\n---\n\n### 5. **Wasserstein GAN with Gradient Penalty (WGAN-GP)**  \nWGAN-GP enhances the Wasserstein GAN framework by addressing the limitations of weight clipping through the introduction of a gradient penalty.\n\n**Key Features:**  \n- Enforces the Lipschitz constraint using a gradient penalty rather than weight clipping, improving model performance and stability.  \n- Provides smoother convergence and alleviates issues with capacity underutilization in the discriminator.  \n- Widely used in high-resolution image generation tasks and applications requiring stable GAN training.\n\n[View Implementation](./WGAN-GP.ipynb)\n\n---\n\n### 6. **Information Maximizing GAN (InfoGAN)**  \nInfoGAN extends the GAN framework by maximizing the mutual information between a subset of latent variables and the generated data, enabling interpretable and disentangled representations.\n\n**Key Features:**  \n- Introduces latent variables with a meaningful structure (e.g., categorical or continuous) to control specific features of the generated data.  \n- Encourages disentanglement of representations, allowing controlled generation based on interpretable factors.  \n- Useful for tasks like style transfer, data clustering, and feature learning.\n\n[View Implementation](./InfoGAN.ipynb)\n\n\n---\n\n### Vanilla GAN\n\u003cimg src=\"/images/Vanilla-GAN.gif\" width=\"200\" height=\"200\" /\u003e\n\n### Conditional GAN\n\u003cimg src=\"/images/Conditional-GAN.gif\" width=\"200\" height=\"200\" /\u003e\n\n### DC GAN\n\u003cimg src=\"/images/Conditional-DCGAN.gif\" width=\"200\" height=\"200\" /\u003e\n\n### WGAN-gp\n\u003cimg src=\"/images/WGAN-gp.gif\" width=\"200\" height=\"200\" /\u003e\n\n### infoGAN w/ walking code 1\n\u003cimg src=\"/images/infoGAN_type1.jpg\" width=\"200\" height=\"200\" /\u003e\n\n### infoGAN w/ walking code 2\n\u003cimg src=\"/images/infoGAN_type2.jpg\" width=\"200\" height=\"200\" /\u003e\n\n---\n\n## Requirements\nTo run the notebooks, you will need the following Python packages:\n\n- `torch`\n- `torchvision`\n- `numpy`\n- `matplotlib`\n\nInstall the dependencies using:\n```bash\npip install torch torchvision numpy matplotlib\n```\n\n## Usage\n\n1. Clone the repository:\n\n```bash\ngit clone https://github.com/AnshChoudhary/GAN-Implementation.git\n```\n\n2. Navigate to the repository:\n\n```bash\ncd GAN-Implementation\n```\n\n3. Open the desired notebook in Jupyter Notebook or JupyterLab:\n\n```bash\njupyter notebook VanillaGAN.ipynb\n```\n\n## Applications of GANs\n- **Image generation:** Generating realistic faces, artworks, and other synthetic images.\n- **Image-to-image translation:** Tasks like style transfer, super-resolution, and domain adaptation.\n- **Data augmentation:** Enhancing datasets for machine learning models.\n- **Video generation and prediction:** Synthesizing realistic video sequences or predicting future frames.\n- **Anomaly detection:** Detecting fraud or other outliers by modeling normal data distributions.\n\n---\n\n## References\n1. Goodfellow, I., et al. (2014). Generative Adversarial Networks. [arXiv:1406.2661](https://arxiv.org/abs/1406.2661)\n2. Radford, A., et al. (2015). Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks. [arXiv:1511.06434](https://arxiv.org/abs/1511.06434)\n3. Mirza, M., \u0026 Osindero, S. (2014). Conditional Generative Adversarial Nets. [arXiv:1411.1784](https://arxiv.org/abs/1411.1784)\n4. Arjovsky, M., Chintala, S., \u0026 Bottou, L. (2017). Wasserstein GAN. [arXiv:1701.07875](https://arxiv.org/pdf/1701.07875)\n\n---\n\n## Acknowledgments\nThis repository was created as a comprehensive guide to GAN architectures and their implementations. Contributions and suggestions are welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshchoudhary%2Fgan-implementation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanshchoudhary%2Fgan-implementation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshchoudhary%2Fgan-implementation/lists"}