-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add project files to remote repository.
- Loading branch information
Showing
4 changed files
with
1,580 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Udacity project Face Generator using CelebA | ||
This project was part of the [Udacity Deep Learning Nano Degree Program](https://www.udacity.com/course/deep-learning-nanodegree--nd101) | ||
that was teaching basics on building Generative Adversarial Networks (GANs). | ||
|
||
In this project, we did build and train a custom GAN architecture on the CelebA dataset, | ||
leveraging the different skills learned during the course mentioned above. | ||
|
||
## Model Architecture | ||
### Deep Convolutional GANs | ||
In this notebook, I've chosen to apply the DCGAN architecture to build a GAN using convolutional layers in the generator and discriminator. | ||
This is called a Deep Convolutional GAN, or DCGAN for short. | ||
|
||
The DCGAN architecture was first explored in 2016 and has seen impressive results in generating new images. | ||
You can read the original paper, [here](https://arxiv.org/pdf/1511.06434.pdf). | ||
|
||
Next to using Convolutional layers, I used label smoothing technique for the discriminator and the | ||
'Two Times Update Rule' for the genrator part of the model. | ||
|
||
## Data Set | ||
You’ll be training DCGAN on the [Large-scale CelebFaces Attributes (CelebA) Dataset](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html) dataset. | ||
|
||
These are color images of celebrities. In this course, Udacity provides a smaller subset of this data set with in total 32,600 pre-processed images. | ||
More details are provided by Udacity in the Jupyter notebook `face_generator.ipynb`. | ||
|
||
# Getting Started | ||
So, our goal is to create a DCGAN that can generate new, realistic-looking images. | ||
We’ll go through the following steps: | ||
1. Extract the prepared subset of the celeb data set | ||
2. Define discriminator and generator networks | ||
3. Train the DCGAN network | ||
4. Visualize the loss over time and some sample, generated images | ||
|
||
## Requirements | ||
It is recommended to train the model on GPU. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
matplotlib==3.4.3 | ||
numpy==1.21.4 | ||
Pillow==9.0.0 | ||
torch==1.10.0 | ||
torchvision==0.11.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import numpy as np | ||
import torch | ||
from torch.utils.data import DataLoader, Dataset | ||
|
||
|
||
def check_dataset_outputs(dataset: Dataset): | ||
assert len(dataset) == 32600, 'The dataset should contain 32,600 images.' | ||
index = np.random.randint(len(dataset)) | ||
image = dataset[index] | ||
assert image.shape == torch.Size([3, 64, 64]), 'You must reshape the images to be 64x64' | ||
assert image.min() >= -1 and image.max() <= 1, 'The images should range between -1 and 1.' | ||
print('Congrats, your dataset implementation passed all the tests') | ||
|
||
|
||
def check_discriminator(discriminator: torch.nn.Module): | ||
images = torch.randn(1, 3, 64, 64) | ||
score = discriminator(images) | ||
print(score.shape) | ||
assert score.shape == torch.Size([1, 1, 1, 1]), 'The discriminator output should be a single score.' | ||
print('Congrats, your discriminator implementation passed all the tests') | ||
|
||
|
||
def check_generator(generator: torch.nn.Module, latent_dim: int): | ||
latent_vector = torch.randn(1, latent_dim, 1, 1) | ||
image = generator(latent_vector) | ||
assert image.shape == torch.Size([1, 3, 64, 64]), 'The generator should output a 64x64x3 images.' | ||
print('Congrats, your generator implementation passed all the tests') | ||
|