Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/letsdoitbycode/gan-model-implementation

This project implements a Deep Convolutional GAN (DCGAN) to generate handwritten digit images similar to those in the MNIST dataset. The project includes the model design, training script, and utilities for managing data and generating images, all set up to run in a self-contained environment.
https://github.com/letsdoitbycode/gan-model-implementation

dcgan deep-learning gan-models mnist-dataset python

Last synced: about 2 months ago
JSON representation

This project implements a Deep Convolutional GAN (DCGAN) to generate handwritten digit images similar to those in the MNIST dataset. The project includes the model design, training script, and utilities for managing data and generating images, all set up to run in a self-contained environment.

Awesome Lists containing this project

README

        

# # GAN MNIST dataset Implementation

This project implements a Deep Convolutional GAN (DCGAN) to generate handwritten digit images similar to those in the MNIST dataset. The project includes the model design, training script, and utilities for managing data and generating images, all set up to run in a self-contained environment.

### Model Overview
This project uses a DCGAN, a type of GAN (Generative Adversarial Network), where:
- The Generator learns to generate new digit images by taking random noise as input.
- The Discriminator learns to distinguish between real MNIST images and fake images generated by the Generator.
- The two models are trained together in an adversarial process, where the Generator improves at producing realistic images, and the Discriminator improves at detecting fakes.

### Installation
1. Clone the repository
```sh
git clone https://github.com/letsdoitbycode/GAN-model-implementation.git
cd GAN-model-implementation
```

3. Create a virtual environment and activate it:
```sh
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
```

3. Install the required packages:
```sh
pip install torch torchvision numpy Pillow
pip install requirements.txt #else you can do this directly
```

4. Run the Training Script:
- The training script will download the MNIST dataset (if not already present) and begin training the GAN.
```sh
python train.py
```

### Project Structure
```plaintext
GAN-model-implementation/
├── data/ # Directory for downloaded MNIST dataset
├── generated_images/ # Directory to save generated images during training
├── models/
│ ├── generator.py # Generator model code
│ └── discriminator.py # Discriminator model code
├── train.py # Script to train the GAN
├── utils.py # Utility functions (e.g., image saving, initialization)
├── requirements.txt # Python dependencies
└── README.md # Project description and setup instructions

```

### Code Structure
```plaintext models/generator.py``` Defines the architecture of the Generator network, which creates fake MNIST images from random noise.
```plaintext models/discriminator.py``` Defines the architecture of the Discriminator network, which evaluates if images are real or fake.
```plaintexttrain.py``` Script for training the GAN. It sets up the data, trains the Generator and Discriminator, and saves generated images at intervals.
```plaintext utils.py``` Contains utility functions, such as save_generated_images to save generated images during training, and initialize_weights to initialize model weights.
```plaintext requirements.txt``` Lists the Python dependencies required for this project.
```plaintext README.md``` Provides an overview, setup instructions, and details on the project structure.

### Results
Generated images are saved in the ```plaintext generated_images/``` directory. As training progresses, you can observe the images evolving to resemble handwritten digits more closely.

### Sample Generated Images
You may want to include a few sample images here from ```plaintext generated_images/``` after running the project.

### Additional Notes
- Training Duration: Depending on your hardware, training might take some time. The script is set to run for 50 epochs, but you may experiment with different settings.
- Noise Dimension: The input noise dimension for the Generator is set to 100. You can experiment with this to see how it impacts the quality of generated images.

## Contributing
Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements.