Welcome to
this episode of Bone Hunt:
Discovering Dinosaurs with AI.
I'm Bob Chesebrough,
I'm a solution engineer and technical
evangelist supporting
oneAPI AI here at Intel Corporation.
In this episode of Bone Hunt:
Discovering Dinosaurs with the AI,
we'll be talking about PyTorch,
and to start,
let's talk about what PyTorch is.
However, before we get to that,
I want to acknowledge the help
and support of my colleague
Rahul Unnikrishnan Nair,
who has been instrumental in building
both this video series
and the workshop on which it is based.
PyTorch is a popular
deep learning framework
for building applications
from recommendation systems
to natural language processing.
I chose PyTorch
because it has been adopted by academia
and is community driven.
It is also very similar
to NumPy and Karas.
A key
motivation for using PyTorch
was that I wanted to do this
project on a CPU
and I didn't have a budget
to run a high end GPU node.
If you can do the process on a CPU versus
renting a GPU,
you'll be able to keep your costs down.
With PyTorch, I could go
to their Torch
Vision tutorials,
which provided
a great starting point
for me to begin fine
tuning my model to fit my custom dataset.
There are quite a few pre-trained models
such as ResNet,
which have been trained
on the ImageNet dataset.
Many developers
assume that these pre-trained models
are only good for images closely
related to the images
in the original ImageNet dataset.
But this assumption is false.
We demonstrate here
that images from aerial
photos vastly different
from any image in the ImageNet dataset
can be successfully used
for fine
tuning the ResNet or similar
classification model.
Furthermore, fine tuning worked
well for our custom dataset.
I think this is important for people
to know and understand
because many people get the impression
that they must always
start their project
from scratch
because their data is
unlike anything else in the world.
But that's not the case.
Instead,
you can work
with pre-trained datasets and fine tune
your results.
The technique I used
is called Transfer Learning,
and what it is,
is that we use a pre-trained model
to tweak the model's parameters
and change the last layer
so that it can be used for the datasets
we have defined.
In traditional deep learning,
you might need thousands of images,
but with transfer learning
we are able to get good results
and accuracy
with just hundreds of images per class
and the training time
is significantly less
compared to training a deep
neural network from scratch.
My approach for using PyTorch
was class based.
I defined a dinosaur class,
but for some other use
you could create your own application
class, whatever it is.
Whereas mine just happened
to be focused on dinosaurs.
Once I defined a dinosaur class,
I implemented
two additional classes a trainer class
and a metrics class.
For this project,
we had Class 1: dinosaur bone finder.
This defines
what the model is,
such as the ResNet backbone
and any additional transformation layers.
Class 2:
Metrics Class
which is used to enumerate
accuracy and error rates.
Class 3: Trainer Class helper functions
to easily train
the number of steps
you take to train the model
and the key
train and fine tune loops
in the trainer class.
We provided
a one batch
training mechanism that you can use
to debug your model.
You can get a model to the point
where everything runs,
but that doesn't mean
that the model or the training
has been run correctly.
A quick way to test
is to over fit your model
by training it over one batch.
And if you cannot over fit your model
successfully in one batch,
then clearly there is some issue
with your training algorithm
or your model design.
We have implemented
a data loader approach
compatible with Fast.AI,
which has become a more standard approach
for many people.
My approach was to use two libraries,
PyTorch and Intel Extension for PyTorch,
also known as IPEX.
I use these because PyTorch is already
Intel XPU optimized.
The oneAPI Deep Neural Network
library or oneDNN,
which is part of the oneAPI library
that Intel has open sourced
is the key
ingredient accelerating PyTorch.
With IPEX
you can do mixed precision training
and quantized inference.
IPEX is an end to end library
that extends PyTorch’s capabilities.
If you install PyTocrch for CPU
or even GPU,
you are already getting Intel
optimizations by default.
Intel has done all the work
and you get all the optimizations
just by installing the standard package.
The reason IPEX exists is, one:
It contains recent optimizations
for XPUs prior
to merging to the PyTorch mainline.
So if you need to test them out
they will be in IPEX.
Two: our future GPUs will be supported
for deep learning with PyTorch
using IPEX.
Using IPEX is extremely easy,
it is 1 to 3 lines of change
to your code base
depending on what
optimizations that you need.
Framework developers
using oneDNN provide us with, One:
improved performance of frameworks
you already use such as PyTorch
and TensorFlow as well as others.
Two: help
developing faster, deep learning
applications and frameworks
when using optimized building blocks.
And three: targeting of applications
optimized for Intel XPUs.
If you are familiar with PyTorch
or deep learning frameworks,
you'll likely have an intuitive
understanding of our implementation.
The overall approach I am using targeted
dinosaur data sets,
but the approach could be used
for other datasets
like forest fire mitigation
based on aerial photos
or satellite images, providing
analysis of road
patterns, foliage density
and weather conditions.
Regulatory compliance of public land
management based on aerial photos,
interplanetary water
exploration based on the classification
of sedimentary structures
on other planets.
We encourage you to explore and share
any additional use cases or examples
you create.
You can find links to resources, tools
and downloads
as well as where you can go to learn more
about everything in this series.
In the description,
remember to like
and share this video
and subscribe
to the Intel Software YouTube channel.
In our next episode
will be looking at OpenVINO Toolkit.
See you then
as our dinosaur
hunting adventure continues.
Let the
adventure begin!