This chapter explains the general concept of the deep learning (DL) model in HALCON and the data handling.
By concept, a deep learning model in HALCON is a deep neural network. Each deep neural network has an architecture defining its function, i.e., the tasks it can be used for. There can be several possible network architectures for one functionality. Currently, networks for the following functionalities, also referred to as methods or types, are implemented in HALCON as model:
Anomaly Detection, see Deep Learning / Anomaly Detection.
Classification, see Deep Learning / Classification.
Object detection, see Deep Learning / Object Detection.
Semantic segmentation, see Deep Learning / Semantic Segmentation.
For the implemented methods you can find further information about the specific workflow, data requirements, and validation measures in the corresponding chapters. Information to deep learning in general are given in the chapter Deep Learning.
In this chapter you find the information, which data a DL model needs and returns as well as how this data is transferred.
Independent of the deep learning method used, the
data has to be provided to the model following certain conventions.
As basic concept, the model handles data over dictionaries.
More precisely, the model receives for every input image a dictionary
.
Such a dictionary contains the image and, in case of training and
evaluation, information like e.g., the ground truth annotations.
As output the model returns a dictionary DLSample
with the
results. An illustration is given in the figure below.
DLResult
(1) | (2) |
During training and evaluation, an additional dictionary
serves as a database and collects all the individual
image information dictionaries (stored in the key DLDataset
).
Out of this database the model input dictionaries, samples
,
are created, see the illustration below and the section
“Training and evaluation input data”.
DLSample
Although not necessary for the model itself, the dictionary
is used from the training and evaluation procedures.
Therefore we highly recommend to create a dictionary DLDataset
out of your data.
Its necessary entries are described below.
This dictionary is directly created when labeling your data using the
MVTec Deep Learning Tool.
Alternatively it is created when reading in your data using one of the
following procedures:
DLDataset
read_dl_dataset_anomaly
(anomaly detection)
read_dl_dataset_classification
(classification)
read_dl_dataset_from_coco
(object detection with
'instance_type'
= 'rectangle1'
)
read_dl_dataset_segmentation
(semantic segmentation).
Please see the respective procedure documentation for the requirements on
the data in order to use these procedures.
In case you create
in an other way, it has to
contain at least the entries not marked with a number in the description
below.
During the preprocessing of your dataset the respective procedures include
the further entries of the dictionary DLDataset
.
DLDataset
In the following, we explain the different data and the involved dictionaries. Thereby, the following abbreviations mark for which methods the entry applies:
'Any': any method
'AD': anomaly detection
'CL': classification
'OD': object detection
In case the entry is only applicable for a certain
'instance_type'
,
the specification 'r1': 'rectangle1'
,
'r2': 'rectangle2'
is added
'SE': semantic segmentation
The entries only applicable for certain methods are described more extensively in the corresponding chapter reference.
The dataset consists of images and 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 information about the images and the dataset is
represented in a dictionary
,
which serves as a database.
More precisely, it stores the general information about the dataset and
the dictionaries of the individual samples collected under
DLDataset
.
When the actual image data is needed, a dictionary samples
is created (or read if it already exists) for each image required.
The relation of these dictionaries is illustrated in the figure above.
In the following we will explain these dictionaries with their key/value
pairs in more details.
DLSample
DLDataset
The dictionary
stores general information about the dataset and collects the
dictionaries of the individual samples. Thereby iconic data is not
included in DLDataset
but the paths to the respective
images.
Depending on the model type, this dictionary can have the following
entries:
DLDataset
image_dir
: AnyCommon base path to all images.
format: string
dlsample_dir
: Any [1]Common base path of all sample files (if present).
format: string
class_names
: AnyNames of all classes that are to be distinguished.
format: tuple of strings
class_ids
: AnyIDs of all classes that are to be distinguished (range: 0-65534).
format: tuple of integers
preprocess_param
: Any [1]All parameter values used during preprocessing.
format: dictionary
samples
: AnyCollection of sample descriptions.
format: tuple of dictionaries
class_weights
: SE [1]Weights of the different classes.
format: tuple of reals
anomaly_dir
: ADCommon base path of all anomaly regions (regions indicating anomalies in the image).
format: string
segmentation_dir
: SECommon base path of all segmentation images.
format: string
This dictionary is directly created when labeling your data using the MVTec Deep Learning Tool. It is also created by the procedures mentioned above for reading in your data. The entries marked with [1] are added by the preprocessing procedures.
samples
The
key DLDataset
gets a tuple of
dictionaries as value, one for each sample in the dataset.
These dictionaries contain the information concerning an individual
sample of the dataset.
Depending on the model type, this dictionary can have the following
entries:
samples
image_file_name
: Any
File name of the image and its path relative to
.image_dir
format: string
image_id
: AnyUnique image ID (encoding format: UINT8).
format: integer
split
: Any [2]
Specifies the assigned split subset
('train'
,'validation'
,'test'
).
format: string
dlsample_file_name
: Any [3]
File name of the corresponding dictionary
and its
path relative to DLSample
.dlsample_dir
format: string
anomaly_file_name
: AD
Optional. Path to region files with ground truth annotations
(relative to
).anomaly_dir
format: string
anomaly_label
: AD
Ground truth anomaly label on image level
(in the form of
).class_names
format: string
image_label_id
: CL
Ground truth label for the image (in the form of
).class_ids
format: tuple of integers
bbox_label_id
: OD
Ground truth labels for the bounding boxes
(in the form of
).class_ids
format: tuple of integers
bbox_row1
: OD:r1 [4]Ground truth bounding boxes: upper left corner, row coordinate.
format: tuple of reals
bbox_col1
: OD:r1 [4]Ground truth bounding boxes: upper left corner, column coordinate.
format: tuple of reals
bbox_row2
: OD:r1 [4]Ground truth bounding boxes: lower right corner, row coordinate.
format: tuple of reals
bbox_col2
: OD:r1 [4]Ground truth bounding boxes: lower right corner, column coordinate.
format: tuple of reals
coco_raw_annotations
: OD:r1
Optional. It contains for every
within this
image a dictionary with all raw COCO annotation information.bbox_label_id
format: tuple of dictionaries
bbox_row
: OD:r2 [4]Ground truth bounding boxes: center point, row coordinate.
format: tuple of reals
bbox_col
: OD:r2 [4]Ground truth bounding boxes: center point, column coordinate.
format: tuple of reals
bbox_phi
: OD:r2 [4]Ground truth bounding boxes: angle phi.
format: tuple of reals
bbox_length1
: OD:r2 [4]Ground truth bounding boxes: half length of edge 1.
format: tuple of reals
bbox_length2
: OD:r2 [4]Ground truth bounding boxes: half length of edge 2.
format: tuple of reals
segmentation_file_name
: SE
File name of the ground truth segmentation image and its path relative
to
.segmentation_dir
format: string
These dictionaries are part of
and thus they are
created concurrently.
An exception are the entries with a mark in the table,
[2]: the procedure DLDataset
split_dl_dataset
adds
,
[3]: the procedure split
preprocess_dl_samples
adds
.
[4]: Pixel centered, subpixel accurate coordinates are used.
dlsample_file_name
DLSample
The dictionary
serves as input for the model.
For a batch, they are handed over as the entries of the tuple
DLSample
.
DLSampleBatch
A dictionary
is created out of
DLSample
for every image sample by the procedure
DLDataset
gen_dl_samples
.
It contains all ground truth annotations of an image.
If preprocessing is done using the standard procedure
preprocess_dl_samples
, they are created automatically
therein.
Note, preprocessing steps may lead to an update of the corresponding
dictionary.
DLSample
Depending on the model type,
can have the
following entries:
DLSample
image
: AnyInput image.
format: image
image_id
: Any
Unique image ID (as in
).DLDataset
format: integer
anomaly_ground_truth
: AD
Anomaly image or region, read from
.anomaly_file_name
format: image or region
anomaly_label
: AD
Ground truth anomaly label on image level
(in the form of
).class_names
format: string
anomaly_label_id
: AD
Ground truth anomaly label ID on image level
(in the form of
).class_ids
format: integer
image_label_id
: CL
Ground truth label for the image (in the form of
).class_ids
format: tuple of integers
bbox_label_id
: OD
Ground truth labels for the image part within the bounding box
(in the form of
).class_ids
format: tuple of integers
bbox_row1
: OD:r1 [4]Ground truth bounding boxes: upper left corner, row coordinate.
format: tuple of reals
bbox_col1
: OD:r1 [4]Ground truth bounding boxes: upper left corner, column coordinate.
format: tuple of reals
bbox_row2
: OD:r1 [4]Ground truth bounding boxes: lower right corner, row coordinate.
format: tuple of reals
bbox_col2
: OD:r1 [4]Ground truth bounding boxes: lower right corner, column coordinate.
format: tuple of reals
bbox_row
: OD:r2 [4]Ground truth bounding boxes: center point, row coordinate.
format: tuple of reals
bbox_col
: OD:r2 [4]Ground truth bounding boxes: center point, column coordinate.
format: tuple of reals
bbox_phi
: OD:r2 [4]Ground truth bounding boxes: angle phi.
format: tuple of reals
bbox_length1
: OD:r2 [4]Ground truth bounding boxes: half length of edge 1.
format: tuple of reals
bbox_length2
: OD:r2 [4]Ground truth bounding boxes: half length of edge 2.
format: tuple of reals
segmentation_image
: SE
Image with the ground truth segmentations,
read from
.segmentation_file_name
format: image
weight_image
: SE [5]Image with the pixel weights.
format: image
These dictionaries are created by the procedure
gen_dl_samples
.
An exception is the entry marked in the table above, [5]: created
by the procedure gen_dl_segmentation_weights
.
[4]: Pixel centered, subpixel accurate coordinates are used.
Note, in case these
should be stored, use
the procedure DLSample
write_dl_samples
. You can read them with the
procedure read_dl_samples
.
The inference input data consists of bare images. They have to be provided in a way the model can process them. Concerning the image requirements, find more information in the subsection “Images” below.
The model is set up to hand over all data through a dictionary
.
For the inference, such a dictionary containing only the image can be
created using the procedure DLDataset
gen_dl_samples_from_images
.
These dictionaries can be passed one at a time or within a tuple
.
DLSampleBatch
The training output data is given in the dictionary
.
Its entries depend on the model and thus on the operator used
(for further information see the documentation of the corresponding
operator):
DLTrainResult
The operator
returns
train_dl_model_batch
total_loss
possible further losses included in your model
The operator
returns
train_dl_model_anomaly_dataset
final_error
final_epoch
As output from the operator
, the model will return
a dictionary apply_dl_model
for each sample.
Depending on the model type, this dictionary can have the following
entries:
DLResult
anomaly_image
: ADSingle channel image whose gray values are scores, indicating how likely the corresponding pixel in the input image belongs to an anomaly.
format: image
anomaly_score
: AD
Anomaly score calculated from
.anomaly_image
format: real
classification_class_ids
: CLInferred class ids for the image sorted by confidence values.
format: tuple of integers
classification_class_names
: CLInferred class names for the image sorted by confidence values.
format: tuple of strings
classification_confidences
: CLConfidence values of the image inference for each class.
format: tuple of reals
bbox_class_id
: OD
Inferred class for the bounding box
(in the form of
).class_ids
format: tuple of integers
bbox_confidence
: ODConfidence value of the inference for the bounding box.
format: tuple of reals
bbox_row1
: OD:r1 [6]Inferred bounding boxes: upper left corner, row coordinate.
format: tuple of reals
bbox_col1
: OD:r1 [6]Inferred bounding boxes: upper left corner, column coordinate.
format: tuple of reals
bbox_row2
: OD:r1 [6]Inferred bounding boxes: lower right corner, row coordinate.
format: tuple of reals
bbox_col2
: OD:r1 [6]Inferred bounding boxes: lower right corner, row coordinate.
format: tuple of reals
bbox_row
: OD:r2 [6]Inferred bounding boxes: center point, row coordinate.
format: tuple of reals
bbox_col
: OD:r2 [6]Inferred bounding boxes: center point, column coordinate.
format: tuple of reals
bbox_phi
: OD:r2 [6]Inferred bounding boxes: angle phi.
format: tuple of reals
bbox_length1
: OD:r2 [6]Inferred bounding boxes: half length of edge 1.
format: tuple of reals
bbox_length2
: OD:r2 [6]Inferred bounding boxes: half length of edge 2.
format: tuple of reals
segmentation_image
: SEImage with the segmentation result.
format: image
segmentation_confidence
: SEImage with the confidence values of the segmentation result.
format: image
[6]: Pixel centered, subpixel accurate coordinates are used.
For a further explanation to the output values we refer to the chapters of the respective method, e.g., Deep Learning / Semantic Segmentation.
Regardless of the application, the network poses requirements on the
images. The specific values depend on the network itself and can be
queried using
.
In order to fulfill these requirements, you may have to preprocess your
images.
Standard preprocessing of the entire dataset and therewith also the
images is implemented in get_dl_model_param
preprocess_dl_samples
.
In case of custom preprocessing this procedure offers guidance on the
implementation.
apply_dl_model
clear_dl_model
deserialize_dl_model
gen_dl_model_heatmap
get_dl_model_param
read_dl_model
serialize_dl_model
set_dl_model_param
train_dl_model_batch
write_dl_model