List of Operators ↓
The workflow and operators described in this chapter are obsolete and only provided for reasons backward compatibility. New applications should use the workflow and operators described in Deep Learning / Classification.
This chapter explains how to use classification based on deep learning, both for the training and inference phases.
This section describes the main steps and the workflow for classification with Deep Learning using the obsolete workflow.
This part is about how to prepare and preprocess your data.
First, a pretrained network has to be read using the operator
This operator is used as well when you want to read your own trained
networks, after you saved them with
To read the data for your deep learning classification training the procedure
is available. Using this procedure you can get a list of image file paths and their respective labels (the ground truth labels) as well as a list of the unique classes, to which at least one of the listed images belongs.
The network will impose several requirements on the images,
as the image dimensions and the gray value range.
The default values are listed in
. These are
the values with which the networks have been pretrained.
The network architectures allow different image dimensions, which can
be set with
, but depending on the
network a change may make a retraining necessary.
The actually set values can be retrieved with
preprocess_dl_classifier_images provides great
guidance on how to implement such a preprocessing stage.
We recommend to preprocess and store all images used for the training
before starting the classifier training, since this speeds up the
Next, we recommend to split the dataset into three distinct datasets which are used for training, validation, and testing, see the section “Data” in the chapter Deep Learning. This can be achieved using the procedure
You need to specify the
'classes' (determined before by
read_dl_classifier_data_set) you want to differentiate
with your classifier. For this, the operator
This operator can also be used to set hyperparameters, which are
important for training, e.g.,
For a more detailed explanation, see the chapter
Deep Learning and the documentation of
Once your network is set up and your data prepared it is time to train the classifier for your specific task.
Set the hyperparameters used for training with the operator
For an overview of possible hyperparameters, see the documentation of
. Additional explanations can be found
in the chapter Deep Learning.
To train the classifier the operator
is available. The intermediate training results are stored in the output handle.
As the name of
operator processes a batch of data (images and ground truth labels) at
We iterate through our training data in order to train
the classifier successively with
You can repeat this process multiple times and iterate over so many
training epochs until you are satisfied with the training result.
To know how well the classifier learns the new task, the procedure
is provided. With it you can plot the classification errors during training. To compute the input necessary for the visualization, the procedures
are available. With them you can reduce the number of images used for this classification validation, apply the classifier on the selected data and compute, for example, the top-1 error.
Your classifier is trained for your task and ready to be applied. But before deploying in the real world you should evaluate how well the classifier performs on basis of your test data.
To apply the classifier on a set containing an arbitrary number of images, use the operator
The runtime of this operator depends on the number of batches needed for the given image set.
The results are returned in a handle.
To retrieve the predicted classes and confidences, use the operator
Now it is time to evaluate these results. The performance of the
classifier can be evaluated as during the training with
To visualize and analyze the classifier quality, the confusion matrix is a useful tool (see below for an explanation). For this, you can use the procedures
The interactive procedure gives you the possibility to select examples of a specific category, but it does not work with exported code.
Additionally, after applying the classifier on a set of data, you can use the procedure
to display and return images according to certain criteria, e.g., wrongly classified ones. Then, you might want to use this input for the procedure
to display a heatmap of the input image, with which you can analyze which regions of the image are relevant for the classification result.
When your classifier is trained and you are satisfied with its performance, you can use it to classify new images. For this, you simply preprocess your images according to the network requirements (i.e., the same way as you did for your dataset used for training the classifier) and apply the classifier using
We distinguish between data used for training and data for inference. Latter one consists of bare images. But for the former one you already know to which class the images belong and provide this information over the corresponding labels.
The training data is used to train a classifier for your specific task.
With the aid of this data the classifier can learn which classes are to be
distinguished and how their representatives look like.
In classification, the image is classified as a whole.
Therefore, the training data consists of images and their ground truth
labels, thus the class you say this image belongs to.
Note that the images should be as representative as possible for your
There are different possible ways, how to store and retrieve the ground
read_dl_classifier_data_set supports the following
sources of the ground truth label for an image:
The last directory name containing the image
The file name.
For training a classifier, we use a technique called transfer learning (see the chapter Deep Learning). For this, you need less resources, but still a suitable set of data which is generally in the order of hundreds to thousands per class. While in general the network should be more reliable when trained on a larger dataset, the amount of data needed for training also depends on the complexity of the task. You also want enough training data to split it into three subsets, which are preferably independent and identically distributed, see the section “Data” in the chapter Deep Learning.
Regardless of the application,
the network poses requirements on the images regarding the image
dimensions, the gray value range, and the type.
The specific values depend on the network itself and can be queried with
You can find guidance on how to implement such a preprocessing stage
by the procedure