Workflow for multi-label classification🔗
We assume that your dataset is already labeled; see also About data below.
Tip
Take a look at the HDevelop example dl_multi_label_classification_workflow.hdev for an application.
-
Create a multi-label classification model.
The model is created based on a backbone model. The creation can be done with the procedure
create_dl_model_multi_label_classification.
Thereby, a model
DLModelHandleis created, where the backbone serves as feature extractor, to which the necessary layers for the training are added. Generally, it is possible to use any deep learning model as a backbone. However, depending on the complexity, we recommend using one of the classification models.
For more information about the backbone and which one to use, see the procedure documentation ofcreate_dl_model_multi_label_classification.create_dl_model_multi_label_classificationuses a docking layer to attach the necessary layers for multi-label classification to the backbone classifier. The pretrained classifiers provided by HALCON have already specified docking layers. If you use a self-provided classifier as backbone, you have to specify it yourself.After the model has been created, save it using
write_dl_modeland subsequently read it usingread_dl_model. -
Preprocess the data.
-
The information about what is found in which image of your training dataset needs to be transferred. This is done by the procedure
read_dl_dataset_multi_label_classification.
Thereby, a dictionary
DLDatasetis created, 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 About data below and the page Deep learning > HALCON DL model. -
Split the dataset represented by the dictionary
DLDataset. This can be done using the proceduresplit_dl_dataset.
⤷ The resulting split is saved via the key
splitin each sample entry ofDLDataset. -
Now you can preprocess your dataset. For this, you can use the procedure
preprocess_dl_dataset.
In case of custom preprocessing, this procedure offers guidance on the implementation.
To use this procedure, specify the preprocessing parameters as, for example, the image size. Store all the parameters with their values in a dictionary
DLPreprocessParam. To do this, you can use the procedurecreate_dl_preprocess_param.
We recommend saving this dictionary
DLPreprocessParamto have access to the preprocessing parameter values later during the inference phase.
These steps are also shown in the HDevelop example
dl_multi_label_classification_workflow.hdev. -
-
Train the model.
-
Set the training parameters and store them in the dictionary
TrainParam. These parameters include:- Hyperparameters, as described in the deep learning overview page
- Parameters for possible data augmentation (optional)
- Parameters for the evaluation during training
- Parameters for the visualization of training results
- Parameters for serialization
This can be done using the procedure
create_dl_train_param.
-
Train the model. This can be done using the procedure
train_dl_model.
The procedure expects the following:
- Model handle
DLModelHandle - Dictionary with the data information
DLDataset - Dictionary with the training parameter
TrainParam - Information how many epochs the training shall run
If the procedure
train_dl_modelis used, the total loss as well as optional evaluation measures are visualized.
These steps are also shown in the HDevelop example
dl_multi_label_classification_workflow.hdev. -
-
Evaluate the trained model.
-
The evaluation can conveniently be done using the procedure
evaluate_dl_model.
-
The dictionary
EvaluationResultholds the resulting evaluation measures. You can visualize your evaluation results using the proceduredev_display_multi_label_classification_evaluation.
These steps are also shown in the HDevelop example
dl_multi_label_classification_workflow.hdev. -
-
Run inference on new images.
-
Set the parameters as, for example,
'batch_size'using the operator -
Generate a data dictionary
DLSamplefor each image. This can be done using the proceduregen_dl_samples_from_images.
-
Preprocess the images as done for the training. We recommend using the procedure
preprocess_dl_samples.
IF you saved the dictionary
DLPreprocessParamduring 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
'DLResultBatch'.
These steps are also shown in the HDevelop example
dl_multi_label_classification_workflow.hdev. -