Operators |
read_dl_classifier — Read a deep-learning-based classifier from a file.
read_dl_classifier( : : FileName : DLClassifierHandle)
The operator read_dl_classifier reads a neural network written by write_dl_classifier.
HALCON provides pretrained neural networks. These neural networks are good starting points to train a custom classifier for image classification. They have been pretrained on a large image data set. The provided pretrained neural networks are:
This neural network is designed to be memory and runtime efficient.
This classifier expects the images to be of the type 'real' . Additionally, the network is designed for certain image properties. The corresponding values can be retrieved with get_dl_classifier_param. Here we list the default values with which the classifier has been trained:
'image_width': 224
'image_height': 224
'image_num_channels': 3
'image_range_min': -127
'image_range_max': 128
This network does not contain any fully connected layer. The network architecture allows changes concerning the image dimensions, but requires a minimum 'image_width' and 'image_height' of 17 pixels.
This neural network has more hidden layers than 'pretrained_dl_classifier_compact.hdl' and is therefore assumed to be better suited for more complex classification tasks. But this comes at the cost of being more time and memory demanding. As a result, e.g. in comparison to the above compact network, the batch size has to be decreased network during the training, see set_dl_classifier_param.
This classifier expects the images to be of the type 'real' . Additionally, the network is designed for certain image properties. The corresponding values can be retrieved with get_dl_classifier_param. Here we list the default values with which the classifier has been trained:
'image_width': 224
'image_height': 224
'image_num_channels': 3
'image_range_min': -127
'image_range_max': 128
The network architecture allows changes concerning the image dimensions, but requires a minimum 'image_width' and 'image_height' of 223 pixels. There is no maximum image size, but large image sizes will increase the memory demand and the runtime significantly. Changing the image size will reinitialize the weights of the fully connected layers and therefore makes a retraining necessary.
The values listed above are the default image dimensions and gray value range for the networks and these are the values with which the classifiers have been trained. The network architectures allow different image sizes which can be set with set_dl_classifier_param. For networks with at least one fully connected layer such a change makes a retraining necessary. Networks without fully connected layers are directly applicable to different image sizes. However, images with a size differing from the size with which the classifier has been trained are likely to show a reduced classification accuracy.
The actually configured dimensions can be queried by get_dl_classifier_param. Every image that is fed into a network must be present according to the required dimensions. To adjust images accordingly, the procedure preprocess_dl_classifier_images is available.
Typically it is easier, faster and better to retrain a pretrained classifier for a given classification problem. A pretrained classifier has already learned good general purpose features. To retrain the network for a custom problem, the new 'classes' of the classifier have to be set with set_dl_classifier_param (see HDevelop example classify_pill_defects_deep_learning.hdev)
The neural network is loaded from the file FileName. This file is hereby searched in the directory ($HALCONROOT/dl/) as well as in the currently used directory.
Please note that the runtime specific parameter 'gpu' of the classifier is not read from file. Instead it is initialized with its default value (see set_dl_classifier_param).
The default HALCON file extension for deep learning classifiers is '.hdl' .
For an explanation of the concept of deep-learning-based classification see the introduction of chapter Deep Learning / Classification.
This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.
File name.
Default value: 'pretrained_dl_classifier_compact.hdl'
List of values: 'pretrained_dl_classifier_compact.hdl' , 'pretrained_dl_classifier_enhanced.hdl'
File extension: .hdl
Handle of the deep learning classifier.
If the indicated file is available and the format is correct, the operator read_dl_classifier returns the value 2 (H_MSG_TRUE). Otherwise an exception will be raised.
set_dl_classifier_param, get_dl_classifier_param, apply_dl_classifier, train_dl_classifier_batch
read_class_mlp, read_class_svm
Deep Learning Inference
Operators |