In previous video we created a neural network
that tells us whether test image contains
hand or not well what next, if neural network
classifies an image as containing hand we
would like to know location of that hand.
This is called object detection in computer
vision literature.
so, let's train a neural network that does
exactly same.
Let's get started.
If you want a neural network to output location
of hand, we need to train it in such a fashion
i.e. unlike previous neural network where
each image was labeled as either with hand
and without hand.
This time all images with hand will have four
labels corresponding to diagonal coordinates
of bounding box around hand in that image.
This csv file contains label for each image.
Please note that coordinates are normalized
with image dimension i.e. if upper X coordinate
is at 320th pixel in image with width of 640
pixels, we will label it as 0.5.
You might be wondering how I managed to label
all 82 images, well I wrote a GUI in python
that helped me with this task.
Once image is loaded in GUI.
I left click at upper coordinate and right
click at lower coordinate of probable bounding
box around the hand.
These coordinates are then written to a file
following that I click next button to load
next image.
I repeated this procedure for all 82 train
and 4 test images.
Once labels were ready , it was training time.
First we need to load all necessary libraries.
Which includes PIL for image manipulation,
matplotlib for plotting, numpy for matrix
operation, os for operating system dependent
functionality and keras for neural network.
In 2nd, 3rd, 4th and 5th cell we load images
into numpy array and create a four dimensional
array from csv file to act as labels.
In cell number 6 we create our neural network.
Its architecture is identical to neural network
used for classification except the output
layer dimension which is 4 and not 1.
Another difference comes from loss function
used which is mean squared error.
In cell number 8 we start training of our
neural network once trained I ran this model
on test set to get predictions for bounding
box on overlaying coordinates of bounding
box they looked pretty accurate.
So, guys thats it for this miniProject if
you liked this video please don't forget to
like, share and subscribe to my channel.
I will see you soon with another video till
then train a neural network.
