List of Operators ↓
This chapter explains how to use anomaly detection based on deep learning.
With anomaly detection we want to detect whether or not an image contains anomalies. An anomaly means something deviating from the norm, something unknown.
An anomaly detection model learns common features of images without anomalies. The trained model will infer, how likely an input image contains only learned features or if the image contains something different. Latter one is interpreted as an anomaly. This inference result is returned as a gray value image. The pixel values therein indicate how likely the corresponding pixels in the input image pixels show an anomaly.
In this paragraph, we describe the general workflow for an anomaly detection task based on deep learning.
This part is about how to preprocess your data.
The information content of your dataset needs to be converted. This is done by the procedure
It creates a dictionary
DLDataset which serves as
a database and stores all necessary information about your data.
For more information about the data and the way it is transferred, see
the section “Data” below and the chapter
Deep Learning / Model.
Split the dataset represented by the dictionary
DLDataset. This can be done using the procedure
The network imposes several requirements on the images. These requirements (for example the image size and gray value range) can be retrieved with
For this you need to read the model first by using
Now you can preprocess your dataset. For this, you can use the procedure
In case of custom preprocessing, this procedure offers guidance on the implementation.
To use this procedure, specify the preprocessing parameters as, e.g.,
the image size.
Store all the parameter with their values in a dictionary
DLPreprocessParam, for which you can use the procedure
We recommend to save this dictionary
order to have access to the preprocessing parameter values later
during the inference phase.
This part explains how to train a DL anomaly detection model.
Set the training parameters and store them in the dictionary
This can be done using the procedure
Train the model. This can be done using the procedure
The procedure expects:
the model handle
DLDataset containing the data
TrainParam containing the training
In this part, we evaluate the anomaly detection model.
Set the model parameters which may influence the evaluation.
The evaluation can be done conveniently using the procedure
This procedure expects a dictionary
GenParamEval with the
EvaluationResults holds the desired
This part covers the application of a DL anomaly detection model. For a trained model, perform the following steps:
Request the requirements the model imposes on the images using the operator
or the procedure
Set the model parameter described in the section “Model Parameters” below, using the operator
Generate a data dictionary
DLSample for each image.
This can be done using the procedure
Every image has to be preprocessed the same way as for the training. For this, you can use the procedure
When you saved the dictionary
the preprocessing step, you can directly use it as input to specify
all parameter values.
Apply the model using the operator
Retrieve the results from the dictionary
We distinguish between data used for training, evaluation, and inference on new images.
As a basic concept, the model handles data by dictionaries, meaning it
receives the input data from a dictionary
DLSample and returns
More information on the data handling can be found in the chapter
Deep Learning / Model.
In anomaly detection there are exactly two classes:
'ok', meaning without anomaly, class ID 0.
'nok', meaning with anomaly, class ID 1
(on pixel values an ID >0, see the subsection
“Data for evaluation” below).
These classes apply to the whole image as well as single pixels.
This dataset consists only of images without anomalies and the corresponding information. They have to be provided in a way the model can process them. Concerning the image requirements, find more information in the section “Images” below.
The training data is used to train a model for your specific task. With the aid of this data the model can learn which features the images without anomalies have in common.
This dataset should include images without anomalies but it can also
contain images with anomalies.
Every image within this set needs a ground truth label
specifying the class of the image (see the section above).
This indicates if the image shows an anomaly (
or not (
Evaluating the model performance on finding anomalies can visually
also be done on pixel level if an image
included in the
In this image
anomaly_file_name every pixel indicates the
class ID, thus if the corresponding pixel in the input image shows an
anomaly (pixel value > 0) or not (pixel value equal to 0).
The model poses requirements on the images, such as the dimensions,
the gray value range, and the type.
The specific values depend on the model itself. See the documentation
for the specific values of different models.
For a read model they can be queried with
In order to fulfill these requirements, you may have to preprocess your
Standard preprocessing of an entire sample, including the
image, is implemented in
In case of custom preprocessing these procedure offers guidance on the
As training output, the operator
will return a dictionary
with the best obtained
error received during training and the epoch in which this error was
As inference and evaluation output, the model will return a dictionary
for every sample. For anomaly detection, this
dictionary includes the following extra entries:
anomaly_score: A score indicating how likely the entire
image is to contain an anomaly.
This score is based on the pixel scores given in
An image, where the value of each pixel indicates how likely its
corresponding pixel in the input image shows an anomaly
(see the illustration below).
The values are .