image classification of rock paper scissor hands
In this post we are going to setup a simple CNN to be able to classify images of hands playing rock, paper, scissor game. This data-set will be loaded from tensorflow_datasets module
Use pip install tensorflow-datasets if you don’t have this module installed already.
The data-set contains images of people playing the rock, paper scissor games as shown in the picture below.It consist of 2,892 images having only train and test splits. Each image has a shape of [300, 300, 3] with 3 output classes(i.e rock, scissor, paper
To load the data-set the first thing we will need to do is import the necessary libraries. We will then use the tfds.load() to load (downloads and then load on the first time)our data-set while setting with _info and as_supervised to True.
#import the necessary libraries
from tensorflow import keras
import tensorflow as tf
import os,datetime
import tensorflow_datasets as tfds
#Loading the datase
df, info = tfds.load('rock_paper_scissors', with_info = True, as_supervised = True)
view raw
ROCK,PAPER,SCISSOR hosted with ❤ by GitHub
Let’s try to go over some parts of the code that might not be clear
Remember we have just train and test split we need to get our validation split. We will use 10% of the train data as our validation split.
#10 % of the train data as validation data
num_validation = 0.1 * info.splits['train'].num_examples
#Turning it to an integer as a float may cause problem along the way
num_validation = tf.cast(num_validation, tf.int64)
view raw
ROCK,PAPER,SCISSOR hosted with ❤ by GitHub
Before feeding our data into the CNN it will have to go through some form of preprocessing.
Each pixels of the image in our data-set ranges from 0 to 255 which we will scale to between 0 and 1 with the help of a small function
#deep-learning #ai #machine-learning #deep learning