create_dl_layer_class_id_conversionT_create_dl_layer_class_id_conversionCreateDlLayerClassIdConversionCreateDlLayerClassIdConversioncreate_dl_layer_class_id_conversion (Operator)

Name

create_dl_layer_class_id_conversionT_create_dl_layer_class_id_conversionCreateDlLayerClassIdConversionCreateDlLayerClassIdConversioncreate_dl_layer_class_id_conversion — Create a class ID conversion layer.

Signature

create_dl_layer_class_id_conversion( : : DLLayerInput, LayerName, ConversionMode, GenParamName, GenParamValue : DLLayerClassIdConversion)

Herror T_create_dl_layer_class_id_conversion(const Htuple DLLayerInput, const Htuple LayerName, const Htuple ConversionMode, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerClassIdConversion)

void CreateDlLayerClassIdConversion(const HTuple& DLLayerInput, const HTuple& LayerName, const HTuple& ConversionMode, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerClassIdConversion)

HDlLayer HDlLayer::CreateDlLayerClassIdConversion(const HString& LayerName, const HString& ConversionMode, const HTuple& GenParamName, const HTuple& GenParamValue) const

HDlLayer HDlLayer::CreateDlLayerClassIdConversion(const HString& LayerName, const HString& ConversionMode, const HString& GenParamName, const HString& GenParamValue) const

HDlLayer HDlLayer::CreateDlLayerClassIdConversion(const char* LayerName, const char* ConversionMode, const char* GenParamName, const char* GenParamValue) const

HDlLayer HDlLayer::CreateDlLayerClassIdConversion(const wchar_t* LayerName, const wchar_t* ConversionMode, const wchar_t* GenParamName, const wchar_t* GenParamValue) const   (Windows only)

static void HOperatorSet.CreateDlLayerClassIdConversion(HTuple DLLayerInput, HTuple layerName, HTuple conversionMode, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerClassIdConversion)

HDlLayer HDlLayer.CreateDlLayerClassIdConversion(string layerName, string conversionMode, HTuple genParamName, HTuple genParamValue)

HDlLayer HDlLayer.CreateDlLayerClassIdConversion(string layerName, string conversionMode, string genParamName, string genParamValue)

def create_dl_layer_class_id_conversion(dllayer_input: HHandle, layer_name: str, conversion_mode: str, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]]) -> HHandle

Description

The operator create_dl_layer_class_id_conversioncreate_dl_layer_class_id_conversionCreateDlLayerClassIdConversionCreateDlLayerClassIdConversionCreateDlLayerClassIdConversioncreate_dl_layer_class_id_conversion creates a class ID conversion layer whose handle is returned in DLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversiondllayer_class_id_conversion. The layer converts between the IDs used internally by the network and the target / output class IDs.

The network internally uses consecutive integer values starting from 0 as IDs (the number of values depends on the model type). In case the target / output class IDs differ from the internal IDs, this layer can be used to convert between them. The target / output class IDs are stored in the model parameter 'class_ids'"class_ids""class_ids""class_ids""class_ids""class_ids" (see get_dl_model_paramget_dl_model_paramGetDlModelParamGetDlModelParamGetDlModelParamget_dl_model_param for more information on this parameter). If no 'class_ids'"class_ids""class_ids""class_ids""class_ids""class_ids" are set, this layer copies the input to the output.

The parameter ConversionModeConversionModeConversionModeConversionModeconversionModeconversion_mode specifies the conversion direction and accepts the following values:

The parameter DLLayerInputDLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input determines the feeding input layer and expects the layer handle as value.

The parameter LayerNameLayerNameLayerNameLayerNamelayerNamelayer_name sets an individual layer name. Note that if creating a model using create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelCreateDlModelcreate_dl_model each layer of the created network must have a unique name.

The following generic parameters GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name and the corresponding values GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value are supported:

'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output""is_inference_output":

Determines whether apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelApplyDlModelapply_dl_model will include the output of this layer in the dictionary DLResultBatchDLResultBatchDLResultBatchDLResultBatchDLResultBatchdlresult_batch even without specifying this layer in OutputsOutputsOutputsOutputsoutputsoutputs ('true'"true""true""true""true""true") or not ('false'"false""false""false""false""false").

Default: 'false'"false""false""false""false""false"

'num_trainable_params'"num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params":

Number of trainable parameters (weights and biases) of the layer.

Certain parameters of layers created using this operator create_dl_layer_class_id_conversioncreate_dl_layer_class_id_conversionCreateDlLayerClassIdConversionCreateDlLayerClassIdConversionCreateDlLayerClassIdConversioncreate_dl_layer_class_id_conversion can be set and retrieved using further operators. The following tables give an overview, which parameters can be set using set_dl_model_layer_paramset_dl_model_layer_paramSetDlModelLayerParamSetDlModelLayerParamSetDlModelLayerParamset_dl_model_layer_param and which ones can be retrieved using get_dl_model_layer_paramget_dl_model_layer_paramGetDlModelLayerParamGetDlModelLayerParamGetDlModelLayerParamget_dl_model_layer_param or get_dl_layer_paramget_dl_layer_paramGetDlLayerParamGetDlLayerParamGetDlLayerParamget_dl_layer_param. Note, the operators set_dl_model_layer_paramset_dl_model_layer_paramSetDlModelLayerParamSetDlModelLayerParamSetDlModelLayerParamset_dl_model_layer_param and get_dl_model_layer_paramget_dl_model_layer_paramGetDlModelLayerParamGetDlModelLayerParamGetDlModelLayerParamget_dl_model_layer_param require a model created by create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelCreateDlModelcreate_dl_model.

Layer Parameters set get
'input_layer'"input_layer""input_layer""input_layer""input_layer""input_layer" (DLLayerInputDLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input)
'name'"name""name""name""name""name" (LayerNameLayerNameLayerNameLayerNamelayerNamelayer_name)
'output_layer'"output_layer""output_layer""output_layer""output_layer""output_layer" (DLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversiondllayer_class_id_conversion)
'shape'"shape""shape""shape""shape""shape"
'to_class_id'"to_class_id""to_class_id""to_class_id""to_class_id""to_class_id" (ConversionModeConversionModeConversionModeConversionModeconversionModeconversion_mode)
'type'"type""type""type""type""type"
Generic Layer Parameters set get
'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output""is_inference_output"
'num_trainable_params'"num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params"

Execution Information

Parameters

DLLayerInputDLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input (input_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Feeding layer.

LayerNameLayerNameLayerNameLayerNamelayerNamelayer_name (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Name of the output layer.

ConversionModeConversionModeConversionModeConversionModeconversionModeconversion_mode (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Direction of the class ID conversion.

Default value: 'from_class_id' "from_class_id" "from_class_id" "from_class_id" "from_class_id" "from_class_id"

List of values: 'from_class_id'"from_class_id""from_class_id""from_class_id""from_class_id""from_class_id", 'to_class_id'"to_class_id""to_class_id""to_class_id""to_class_id""to_class_id"

GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name (input_control)  attribute.name(-array) HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)

Generic input parameter names.

Default value: []

List of values: 'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output""is_inference_output", 'num_trainable_params'"num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params"

GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value (input_control)  attribute.value(-array) HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)

Generic input parameter values.

Default value: []

Suggested values: 'true'"true""true""true""true""true", 'false'"false""false""false""false""false"

DLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversionDLLayerClassIdConversiondllayer_class_id_conversion (output_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Class IDs conversion layer.

Example (HDevelop)

* Example demonstrating the usage of
* create_dl_layer_class_id_conversion.
*
dev_update_off ()
set_system ('seed_rand', 42)
*
* Create simple segmentation model.
NumClasses := 3
InputShape := [32, 32, 3]
*
* Input feeding layers.
create_dl_layer_input ('image', InputShape, [], [], DLLayerInput)
create_dl_layer_input ('target', [InputShape[0],InputShape[1],1], [], [], \
                       DLLayerTarget)
create_dl_layer_class_id_conversion (DLLayerTarget, 'target_internal', \
                                     'from_class_id', [], [], \
                                     DLLayerTargetInternal)
* Feature extraction layers.
create_dl_layer_convolution (DLLayerInput, 'conv1', 3, 1, 1, 32, 1, \
                             'half_kernel_size', 'relu', [], [], \
                             DLLayerConv1)
create_dl_layer_convolution (DLLayerConv1, 'conv2', 3, 1, 1, 32, 1, \
                             'half_kernel_size', 'relu', [], [], \
                             DLLayerConv2)
* Output generation layers.
create_dl_layer_convolution (DLLayerConv2, 'conv_final', 1, 1, 1, \
                             NumClasses, 1, 'none', 'none', [], [], \
                             DLLayerConvFinal)
create_dl_layer_softmax (DLLayerConvFinal, 'softmax', [], [], \
                          DLLayerSoftMax)
create_dl_layer_depth_max (DLLayerSoftMax, 'output_internal', \
                           'argmax', [], [], DLLayerOutputInternal, _)
create_dl_layer_class_id_conversion (DLLayerOutputInternal, 'output', \
                                     'to_class_id', [], [], DLLayerOutput)
* Loss layer.
create_dl_layer_loss_cross_entropy (DLLayerSoftMax, DLLayerTargetInternal, \
                                    [], 'loss', 1.0, [], [], DLLayerLoss)
*
* Create the model.
create_dl_model ([DLLayerOutput, DLLayerLoss], DLModelHandle)
set_dl_model_param (DLModelHandle, 'type', 'segmentation')
set_dl_model_param (DLModelHandle, 'runtime', 'cpu')
*
* Test model on dummy example data.
read_image (Image, 'claudia')
zoom_image_size (Image, Image, InputShape[0], InputShape[1], 'constant')
convert_image_type (Image, Image, 'real')
*
* Fill target image with specific target class IDs.
ClassIDs := [42, 17, 5]
gen_image_const (Target, 'real', InputShape[0], InputShape[1])
paint_region (Target, Target, Target, ClassIDs[0], 'fill')
gen_rectangle1 (RectClass1, 1, 3, 16, 27)
paint_region (RectClass1, Target, Target, ClassIDs[1], 'fill')
gen_rectangle1 (RectClass2, 19, 1, 30, 30)
paint_region (RectClass2, Target, Target, ClassIDs[2], 'fill')
*
* Set class IDs in the model.
set_dl_model_param (DLModelHandle, 'class_ids', ClassIDs)
*
* Create test sample.
create_dict (DLSample)
set_dict_object (Image, DLSample, 'image')
set_dict_object (Target, DLSample, 'target')
*
* Train model for a few iterations. Note that training would not
* work without the first class ID conversion layer 'target_internal'.
for Idx := 1 to 100 by 1
    train_dl_model_batch (DLModelHandle, DLSample, DLTrainResult)
endfor
*
* Apply model on test image. With the second class ID conversion
* layer 'output', the image now contains values according to the
* target IDs in segmentation_image.
apply_dl_model (DLModelHandle, DLSample, [], DLApplyResult)
get_dict_object (SegmentationImage, DLApplyResult, 'output')
dev_display (SegmentationImage)

Module

Deep Learning Training