read_dl_classifierT_read_dl_classifierReadDlClassifierReadDlClassifierread_dl_classifier (算子)
名称
read_dl_classifierT_read_dl_classifierReadDlClassifierReadDlClassifierread_dl_classifier — 从文件中读取基于深度学习的分类器。
警告
read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier 已过时,仅出于向后兼容性考虑而保留。 New applications should use the
common CNN-based operator read_dl_modelread_dl_modelReadDlModelReadDlModelReadDlModelread_dl_model。
签名
def read_dl_classifier(file_name: str) -> HHandle
描述
算子 read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier reads a neural network written
by write_dl_classifierwrite_dl_classifierWriteDlClassifierWriteDlClassifierWriteDlClassifierwrite_dl_classifier。As a result, the handle DLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandledlclassifier_handle is returned.
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 dataset. The provided pretrained neural networks are:
- 'pretrained_dl_classifier_compact.hdl'"pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl":
-
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_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_dl_classifier_param。Here we list the default values with
which the classifier has been trained:
'image_width'"image_width""image_width""image_width""image_width""image_width":224
'image_height'"image_height""image_height""image_height""image_height""image_height":224
'image_num_channels'"image_num_channels""image_num_channels""image_num_channels""image_num_channels""image_num_channels":3
'image_range_min'"image_range_min""image_range_min""image_range_min""image_range_min""image_range_min":-127.0
-
'image_range_max'"image_range_max""image_range_max""image_range_max""image_range_max""image_range_max":128.0
This network does not contain any fully connected layer.
The network architecture allows changes concerning the image dimensions,
but requires a minimum 'image_width'"image_width""image_width""image_width""image_width""image_width" and 'image_height'"image_height""image_height""image_height""image_height""image_height"
of 15 pixels.
- 'pretrained_dl_classifier_enhanced.hdl'"pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl":
-
This neural network has more hidden layers than
'pretrained_dl_classifier_compact.hdl'"pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""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_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_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_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_dl_classifier_param。Here we list the default values with
which the classifier has been trained:
'image_width'"image_width""image_width""image_width""image_width""image_width":224
'image_height'"image_height""image_height""image_height""image_height""image_height":224
'image_num_channels'"image_num_channels""image_num_channels""image_num_channels""image_num_channels""image_num_channels":3
'image_range_min'"image_range_min""image_range_min""image_range_min""image_range_min""image_range_min":-127.0
-
'image_range_max'"image_range_max""image_range_max""image_range_max""image_range_max""image_range_max":128.0
The network architecture allows changes concerning the image dimensions,
but requires a minimum 'image_width'"image_width""image_width""image_width""image_width""image_width" and 'image_height'"image_height""image_height""image_height""image_height""image_height"
of 47 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.
- 'pretrained_dl_classifier_resnet18.hdl'"pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl":
-
As the neural network 'pretrained_dl_classifier_enhanced.hdl'"pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl",
this classifier is suited for more complex tasks.
But its structure differs, bringing the advantage of making the training
more stable and being internally more robust. Compared to the neural
network 'pretrained_dl_classifier_resnet50.hdl'"pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl" it is less
complex and has faster inference times.
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_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_dl_classifier_param。Here we list the default values with
which the classifier has been trained:
'image_width'"image_width""image_width""image_width""image_width""image_width":224
'image_height'"image_height""image_height""image_height""image_height""image_height":224
'image_num_channels'"image_num_channels""image_num_channels""image_num_channels""image_num_channels""image_num_channels":3
'image_range_min'"image_range_min""image_range_min""image_range_min""image_range_min""image_range_min":-127.0
-
'image_range_max'"image_range_max""image_range_max""image_range_max""image_range_max""image_range_max":128.0
The network architecture allows changes concerning the image dimensions,
but a minimum 'image_width'"image_width""image_width""image_width""image_width""image_width" and 'image_height'"image_height""image_height""image_height""image_height""image_height"
of 32 pixels is recommended. There is no maximum image size, but large
image sizes will increase the memory demand and the runtime significantly.
Despite the fully connected layer a change of the image size does
not lead to a reinitialization of the weights.
- 'pretrained_dl_classifier_resnet50.hdl'"pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl":
-
As the neural network 'pretrained_dl_classifier_enhanced.hdl'"pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl",
this classifier is suited for more complex tasks.
But its structure differs, bringing the advantage of making the training
more stable and being internally more robust.
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_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_dl_classifier_param。Here we list the default values with
which the classifier has been trained:
'image_width'"image_width""image_width""image_width""image_width""image_width":224
'image_height'"image_height""image_height""image_height""image_height""image_height":224
'image_num_channels'"image_num_channels""image_num_channels""image_num_channels""image_num_channels""image_num_channels":3
'image_range_min'"image_range_min""image_range_min""image_range_min""image_range_min""image_range_min":-127.0
-
'image_range_max'"image_range_max""image_range_max""image_range_max""image_range_max""image_range_max":128.0
The network architecture allows changes concerning the image dimensions,
but a minimum 'image_width'"image_width""image_width""image_width""image_width""image_width" and 'image_height'"image_height""image_height""image_height""image_height""image_height"
of 32 pixels is recommended. There is no maximum image size, but large
image sizes will increase the memory demand and the runtime significantly.
Despite the fully connected layer a change of the image size does
not lead to a reinitialization of the weights.
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_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_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_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_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'"classes""classes""classes""classes""classes" of the classifier have to be
set with set_dl_classifier_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param。
The neural network is loaded from the file FileNameFileNameFileNameFileNamefileNamefile_name.
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'"gpu""gpu""gpu""gpu""gpu" of the
classifier is not read from file. Instead it is initialized with its default
value (see set_dl_classifier_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param).
The default HALCON file extension for deep learning classifiers is
'.hdl'".hdl"".hdl"".hdl"".hdl"".hdl".
有关基于深度学习的分类概念的说明,请参阅 深度学习 / 分类 一章的引言。涉及此遗留算子的工作流在
遗留 / 深度学习分类 一章中有详细说明。
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
此算子返回一个句柄。请注意,即使该句柄被用作特定算子的输入参数,这些算子仍可能改变此句柄类型的实例状态。
参数
FileNameFileNameFileNameFileNamefileNamefile_name (输入控制) filename.read → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
File name.
默认值:
'pretrained_dl_classifier_compact.hdl'
"pretrained_dl_classifier_compact.hdl"
"pretrained_dl_classifier_compact.hdl"
"pretrained_dl_classifier_compact.hdl"
"pretrained_dl_classifier_compact.hdl"
"pretrained_dl_classifier_compact.hdl"
值列表:
'pretrained_dl_classifier_compact.hdl'"pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl""pretrained_dl_classifier_compact.hdl", 'pretrained_dl_classifier_enhanced.hdl'"pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl""pretrained_dl_classifier_enhanced.hdl", 'pretrained_dl_classifier_resnet18.hdl'"pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl""pretrained_dl_classifier_resnet18.hdl", 'pretrained_dl_classifier_resnet50.hdl'"pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl""pretrained_dl_classifier_resnet50.hdl"
File extension:
.hdl
DLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandleDLClassifierHandledlclassifier_handle (输出控制) dl_classifier → HDlClassifier, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
Handle of the deep learning classifier.
结果
If the indicated file is available and the format is correct,
the operator read_dl_classifierread_dl_classifierReadDlClassifierReadDlClassifierReadDlClassifierread_dl_classifier 返回值 2 ( H_MSG_TRUE )。否则将抛出异常。
可能的后继
set_dl_classifier_paramset_dl_classifier_paramSetDlClassifierParamSetDlClassifierParamSetDlClassifierParamset_dl_classifier_param,
get_dl_classifier_paramget_dl_classifier_paramGetDlClassifierParamGetDlClassifierParamGetDlClassifierParamget_dl_classifier_param,
apply_dl_classifierapply_dl_classifierApplyDlClassifierApplyDlClassifierApplyDlClassifierapply_dl_classifier,
train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch
替代
read_dl_modelread_dl_modelReadDlModelReadDlModelReadDlModelread_dl_model,
read_class_mlpread_class_mlpReadClassMlpReadClassMlpReadClassMlpread_class_mlp,
read_class_svmread_class_svmReadClassSvmReadClassSvmReadClassSvmread_class_svm
模块
深度学习推理