Skip to content
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.DS_Store
images/
.vscode/
/images/
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# ML facial Generation

ML algorithn to generate faces based on race and gender.

# Installation
This can be done using virtual environments.
The steps with different virtual environments are shown below

## Virtual Environments

### ****Conda***

#### Create an environment

```conda create --name nameofenvironment --file requirements.txt```

#### Activating environment
```conda activate nameofenvironment```

# Run
```python cli.py age race gender```
Binary file modified __pycache__/genwhite.cpython-36.pyc
Binary file not shown.
Binary file removed __pycache__/helper.cpython-36.pyc
Binary file not shown.
43 changes: 34 additions & 9 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,42 @@ def main(age,region,sex):
z_dim = 100
learning_rate = 0.0002
beta1 = 0.5
epochs = 2
epochs = 20
if region=='black':
pass
#genblack.train(epochs, batch_size, z_dim, learning_rate, beta1, get_batches, shape)
if sex == 'female':
data_files = genwhite.glob(os.path.join(data_dir, 'black/female/*.jpg'))
data_files.extend(genwhite.glob('*.png'))
shape = len(data_files), IMAGE_WIDTH, IMAGE_HEIGHT, 3
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
with tf.Graph().as_default():
genwhite.train(epochs, batch_size, z_dim, learning_rate, beta1,shape)
elif sex == 'male':
data_files = genwhite.glob(os.path.join(data_dir, 'black/male/*.jpg'))
data_files.extend(genwhite.glob('*.png'))
shape = len(data_files), IMAGE_WIDTH, IMAGE_HEIGHT, 3
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
with tf.Graph().as_default():
genwhite.train(epochs, batch_size, z_dim, learning_rate, beta1,shape)

elif region=='white':
data_files = genwhite.glob(os.path.join(data_dir, 'white/*.jpg'))
shape = len(data_files), IMAGE_WIDTH, IMAGE_HEIGHT, 3
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
with tf.Graph().as_default():
genwhite.train(epochs, batch_size, z_dim, learning_rate, beta1,shape)
if sex == 'female':
data_files = genwhite.glob(os.path.join(data_dir, 'white/female/*.jpg'))
data_files.extend(genwhite.glob('*.png'))
shape = len(data_files), IMAGE_WIDTH, IMAGE_HEIGHT, 3
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
with tf.Graph().as_default():
genwhite.train(epochs, batch_size, z_dim, learning_rate, beta1,shape)
elif sex == 'male':
data_files = genwhite.glob(os.path.join(data_dir, 'white/male/*.jpg'))
data_files.extend(genwhite.glob('*.png'))
shape = len(data_files), IMAGE_WIDTH, IMAGE_HEIGHT, 3
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
with tf.Graph().as_default():
genwhite.train(epochs, batch_size, z_dim, learning_rate, beta1,shape)
else:
click.echo("Enter either black or white as region")

Expand Down
6 changes: 4 additions & 2 deletions genwhite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
# Image configuration
IMAGE_HEIGHT = 28
IMAGE_WIDTH = 28
data_files = glob(os.path.join(data_dir, 'white/*.jpg'))
data_files = glob('images/**/*.*', recursive=True)
shape = len(data_files), IMAGE_WIDTH, IMAGE_HEIGHT, 3

# print(len(data_files))

def get_image(image_path, width, height, mode):
"""
Read image from image_path
Expand Down Expand Up @@ -223,7 +225,7 @@ def train(epoch_count, batch_size, z_dim, learning_rate, beta1, data_shape):
_ = sess.run(d_opt, feed_dict={input_real: batch_images, input_z: batch_z})
_ = sess.run(g_opt, feed_dict={input_real: batch_images, input_z: batch_z})

if steps % 400 == 0:
if steps % 20 == 0:
# At the end of every 10 epochs, get the losses and print them out
train_loss_d = d_loss.eval({input_z: batch_z, input_real: batch_images})
train_loss_g = g_loss.eval({input_z: batch_z})
Expand Down
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
python=3.6
click
requests
tqdm
tensorflow
numpy
matplotlib
pillow