Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC] Face Aging with Age-cGAN #83

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tensorflow_examples/models/age_cgan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Age-cGAN
### Face aging - FaceApp
---
#### Dependencies
```
tensorflow==2.0.0b1
absl_py==0.7.0
numpy==1.16.4
matplotlib==2.2.3
scipy==1.1.0
```
#### Downloads
- To download all the dependencies, simply execute
```
pip install -r requirements.txt
```
- To download the Wiki Cropped Faces dataset, simply execute the `data_download.py` file
```
python data_download.py
```
#### Training
There are 3 stages of training:
1. Conditional GAN Training (Generator and Discriminator)
2. Initial Latent Vector Approximation (Encoder)
3. Latent vector optimization (Encoder and Generator)
- The `model.py` file contains the code to run all 3 stages of training. It automatically stores the weights after the specified/default number of epochs have completed. Note that the weights will be stored at the same directory level as `model.py`.
```
python model.py
```
- An important distinction to note is that there are 3 bool variables, namely `TRAIN_GAN`, `TRAIN_ENCODER` and `TRAIN_ENC_GAN` wich respectively represent the 3 stages of training. They have been set to `True` by default. If the requirement arises such that the training be completed individually, set the respective variables to `False` and ensure the requirements are met before proceeding.
---
#### Architecture
1. Encoder: Learns the reverse mapping of input face images and the latent vector
2. FaceNet: Face recognition network
3. Generator: Takes a hidden representation of the face and a condition vector to generate a face
4. Discriminator: Distinguishes between real and fake images
#
- **Encoder**: 4 CNN blocks with BatchNorm and Activation layers followed by 2 FC layers
- **Generator**: CNNs, Upsampling layers and dense layers
- **Face Recognition**: Pretrained `Inception-ResNet-V2` or `ResNet-50`
- **Discriminator**: CNN blocks with BatchNorm and Activation layers
#
#### Reference Papers
1. Face Aging with Conditional Generative Adversarial Networks [[Arxiv Link](https://arxiv.org/abs/1702.01983)]
2. Improved Techniques for Training GANs [[Arxiv Link](https://arxiv.org/pdf/1606.03498.pdf)]
Empty file.
56 changes: 56 additions & 0 deletions tensorflow_examples/models/age_cgan/data_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Download the data.

Dataset Citation:
@article{Rothe-IJCV-2016,
author = {Rasmus Rothe and Radu Timofte and Luc Van Gool},
title = {Deep expectation of real and apparent age from a single image without facial landmarks},
journal = {International Journal of Computer Vision (IJCV)},
year = {2016},
month = {July},
}
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import argparse
import tensorflow as tf
assert tf.__version__.startswith('2')

ap = argparse.ArgumentParser()
ap.add_argument('-dp', '--download_path', required=False, help='Download Path')
args = vars(ap.parse_args())

data_url = "https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/static/wiki_crop.tar"

def download_data(download_path):
path_to_zip = tf.keras.utils.get_file(
'wiki_crop.tar', cache_subdir=download_path,
origin = data_url, extract=True)

path_to_folder = os.path.join(os.path.dirname(path_to_zip), '')

return path_to_folder

if __name__ == '__main__':
if args['download_path'] is not None:
path = download_data(args["download_path"])
else:
cur = os.getcwd()
path = download_data(cur)
Loading