YUFENG GUO: One of the top things that I get asked about
is AutoML.
In this two-part video, let's try
using AutoML Vision to build and deploy a machine learning model
that recognizes different types of chairs
along with a few other items sprinkled in for good measure.
We're doing it all--
from the raw data collection, all the way
to serving the model, and everything in between.
Welcome to "AI Adventures," where
we explore the art, science, and tools of machine learning.
My name is Yufeng Guo.
And on this episode, we'll explore AutoML Vision,
currently in alpha, and get our data
into the right format as an input.
In part 2, we'll use this data to build a model
to detect what style of chair is in a picture.
One of the things that makes AutoML so compelling
is having a custom model.
Existing models and services, like the Vision API,
have no problem recognizing that these pictures have
chairs in them.
But what if you made your own chairs,
and that you needed a way to catalog
the various brands of different chairs in your inventory?
Wouldn't it be nice to be able to use a custom Vision
API, so to speak, which recognizes
your particular chairs?
That's what we're going to try to do with AutoML Vision.
AutoML Vision takes as an input lots and lots
of labeled photos.
So get your camera out and start snapping pictures.
How many pictures you ask?
Well, ideally, you'd have hundreds
of pictures per object.
And that would be good.
And then, once you get tired of clicking that shutter option,
perhaps you'll try doing what I did to get
lots and lots of pictures.
To make it easier to capture data for AutoML,
I chose to gather my training data
by capturing videos of the chairs
and then using the tool ffmpeg to extract out those frames.
I've gone out over to the Google Sunnyvale campus.
I took some videos of a variety of different outdoor chairs.
I also took some video of the tables they were positioned
around, as well as a bike-- eh--
just to make things a little more interesting.
Let's take a look at some of that footage now.
Here, we have some chairs of different shapes, styles,
and colors.
No video is greater than 30 seconds in length.
And we have a short clip of a table and another of a bike.
That's the data that we will be working with.
The end state that we want is a CSV file
that has one row per image and two columns--
the first for the location of the image in Google Cloud
Storage, and the second for the label,
like red chair or table or blue chair.
To make it easier to organize, I placed each video
in its own folder.
So then we can run ffmpeg on each video file in turn
within those folders.
That way, once the frames are extracted out,
you'll have one folder per label filled
with images of just that label.
This is a handy way to organize your images and data.
And it's simpler than having one massive folder
of all the images intermingled.
Next, we can upload images to Google Cloud Storage,
using gsutil, replicating our folder structure
of one folder per label.
Now, it's time to get to work creating a CSV file that
lists the path and label for each image I wanted
to include in my data set.
Now, there's lots of ways to accomplish this.
But I chose to spin up a local Jupyter notebook
and create a Pandas data-frame that
gets exported as a CSV file.
Let's walk through that code now.
OK, so here we are in our Jupyter notebook.
And I've imported OS and Pandas, so we
can work with the file system.
And load up Pandas-- that way we can use that to export our CSV.
I've listed out all the folders that I want
to use to pull in the data.
And I've listed this out here explicitly
because, perhaps in a different scenario,
I might choose to use just a subset of these folders
to create a different training set.
So then we have a setup here to create
a dictionary of our folder name and then
mapping to an array of all of our files for that folder.
And so to do that, first, I'm going
to create an array of arrays of just all those file names.
Each inner array is all the file names of one folder.
And the outer array is just for each folder.
And so here, we're listing through all the files
in a folder.
So our data folder is here.
And we'll wrap that in an array so that we can capture that.
And so we can see, here, I've printed
a sample of one value, one image, in each of the folders.
And we can see that they're all different.
So it looks like we're in good shape.
And so we can take those two--
our folder names and all our file
names-- and zip them together.
Pass them to create a dictionary.
Using that and our base Google Cloud Storage path,
we can glue these two together, because we
want to pre-pen the GCS, or Google Cloud Storage path,
in the final output.
So what we want is something like this,
where we have the Google Cloud Storage directory path,
all the way out to the .jpeg name, and then a comma,
and then the name of the label.
So in this case, maybe we have a comma
and then chair_black, like so.
And so to do that, we'll loop over the entire dictionary.
And for each file in the array of file names
in that dictionary, we will put together
the base Google Cloud Storage path,
along with the folder name and file name,
as well as that label.
So now, what we have with us here is an array of pairs.
Each pair has that path and the label.
So we can take this array and just pass it
straight into a data frame.
Pandas accepts that format to create new data
frames from scratch.
And our data frame looks exactly as we'd expect.
We got all our paths and all our labels.
Now, we're ready to export to CSV.
In this particular case, we want to export such
that we use index equals false and header equals false.
This is important and can really trip you up
if you forget to do this.
Because if you leave the defaults, which
are index-- true, and header-- true,
the outputted CSV file will have a header row of 0 and 1.
And moreover, it will have an index column
that comes before everything else, which is just going
to be your 0, 1, 2, 3, 4, 5.
So we don't want any of that.
We just want the path to the file
and the label, nothing else.
So we use index-- false, and header-- false.
So if you organize your folder structure the same way that I
have mine, you can take this notebook
and, with a couple of minimal changes,
adapt it for your use case as well.
So I'll definitely publish this notebook and link
to that down below in the video description.
All right, so now we have a CSV file
describing the location and label for all the images
in our data set.
We're ready to train our model.
Join me in part 2 of this episode.
And we'll see just how well this model can perform.
Thanks for watching this episode of "Cloud AI Adventures."
And if you enjoyed it, hit that Like button down below.
And be sure to subscribe to get all the latest updates right
when they come out.
And while you head over to part two of this video,
I'm going to eat this--
mm-- apple.
[MUSIC PLAYING]