mjplacroix / RockPaperScissor-AI-

Building an AI to play Rock Paper Scissor using Neural Networks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building a Rock Paper Scissor AI with Neural Networks

This Repo is aimed at beginers who want to try and build their own bots with ease. So lets begin!

Getting Our Data

The basis of any Machine Learning model is DATA. Any machine learning engineer would agree that in Machine Learning the Data is far more important than the algorithm. We need to collect images for the symbols Rock, Paper adn Scissor. Here we have getData.py which is run like this

python getData.py label startIndex endIndex

This will essentialy make a folder of name label and store (endIndex-startIndex+1) images .

Training our Model

Next we move to training our model. Here we have used the DenseNet model available from keras.applications as a base model to work upon. It is followed by a MaxPooling Layer which is Flattened and finally run through a Dense Layer with 3 Output Neurons and SoftMax Activation to predict our output from 3 Classes Rock, Paper and Scissor. Here we have trai.py which is run like this

python train.py pathToImages

This will iterate over the files produced by getData.py and train our Model. Once trained the Model architecture is stored in a json file and the weights are stored in .h5 file. Due to lack of computational power I had to train the model using Google Colab by setting Hardware Accelration to GPU.

Time to play!

Now we load our Model Architecture and weights and finally play the game. Refer play.py Before running make sure the model.h5 and model.json files are in same folder as play.py. To Run:

python play.py

In-Game Snapshots


Making Predictions In the Game :


Bot Playing and Score Updates


Final Outcome

Requirements

  • tensorflow
  • keras
  • opencv

Notes:

This model works with staionary backgrounds against which Model has been trained. We could implement Hand Detection followed by Gesture Classifation to improve performance. This is a very basic model that simply tries to make predictions on the input image without any major preprocessing but is enough if you play in the same physical position. If you're new at this try chaning your Dataset and re-train your model multiple times would really help you gain better insights into the project.

About

Building an AI to play Rock Paper Scissor using Neural Networks


Languages

Language:Python 100.0%