Machine Learning and Games

with TensorFlow.js

Rock Paper Scissors Game

Rock paper scissors (also known by other permutations such as scissors paper rock, scissors paper stone or ro-sham-bo) is a hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand.

These shapes are "rock" (a closed fist), "paper" (a flat hand), and "scissors" (a fist with the index finger and middle finger extended, forming a V). "Scissors" is identical to the two-fingered V sign (also indicating "victory" or "peace") except that it is pointed horizontally instead of being held upright in the air.

A simultaneous, zero-sum game, it has only two possible outcomes: a draw, or a win for one player and a loss for the other. Rock paper scissors is often used as a fair choosing method between two people, similar to coin flipping, drawing straws, or throwing dice in order to settle a dispute or make an unbiased group decision. More info about the game here.

Image Classifier with MobileNet

Let's first take a look at an off-the-shelf MobileNet, TensorFlow.js a model that is trained on ImageNet a dataset of millions of images with labels for 1000 different classes of objects, like dogs, cats, and fruits. The pre-trained models are trained to recognize 1000 classes of image. For a full list of classes here.

This TensorFlow.js model can take as input any browser-based image elements and returns an array of most likely predictions and their confidences.

It can be used in many educational games, especially with younger kids. Try it yourself. Paste an URL address for an image with one of the classes and see the prediction. Try as many images as you like!

For example, copy this URL paste it in the input field below and click Go! button.

Transfer Learning Technique

Transfer Learning technique starts with an already trained model and specializes it for the task at hand. This lets you train far more quickly and with less data than if you were to train from scratch. You can use a technique known as transfer learning to re-train a model to recognize classes not in the original set. For example, you could re-train the model to distinguish between Rock, Paper and Scissors. To do this, you will need a set of training images for each of the new labels you wish to train.

For example, you can train the model by clicking Train button

To add Rock image click Add Rock button, make multiple images for each class. You can use your hands or real objects of rock, paper and scissors. (Allow to use your camera!)

Play the game against a computer.

Click the Play button. Show your choice to the camera. Computer will use random choice generator. See who wins. Play again!