Skip to content

ErfanShakouri/Generative

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

DCGAN Implementation for Image Generation

This repository contains a PyTorch implementation of a Deep Convolutional Generative Adversarial Network (DCGAN) for generating realistic images using the CelebA dataset (Its model is taken from Paper1. The GAN consists of a Generator and a Discriminator, which are trained in an adversarial manner to produce high-quality images.


Table of Contents

  1. Overview
  2. Requirements
  3. Dataset
  4. Code Structure
  5. Training the Model
  6. Results

Overview

This project implements a DCGAN using PyTorch. The DCGAN is trained on the CelebA dataset to generate realistic face images. The Generator learns to create images from random noise, while the Discriminator learns to distinguish between real and fake images. The two networks are trained simultaneously in a competitive manner.


Requirements

To run this code, you need the following dependencies:

  • Python 3.x
  • PyTorch
  • Torchvision
  • Matplotlib
  • NumPy
  • Jupyter Notebook (optional, for visualization)

Dataset

The model is trained on the CelebA dataset, which contains over 200,000 celebrity images. The dataset is provided as a zip file (img_align_celeba.zip). The code automatically extracts the dataset and applies the necessary transformations (resizing, cropping, normalization).

Dataset Path

Update the path to the dataset in the following line of the code:

with zipfile.ZipFile('/content/drive/MyDrive/AI_OWN/dataset/celeba/img_align_celeba.zip', 'r') as zip_ref:
    zip_ref.extractall('./data/celeba')

Code Structure

The code is structured as follows:

  1. Data Loading and Preprocessing:

    • The dataset is loaded and preprocessed using torchvision.datasets and torchvision.transforms.
    • Images are resized to 64x64, center-cropped, and normalized.
  2. Model Architecture:

    • Generator: A convolutional neural network that generates images from random noise.
    • Discriminator: A convolutional neural network that classifies images as real or fake.
  3. Training Loop:

    • The Generator and Discriminator are trained alternately using the Adam optimizer.
    • Binary Cross-Entropy Loss (BCELoss) is used as the loss function.
  4. Visualization:

    • Training images and generated images are visualized using Matplotlib.
    • An animation is created to show the progression of generated images during training.

Training the Model

To train the model, simply run the provided Python script or Jupyter Notebook. The training process will display the following:

  • Loss values for the Generator and Discriminator.
  • A grid of real images from the dataset.
  • A grid of generated images at different stages of training.

Hyperparameters

You can adjust the following hyperparameters:

  • batch_size: Batch size for training (default: 128).
  • z_dim: Dimension of the noise vector (default: 100).
  • num_epochs: Number of training epochs (default: 10).
  • learning_rate: Learning rate for the optimizer (default: 0.0002).
  • beta1: Momentum term for the Adam optimizer (default: 0.5).

Results

After training, the model will generate realistic face images. The following visualizations are provided:

  1. Training Images: A grid of real images from the CelebA dataset.
  2. Generated Images: A grid of images generated by the trained Generator.
  3. Training Progress Animation: An animation showing how the generated images improve over time.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages