Conditional GAN for MNIST Digit Generation using Jittor
This repository contains code for training a Conditional Generative Adversarial Network (CGAN) on the MNIST dataset using the Jittor deep learning framework. The CGAN is capable of generating digit images based on input random noise and specified digit labels.
Prerequisites
To run this project, you need to have Python 3.7+ installed.
Installation
Clone this repository:
git clone https://gitlink.org.cn/zhengxl/CGAN_Jittor.git
cd cgan-jittor-mnist
–n_epochs: Number of epochs for training (default: 100)
–batch_size: Size of the batches (default: 64)
–lr: Learning rate for the Adam optimizer (default: 0.0002)
–b1: Adam: decay of first order momentum of gradient (default: 0.5)
–b2: Adam: decay of first order momentum of gradient (default: 0.999)
–n_cpu: Number of CPU threads to use during batch generation (default: 8)
–latent_dim: Dimensionality of the latent space (default: 100)
–n_classes: Number of classes for the dataset (default: 10)
–img_size: Size of each image dimension (default: 32)
–channels: Number of image channels (default: 1)
–sample_interval: Interval between image sampling (default: 1000)
Generating Images
After training, you can generate images using a specified sequence of digits. Modify the number variable in the script to the desired sequence.
number = "20689882064078" # Modify this to your desired sequence
Run the script to generate images and save them as result.png:
Sample Output
The generated images will be saved in the working directory. Images are saved at intervals specified by –sample_interval during training. After training, images corresponding to the specified digit sequence will be saved as result.png.
Directory Structure
cgan-jittor-mnist/
│
├── CGAN.py # Script for training the CGAN and generating image
├── README.md # This README file
├── generator_last.pkl # Saved generator model (after training)
└── discriminator_last.pkl # Saved discriminator model (after training)
Model Description
Generator
The generator model maps the input random noise and digit labels to digit images. It consists of several fully connected layers with Batch Normalization and Leaky ReLU activations, ending with a Tanh activation to generate images.
Discriminator
The discriminator model distinguishes between real and generated images. It consists of fully connected layers with Leaky ReLU activations and Dropout for regularization, ending with a single output neuron for classification.
关于
A Jittor implementation of Conditional GAN (CGAN).
Conditional GAN for MNIST Digit Generation using Jittor
This repository contains code for training a Conditional Generative Adversarial Network (CGAN) on the MNIST dataset using the Jittor deep learning framework. The CGAN is capable of generating digit images based on input random noise and specified digit labels.
Prerequisites
To run this project, you need to have Python 3.7+ installed.
Installation
Clone this repository:
Then install Jittor by following the instructions at the Jittor installation page.
Usage
Training the CGAN
To train the Conditional GAN, you can run the provided script with default settings or modify the arguments as needed.
Arguments
Generating Images
After training, you can generate images using a specified sequence of digits. Modify the number variable in the script to the desired sequence.
Run the script to generate images and save them as result.png:
Sample Output
The generated images will be saved in the working directory. Images are saved at intervals specified by –sample_interval during training. After training, images corresponding to the specified digit sequence will be saved as result.png.
Directory Structure
Model Description
Generator
The generator model maps the input random noise and digit labels to digit images. It consists of several fully connected layers with Batch Normalization and Leaky ReLU activations, ending with a Tanh activation to generate images.
Discriminator
The discriminator model distinguishes between real and generated images. It consists of fully connected layers with Leaky ReLU activations and Dropout for regularization, ending with a single output neuron for classification.