In this lecture we are going to begin looking at our facial recognition code with Siamese networks.
As usual you can look at the title of the notebook to determine what notebook we are currently looking
at.
Since this is a large piece of code it's going to span over several lectures with each lecture focused
on a single theme.
The theme of this lecture will be loading in the data.
As I mentioned previously the actual theory and model behind this project are pretty simple.
And most of the work will go into loading in the data and processing it correctly
so the first thing you'll notice in this script is the strange imports.
This course is about pi talk.
But I'm importing tens of flowing cars.
Why am I doing that.
Well first let's start by recognizing that these are both just Python libraries.
There's no reason you can't use multiple Python libraries simultaneously.
As we often do for example we use an empire map plot lived side by side.
So just because pi torch and sensor flow overlap in what they do in the sense that they're both ways
of building neural networks it's totally acceptable to use a different library that has some useful
functionality even if the neuron that were parts of these libraries are incompatible
so first let's download our dataset.
We'll be using the Yale face data set.
It's just a bunch of different faces that have different emotions like happy sad and so forth
next.
Since this is a zip file we're going to unzip it using the unzip command
next we're going to get the file paths of all the images using the glob function you'll notice that
while all the images are gifts they don't end in the file extension that G I f they have file names
like subjects 0 1 one happy subject.
Oh one not sad and so forth.
So we are looking for any file that starts with the string subject.
Next we are going to shuffle the file pass which will be important later when we create our train and
test sets.
Next we're going to set the number of files to a variable called n so we have one hundred sixty six
images.
Next we have a function that loads in the data from a file path and returns an umpire a there are multiple
things going on here.
So let's break it down.
First we call image dot load AMG to load in the file as an image object.
This also allows us to resize the image to 60 by 80.
Which I found leaves a smaller memory footprint and doesn't prevent us from getting good results.
The original image size was 243 by 320 which was unnecessarily large.
Next we call I am g to array to convert the image object into an umpire.
And finally we convert it to a U.N. eight which takes up only eight bits per pixel rather than 32 or
64 for a float or double
next.
As I always like to do I'm going to plot a random image from the data.
Just for fun.
This always helps me get into the flow of things when I'm coding
if we took the shape of our image.
You might expect to see 60 by 80 since well that's what we specify.
We want the size to be but something weird is happening here if you look closely the actual image shape
is 60 by 80 by 3.
That just seem weird to you because if we look at these images they are clearly grayscale images yet
they are stored as color images with three color channels as an exercise.
I would recommend verifying that each of these channels actually have the same values and so they are
redundant.
Therefore we lose nothing by converting these technically color images integrate scale.
We can do that by taking the mean along the last axis
next we're going to load in the images into a single num higher array so its end by whatever the image
shape is 60 by 80.
So all we do here is we live through each of the image file paths we call the lower AMG function which
we just define and then we store the image in our big array of images.
Next we're going to create an array of labels of length n these are not our binary labels.
These are just labels telling us which subjects the corresponding images of.
Basically this is just a bunch of manual string passing since I don't like to play with regex.
So first we split out the file name by splitting on the last forward slash.
Next we split out the subject's part of the file name by splitting on the first dot.
So now we have a string that's like subject a one a subject or two subjects or three and so forth.
Finally we just remove the subject strain so we're left with 0 1 0 2 or 3 and so on.
And since the IDB starts from one I just subtract one so that it starts from zero.