目录
目录README.md

CGAN_jittor

A solution for the contest

Understanding Generative Adversarial Networks (GANs)

At its core, a Generative Adversarial Network (GAN) is a powerful framework for training generative models. Introduced by Ian Goodfellow and colleagues in 2014, a GAN consists of two neural networks that are trained simultaneously in a competitive, zero-sum game:

  1. The Generator (G): This network’s goal is to learn the data distribution of the training set and generate new data samples that are indistinguishable from the real data. It takes a random noise vector (often from a latent space) as input and transforms it into a data sample (e.g., an image).

  2. The Discriminator (D): This network acts as a binary classifier. It is trained to distinguish between real data samples from the training set and fake data samples generated by the Generator. It takes a data sample as input and outputs a probability estimating whether the sample is real or fake.

The training process is adversarial:

  • The Generator tries to fool the Discriminator by generating increasingly realistic fake data.
  • The Discriminator tries to become better at identifying fake data generated by the Generator.

This dynamic creates a feedback loop where both networks improve over time. Ideally, the training converges when the Generator produces data so realistic that the Discriminator cannot differentiate between real and fake samples, essentially guessing with 50% probability.

Mathematically, the GAN training can be represented as a minimax game with the following objective function:

minGmaxDV(D,G)=Expdata(x)[logD(x)]+Ezpz(z)[log(1D(G(z)))]\min_G \max_D V(D, G) = \mathbb{E}_{x \sim p_{data}(x)}[\log D(x)] + \mathbb{E}_{z \sim p_z(z)}[\log(1 - D(G(z)))]

Where:

  • D(x)D(x) is the Discriminator’s output for a real data sample $x$.
  • G(z)G(z) is the Generator’s output for a noise vector $z$.
  • pdata(x)p_{data}(x) is the true data distribution.
  • pz(z)p_z(z) is the distribution of the noise vector.

The Discriminator aims to maximize $V(D, G)$ (correctly classifying real and fake), while the Generator aims to minimize $V(D, G)$ (fooling the Discriminator).

Conditional Generative Adversarial Network (CGAN) with Jittor

Jittor

This repository contains a Jittor implementation of a Conditional Generative Adversarial Network (CGAN). CGANs extend the basic GAN framework by conditioning the model on additional information (like class labels), allowing for more control over the generated output.

This implementation demonstrates how to build and train a CGAN using the Jittor deep learning framework, likely targeting a dataset like MNIST for generating specific digits based on provided labels.

Repository Link: https://www.gitlink.org.cn/YzI3MzI5Yzcy/CGAN_jittor

Requirements

  • Python 3.7+
  • Jittor: Ensure you have Jittor installed.
    python -m pip install jittor
  • NumPy:
    python -m pip install numpy
  • (Optional) Matplotlib or Pillow (for saving/viewing generated images):
    python -m pip install matplotlib Pillow
  • (Optional) tqdm (for progress bars)
    python -m pip install tqdm

Installation

  1. Clone the repository:
    git clone [https://www.gitlink.org.cn/YzI3MzI5Yzcy/CGAN_jittor.git](https://www.gitlink.org.cn/YzI3MzI5Yzcy/CGAN_jittor.git)
    cd CGAN_jittor
  2. Install the required packages (if not already installed):
    # Install Jittor following official instructions if the pip command above fails
    # [https://cg.cs.tsinghua.edu.cn/jittor/download/](https://cg.cs.tsinghua.edu.cn/jittor/download/)
    python -m pip install numpy matplotlib Pillow tqdm

Dataset

This implementation likely uses the MNIST dataset.

  • Automatic Download: Jittor’s dataset utilities might handle the download and preparation automatically when you run the training script for the first time. Check the code (dataset.py or train.py) for details.
  • Manual Download: If required, you can download the MNIST dataset from Yann LeCun’s website and place the files (e.g., train-images-idx3-ubyte.gz, train-labels-idx1-ubyte.gz, etc.) in a designated data/mnist directory. Update the script paths if necessary.
关于

A Jittor implementation of Conditional GAN (CGAN)

10.8 MB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号