(upbeat music)
- Hi, I'm Paula, AI Evangelist and Inference Maker at Intel.
Today I'm going to show you how to build
a defect detection application
by using our Edge AI reference kit.
In this particular use case,
we are using a robotic arm and a set of cubes
with the simulation of abnormalities as dark spots.
We have put everything on our OpenVINO GitHub repo.
To help you see how the application is built
and how each step works, we create two Jupyter notebooks.
I will explain briefly those Jupyter notebooks.
The first one is the training part using Anomalib
And the second one is running the inference using OpenVINO
and the robotic arm.
In this video, I will focus on the first notebook.
As you see here,
we have the simulation of production line with defects,
with the robotic arm, the cubes, and the dark spots.
The first step that we need to follow is install Anomalib.
Anomalib is an unsupervised anomaly detection library.
This library is based on PyTorch Lightning
and it has several modules for managing dataset, models,
pre- and post-processing workflows
and also the connection with multiple tools
for benchmarking different state-of-the-art models
for anomaly detection
and also find the best hyper parameter value.
So the first thing that we need to do is
import the packages that we need to use,
using Anomalib API and also PyTorch Lightning.
Then we need to download dataset
and the drivers of the robot.
We have also the dataset.
In this case, we will use the cube's custom dataset
but Anomalib also allows you to use benchmark datasets
such as mb-detect.
Here, we have data module, coming from a custom dataset,
with this folded object,
where we need to define which path we will use,
where the normal images are, where the abnormal images are.
Anomalib is supporting different kind
of computer vision task, such as classification, detection,
segmentation, and video detection.
In this case, we will run this as a classification task.
Also, we need to include that in the data module.
We prepare the data and set up the data module.
The next step is model.
In this particular example, we have selected Padim model.
Padim model doesn't need to use GPU for training.
This is a CPU trainable model,
and for this particular case with 10 images,
it takes around 20 seconds to get the training model.
Remember, Anomalib supports many other unsupervised
anomaly detection models.
So you can see that in the Anomalib repository.
The next step is prepare the callbacks.
To train the model properly,
we need to add some non-essential logic,
such as saving the waves, early stopping,
normalizing the anomaly scores,
and visualizing the input output images.
To achieve this, we use callbacks.
Anomalib has its own callbacks
and also supports PyTorch Lightning native callbacks.
So here you can see that we have callbacks for metrics,
the classification task that we already set up.
We can also see here normalization methods
and that we can export the model in the OpenVINO format.
The next step is training.
Now that we have set up the data module,
the model and the callbacks, we can train the model.
The final component to train the model is PyTorch
Lightning trainer object,
which handles the training, testing, predicting pipelines.
Let's create the trainer object to train the model.
So in this case,
we need to use the callbacks that we already set up.
We need to define where we want to train the model.
So in this case, we will use the CPU,
and we can set up the rest of the configuration
for the trainer and just train the model.
It will take short time with a few normal images.
The next step is the inference with OpenVINO.
With Anomalib, you can run the inference using PyTorch
Onnx Gradio.
But now that we train and test the model,
you could check a single inference result using OpenVINO.
In this case, we need to use OpenVINO inference object
coming from Anomalib.
So here the first thing that we need to do
we need to load a test image.
So you can see here that we have the dark spot
and then we need to verify if we have the OpenVINO model
and also the metadata of the model.
Then we need to call the OpenVINO inferencer
and define where we want to run the inference.
In this case, we will use also the CPU.
Finally, we have the prediction.
This variable is amazing,
because we have a lot of information there.
When we run inferencer that predict
we can have this prediction variable.
In this variable we can see different information,
the original image, the predicted heat map,
the confidence of the prediction.
In this case, we can visualize the inference results
using a classification task, and you can see here
that we have the predicted heat map
and also the confidence of the prediction.
Since predictions contains a number of information,
we could specifically define what we want to visualize.
For example, if we want to visualize the predicted mask
in a segmentation result, we could specifically define
segmentation task and see that predicted mask here.
If you have any questions or things you would like to share
join our discussion channels on OpenVINO GitHub
or our Intel community support channel.
Thanks for watching.
(upbeat music)