Generative Machine Learning on the Cloud is a cloud based tool to aid in
generative art and synthetic image generation. The end to end system design
allows a user to have a custom dataset of images to train a Variational
Autoencoder Generative Adversarial Network (VAE-GAN) model on Cloud ML. From
here, their model is deployed to the cloud, where they can input an embedding to
have synthetic images generated from their dataset or input an image to get an
embedding vector.
If using a TensorFlow virtualenv, make sure to clone into a subdirectory
of the virtualenv directory
How To: Run a Training Job
A training job will train the VAE-GAN on your own training data!
Important: You will be using billable components of the Cloud Platform and will
incur charges when running a training job.
cd into the data directory of the source code you just cloned. Make sure to
activate the tensorflow virtualenv (if that is the method you chose to
install TensorFlow).
The larger your image set, the less chance of overfitting!
One rule of thumb is at least ~1000 images per class.
If you are trying to synthesize faces, try to have at least 1000
face images.
If you are trying to generate both cat and dog images, try to have
at least 1000 cats and 1000 dogs.
The model will crop / resize your images to 64x64 squares.
Use the -c flag to specify centered cropping (or else it will random
crop).
The image is cropped to a bounding box of side lengths of
minimum(original_height, original_width).
The image is resized to 64x64 (using
tf.image.resize_images
to either downsample or upsample using bilinear interpolation).
This script will turn your image files into TFRecords file
format
with Example protos and saves them to your GCS bucket. It partitions
your data into a training dataset and a validation dataset.
For efficient throughput, image files should not exceed 4 MB. Reducing
image size can increase throughput.
Example:
sh run_training.sh -d $PATH_TO_TRAINING_DIR -c
Flags: [-d PATH_TO_TRAINING_DIR] : required, supplies image directory of .jpg or
.png images [-c] : optional, if present images will be center-cropped, if absent
images will be randomly cropped. [-p] : optional, port on which to start TensorBoard instance.
Monitor your training job using the TensorBoard you started or the Cloud
dashboard
TensorBoard: Starts at http://0.0.0.0:6006 by default, unless port
specified.
Now that we have a deployed model trained with your own data, we can use it to
generate new samples.
Generate an Image!
I’ve provided a script to randomly generate an image from your model and
display it:
sh generate_image.sh -m $MODEL_NAME
Flags: [-m MODEL_NAME] : required unless -l flag present, specifies model to
generate image. [-l] : optional, if present lists all models associated with user. [-d TEMP_DIR] : optional, directory to which to write json file.
Huge shoutout to this awesome
DCGAN. After much trial error,
the architecture from this network was the one that produced the greatest
generative results and ended up as the network architecture in the final version
of this tool.
Generative Machine Learning on the Cloud
This tool uses the Google Cloud Machine Learning API and Tensorflow.
Generative Machine Learning on the Cloud is a cloud based tool to aid in generative art and synthetic image generation. The end to end system design allows a user to have a custom dataset of images to train a Variational Autoencoder Generative Adversarial Network (VAE-GAN) model on Cloud ML. From here, their model is deployed to the cloud, where they can input an embedding to have synthetic images generated from their dataset or input an image to get an embedding vector.
How To Use the Tool
Pre-steps:
How To: Run a Training Job
A training job will train the VAE-GAN on your own training data!
Important: You will be using billable components of the Cloud Platform and will incur charges when running a training job.
cd into the data directory of the source code you just cloned. Make sure to activate the tensorflow virtualenv (if that is the method you chose to install TensorFlow).
Run the training script
Dataset Tips:
Example:
Flags:
[-d PATH_TO_TRAINING_DIR] : required, supplies image directory of .jpg or .png images
[-c] : optional, if present images will be center-cropped, if absent images will be randomly cropped.
[-p] : optional, port on which to start TensorBoard instance.
Monitor your training job using the TensorBoard you started or the Cloud dashboard
How To: Create and Deploy Model
Now that we have a trained model saved on GCS, lets deploy it on Cloud ML!
cd into the data directory of the source code.
Run create model script (if you don’t know your job name, use the -l flag)
Example:
Flags:
[-j JOB_NAME] : required unless -l flag present, supplies job name
[-l]: optional, if present lists 10 most recent jobs created by user
Look at your deployed model on the cloud dashboard under Cloud ML Engine!
How To: Run an Inference Job
Now that we have a deployed model trained with your own data, we can use it to generate new samples.
Generate an Image!
I’ve provided a script to randomly generate an image from your model and display it:
Flags:
[-m MODEL_NAME] : required unless -l flag present, specifies model to generate image.
[-l] : optional, if present lists all models associated with user.
[-d TEMP_DIR] : optional, directory to which to write json file.
Assumes PIL is installed
Embedding to Image generation
Use the command line & a json file!
Example format:
Embedding array must have dimension of 100 (if using current vae-gan) or whatever was specified in the code:
Example command:
Batch Prediction Job
Example format:
Json file must be on GCS
Example command:
Use python API
Documentation here
Setup project and execute request
Image to Embedding generation
Use the command line & a json file!
Image has to be base64 encoded jpeg
Example format:
Batch Prediction
Python API
Same as for embedding to image, but request_dict:
Where img is a base64 encoded jpeg
Acknowledgements
Huge shoutout to this awesome DCGAN. After much trial error, the architecture from this network was the one that produced the greatest generative results and ended up as the network architecture in the final version of this tool.
Disclaimer
This is not an official Google product.