https://github.com/pointer2alvee/dcgan-human-face-generation
An implementation of the Generative model, DCGAN, for generating human faces using Python, TensorFlow
https://github.com/pointer2alvee/dcgan-human-face-generation
Last synced: 8 months ago
JSON representation
An implementation of the Generative model, DCGAN, for generating human faces using Python, TensorFlow
- Host: GitHub
- URL: https://github.com/pointer2alvee/dcgan-human-face-generation
- Owner: pointer2Alvee
- License: mit
- Created: 2025-04-22T04:55:19.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-04-23T05:53:02.000Z (10 months ago)
- Last Synced: 2025-04-23T06:31:02.789Z (10 months ago)
- Language: Jupyter Notebook
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## π dcgan-human-face-generation
#### π Summary
Implementation of Deep Convolutional Generative Adversarial Network (DCGAN) for generating Human faces using Python and TensorFlow, entirely executed on Kaggle.
#### π§ Overview
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](https://www.kaggle.com/datasets/matheuseduardo/flickr-faces-dataset-resized/data) 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:
1. Generator ("Artist") β creates realistic-looking images.
2. 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:
1. Fully connected (Dense) layer
2. Transposed Convolution layers (upsampling)
3. Final Output Layer
- Workflow:
1. Starts with a latent vector (8x8x512).
2. 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)
3. 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:
1. Convolutional layers (reverse of generator)
2. Flatten and Dropout
3. Final Classification Layer
4.
- Workflow (mirrors Generator in reverse):
1. 256Γ256 β 128Γ128 (16 channels) --> 128Γ128 β 64Γ64 (32) --> 64Γ64 β 32Γ32 (64)-->
2. 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.
#### π― Use Cases
- Synthetic Face Generation
- Data Augmentation
- Anonymization
- Art & Creative Media
- AI Model Benchmarking
- Educational Purpose
- Testing Face Recognition Systems
#### π’ Project Status
- Current Version: V1.0
#### π Repository Structure
```
paper-hbert-sarcasm-detection/
βββ README.md
βββ LICENSE
βββ .gitignore
βββ assets/
β βββ images/
βββ notebooks/
βββ sarcasm-analysis.ipynb
```
### β¨ Features
- β
`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
### π Getting Started
#### π Knowledge & Skills Required
- Python programming
- ML/DL fundamentals, Neural Network Arhitecutres (CNN, GAN)
- Optimizers, Loss Functions
#### π» Software Requirements
- IDE (VS Code) or jupyter notebook or google colab, kaggle
- **Best run on Kaggle using GPU T4x2**
#### π‘οΈ Tech Stack
- Language: python
- NLP/ML: sklearn, pandas, numpy
- Deep Learning: tensorflow
- Visualization: matplotlib
#### π Modules Breakdown
π₯ (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.
##### π Evaluation
- Seeing the generated fake images
- Future work : auraccy, precision , recall , f1
#### βοΈ Installation
```
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
```
##### ποΈ requirements.txt (core packages):
```
pandas
numpy
tensorflow
matplotlib
```
##### π» Running the App Locally
1. Open Repo in VS code / Kaggle (recommended)
2. Run Command
3. See accuracy
#### π Usage
- Open VS Code / kaggle
### π§ͺ Sample Topics Implemented
- β
DCGAN
- β
CNN, CONVOLUTION, POOLING
- β
GAN, OPTIMIZERS, LOSS FUNCTIONS
### π§ Roadmap
- [x] Implementation of DCGAN
- [x] Generation of Fake Human Faces
- [ ] Trained with 300+ epochs
### π€ Contributing
Contributions are welcomed!
1. Fork the repo.
2. Create a branch: ```git checkout -b feature/YourFeature```
3. Commit changes: ```git commit -m 'Add some feature'```
4. Push to branch: ```git push origin feature/YourFeature```
5. Open a Pull Request.
### πLicense
Distributed under the MIT License. See LICENSE.txt for more information.
### πAcknowledgements
- Special thanks to the open-source community / youtube for tools and resources.