Implementation of Deep Convolutional Generative Adversarial Network (DCGAN) for generating Human faces using Python and TensorFlow, entirely executed on Kaggle.
This project implements a variation of the Generative Adversarial Network (GAN) called Deep Convolutional GAN (DCGAN) to generate synthetic human faces using Python and TensorFlow. The DCGAN architecture consists of two competing neural networks:
- (1) The Generator : Creates fake face images from random noise.
- (2) The Discriminator : Tries to distinguish between real and fake images.
Both networks improve through adversarial training: the generator gets better at mimicking real faces, and the discriminator becomes more skilled at detecting fakes. This dynamic pushes the generator to produce increasingly realistic outputs. To maintain balance during training, the discriminator is deliberately kept simpler to avoid overpowering the generator.
The model is trained on the Flickr Faces Dataset Resized from kaggle, which includes 52,000 face images in three resolutions: 64x64, 128x128, and 256x256. Due to GPU memory limitations, 64x64 resolution is recommended for training on the full dataset. However, this project experimented with 256x256 resolution on a smaller subset of the dataset to generate higher-quality outputs. All development and experimentation were carried out on Kaggle, leveraging its GPU resources. This project also shows how input resolution impacts the quality of generated faces—higher-resolution training images lead to sharper, more realistic outputs, while lower resolutions introduce some blur and noise.
DCGAN Model Architecture Summary
- Two Neural Networks:
- Generator ("Artist") – creates realistic-looking images.
- Discriminator ("Critic") – distinguishes real images from fakes. During training, both networks improve in opposition until the discriminator can no longer tell real from fake images.
Generator Architecture
-
Structure:
- Fully connected (Dense) layer
- Transposed Convolution layers (upsampling)
- Final Output Layer
-
Workflow:
- Starts with a latent vector (8x8x512).
- Upsamples through transposed convolutions:
- 8×8 → 16×16 (256 channels) --> 16×16 → 32×32 (128) -->
- 32×32 → 64×64 (64) --> 64×64 → 128×128 (32) --> 128×128 → 256×256 (16)
- Output layer: tanh activation to produce final 64×64×3 RGB image.
-
Activations: ReLU for all layers (except final layer which uses tanh).
Discriminator Architecture
-
Structure:
- Convolutional layers (reverse of generator)
- Flatten and Dropout
- Final Classification Layer
-
Workflow (mirrors Generator in reverse):
- 256×256 → 128×128 (16 channels) --> 128×128 → 64×64 (32) --> 64×64 → 32×32 (64)-->
- 32×32 → 16×16 (128) --> 16×16 → 8×8 (256)
-
Activations: LeakyReLU (after BatchNorm), except output layer.
Loss Functions
-
Binary Crossentropy used for both models.
-
Discriminator Loss:
- Measures accuracy of distinguishing real vs. fake (real → 1, fake → 0).
-
Generator Loss:
- Measures success at fooling the discriminator (fake → 1).
Optimization
- Both models use Adam Optimizer independently for training.
The project successfully demonstrates the capability of DCGANs to generate human faces, although the realism of the output images largely depends on the scale of training and the size of the input dataset.
- Synthetic Face Generation
- Data Augmentation
- Anonymization
- Art & Creative Media
- AI Model Benchmarking
- Educational Purpose
- Testing Face Recognition Systems
- Current Version: V1.0
paper-hbert-sarcasm-detection/
├── README.md
├── LICENSE
├── .gitignore
├── assets/
│ └── images/
└── notebooks/
└── sarcasm-analysis.ipynb
- ✅
DCGAN
model class - ✅ Preprocessed Data
- ✅ Evaluation: Visualization of generated synthetif human face output
🛠️ In progress:-
- On-going training with 256x256 images with more training epochs
- Python programming
- ML/DL fundamentals, Neural Network Arhitecutres (CNN, GAN)
- Optimizers, Loss Functions
- IDE (VS Code) or jupyter notebook or google colab, kaggle
- Best run on Kaggle using GPU T4x2
- Language: python
- NLP/ML: sklearn, pandas, numpy
- Deep Learning: tensorflow
- Visualization: matplotlib
📥 (1) Data-Preprocessing : wh
- Load dataset from kaggle
- Ensure RGB (convert from grayscale if needed)
- Resize images
- Convert to float dtype
- Normalize to (-1, 1) for GAN training
- Append processed images to dataset
🤖 (2) DCGAN : Two Neural Networks: 1. Generator ("Artist") – creates realistic-looking images. - Activations: ReLU for all layers (except final layer which uses tanh). 3. Discriminator ("Critic") – distinguishes real images from fakes. - Activations: LeakyReLU (after BatchNorm), except output layer.
📉 (3) Loss Functions :
- Binary Crossentropy used for both models.
- Discriminator Loss: Measures accuracy of distinguishing real vs. fake (real → 1, fake → 0).
- Generator Loss: Measures success at fooling the discriminator (fake → 1).
📶 (4) Optimization :
- Both models use Adam Optimizer independently for training.
- Seeing the generated fake images
- Future work : auraccy, precision , recall , f1
git clone https://github.com/pointer2Alvee/dcgan-human-face-generation.git
cd dcgan-face-gen
# Recommended: Use a virtual environment
pip install -r requirements.txt
pandas
numpy
tensorflow
matplotlib
- Open Repo in VS code / Kaggle (recommended)
- Run Command
- See accuracy
- Open VS Code / kaggle
- ✅ DCGAN
- ✅ CNN, CONVOLUTION, POOLING
- ✅ GAN, OPTIMIZERS, LOSS FUNCTIONS
- Implementation of DCGAN
- Generation of Fake Human Faces
- Trained with 300+ epochs
Contributions are welcomed!
- Fork the repo.
- Create a branch:
git checkout -b feature/YourFeature
- Commit changes:
git commit -m 'Add some feature'
- Push to branch:
git push origin feature/YourFeature
- Open a Pull Request.
Distributed under the MIT License. See LICENSE.txt for more information.
- Special thanks to the open-source community / youtube for tools and resources.