WEI WEI: Hi there. Welcome back. My name is Wei, and I'm
a developer advocate from Google ML team. Today, we're going to take
a closer look at KerasCV in one of the most common
machine learning use cases, image classification. We will start with
basic inference with a pretrained classifier. Then we'll fine-tune
a pretrained backbone. And finally, we're going to
take the more advanced task of training an image
classifier from scratch. First, basic inference-- KerasCV offers a number of
pretrained backbone models, including EfficientNet,
MobileNet, ResNet, and so on. You can find the complete
list of backbone models in the GitHub link below. In this case, we just load
the EfficientNetV2 model pretrained on ImageNet data set,
using the simple from_preset API. Let's take a cat
image as a test. Now, we have the classifier
and the test image. We can just call
the predict method, and we will get the
prediction result. Finally, we look up the
top two predicted classes from the label file. And we can get the right
class, Egyptian cat. As you can see, with
just a few lines of code, we have used a pretrained
model to classify an image. It's super simple. Moving on to fine-tuning a
pretrained backbone model-- while we can directly use
the pretrained EfficientNet model to make predictions,
we can improve accuracy by fine-tuning a
custom classifier. As an example, we're
going to fine-tune a model for classifying cats and dogs. We first load the cats
and dogs data set, and we resize the training data
as preprocessing using a helper function defined before. We can take a peek at some
preprocessed sample images. Now we load the
EfficientNet model again and compile the model. Note that this time we
specified number of classes as 2, since there are only
two labels, cat and dog. Then we called the familiar fit
method to kick off fine-tuning. After training is finished,
we can run the prediction and get the result, cat. That's it for fine-tuning. Our next topic is more advanced,
training an image classifier from scratch. This time, we're going to
use the Caltech 101 data set. We split and shuffle
the data here. Then we batch the data set and
visualize a few sample images. The Caltech 101 data
set has different sizes for every image so we
use the ragged batch API to batch them together
while maintaining each individual image's
shape information. We may also perform some
data augmentation here. But in the interest of time,
we're skipping that part. Our next video will focus
on data augmentation. So make sure to watch that one. Next, we define the optimizer
with a WarmUpCosineDecay schedule. The specific detail
of this schedule is not very important here. Next step is to build our model
by stacking a few layers on top of the EfficientNetV2 backbone. We also define the categorical
cross-entropy loss. Finally, we compile
and fit the model, and the KerasCV will train a
powerful classifier for you. So in conclusion, from what
we have talked about today, you can see how easy it
is to leverage KerasCV and reuse the building
models and modules to build powerful image classifiers. In our next video,
we're going to cover another important topic,
data augmentation. See you next time. [MUSIC PLAYING]