Conditional Generative Adversarial Network (cGAN) model for generating real 2D images of hands depicting Rock Paper Scissors shapes as used in the game.
Will use the CRISP-ML(Q) process model for the development of the project.
[x] Business and Data Understanding
[~] Data Engineering (Data Preparation)
[~] Machine Learning Model Engineering (Generator, Discriminator, Training Step, Training, ImageGen, Model Testing)
[ ] Quality Assurance for Machine Learning Applications
[x] Deployment (ImageGen API, Server, CI/CD)
[ ] Monitoring and Maintenance
The investigations are recorded & stored in ./docs/.
- HYPERPARAM_ is a documentation of the test runs which aim to find the optimal hyperparameter values on a train run of epochs. Each run documents : I. Hyperparameter values II. Time per epoch & Total time for whole process III. Model loss plot (D, G, D_G) IV. Last image generated by G on a batch
The development process & testing should be carried in a virtual environment. When cloning the repository, there will be no virtual environment available, but it can be created & accessed & exit by running the terminal commands below (Unix/macOS) in the root of the project :
python3 -m venv env
source env/bin/activate
deactivate
Trying to run 'python main.py' while not in the virtual environment won't work as the pip packages are installed in the virtual environment.
Libraries should be installed for the project while in the virtual environment.
The dataset comes from the default tensorflow_datasets package. It needs to be installed in the environment to be accessible. This can be done by running the command below.
pip install tensorflow_datasets
The trained model can be used through the ImageGen API for generating photos of hands similar to the ones used in the training phase.
A Flask server was created that incorporates the ImageGen API which accepts REST requests and returns data (eg: a base64 encoded image of a hand depicting RPS shapes)
The Flask server deployment is automated using GitHub Actions and is deployed to Heroku.
There is a test harness which tests the behaviour of the ImageGen API. Additionally, a test harness was created in order to test the behaviour of the server routes.
A few examples below of libraries used to run the entire project (model training, image generation, Flask server):
- Tensorflow (& Keras)
- sklearn
- Flask (for deployment purposes)
- Other commonly-used libs (numpy, matplotlib, cv2, etc.)
For a complete list of the required libraries, check the requirements.txt
file.
Tensorflow, sklearn and Flask (if neccessary) have to be installed (in the virtual environment) by running the command below in the root directory of the repository :
pip3 install -r requirements.txt
- https://ml-ops.org/content/crisp-ml#:~:text=Overall%2C%20CRISP%2DML(Q,ensure%20the%20ML%20project's%20success
- https://learnopencv.com/conditional-gan-cgan-in-pytorch-and-tensorflow/
- https://developers.google.com/machine-learning/gan/generator
- https://www.tensorflow.org/api_docs/python/tf/
- https://stackoverflow.com/questions/
- https://towardsdatascience.com/10-lessons-i-learned-training-generative-adversarial-networks-gans-for-a-year-c9071159628
- https://towardsdatascience.com/beating-the-gan-game-afbcce0a20be
- https://machinelearningmastery.com/how-to-train-stable-generative-adversarial-networks/