Skip to content

create_dl_layer_anchorsCreateDlLayerAnchorsCreateDlLayerAnchorscreate_dl_layer_anchorsT_create_dl_layer_anchors🔗

Short description🔗

create_dl_layer_anchorsCreateDlLayerAnchorsCreateDlLayerAnchorscreate_dl_layer_anchorsT_create_dl_layer_anchors — Create a layer for generating anchor boxes.

Signature🔗

create_dl_layer_anchors( dl_layer DLLayerInput, dl_layer DLLayerInputImage, string LayerName, number AspectRatios, number NumSubscales, number Angles, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer DLLayerAnchors )void CreateDlLayerAnchors( const HTuple& DLLayerInput, const HTuple& DLLayerInputImage, const HTuple& LayerName, const HTuple& AspectRatios, const HTuple& NumSubscales, const HTuple& Angles, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerAnchors )static void HOperatorSet.CreateDlLayerAnchors( HTuple DLLayerInput, HTuple DLLayerInputImage, HTuple layerName, HTuple aspectRatios, HTuple numSubscales, HTuple angles, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerAnchors )def create_dl_layer_anchors( dllayer_input: HHandle, dllayer_input_image: HHandle, layer_name: str, aspect_ratios: Sequence[Union[float, int]], num_subscales: int, angles: Sequence[Union[float, int]], gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> HHandle

Herror T_create_dl_layer_anchors( const Htuple DLLayerInput, const Htuple DLLayerInputImage, const Htuple LayerName, const Htuple AspectRatios, const Htuple NumSubscales, const Htuple Angles, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerAnchors )

HDlLayer HDlLayer::CreateDlLayerAnchors( const HDlLayer& DLLayerInputImage, const HString& LayerName, const HTuple& AspectRatios, Hlong NumSubscales, const HTuple& Angles, const HTuple& GenParamName, const HTuple& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerAnchors( const HDlLayer& DLLayerInputImage, const HString& LayerName, const HTuple& AspectRatios, Hlong NumSubscales, const HTuple& Angles, const HString& GenParamName, const HString& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerAnchors( const HDlLayer& DLLayerInputImage, const char* LayerName, const HTuple& AspectRatios, Hlong NumSubscales, const HTuple& Angles, const char* GenParamName, const char* GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerAnchors( const HDlLayer& DLLayerInputImage, const wchar_t* LayerName, const HTuple& AspectRatios, Hlong NumSubscales, const HTuple& Angles, const wchar_t* GenParamName, const wchar_t* GenParamValue ) const (Windows only)

HDlLayer HDlLayer.CreateDlLayerAnchors( HDlLayer DLLayerInputImage, string layerName, HTuple aspectRatios, int numSubscales, HTuple angles, HTuple genParamName, HTuple genParamValue )

HDlLayer HDlLayer.CreateDlLayerAnchors( HDlLayer DLLayerInputImage, string layerName, HTuple aspectRatios, int numSubscales, HTuple angles, string genParamName, string genParamValue )

Description🔗

The operator create_dl_layer_anchorsCreateDlLayerAnchors creates a layer for generating anchor boxes whose handle is returned in DLLayerAnchorsDLLayerAnchorsdllayer_anchors. The parameter DLLayerInputDLLayerInputdllayer_input determines the feeding input layer which is used to determine the width and height of the spatial grid, on which the anchors are generated. For example, this could be the last or any intermediate feature layer of a CNN. Usually, when using anchors, the same layer is feeding a classification and box regression branch that are used to determine the class of each anchor and to refine its shape (see also create_dl_layer_box_proposalsCreateDlLayerBoxProposals and create_dl_layer_box_targetsCreateDlLayerBoxTargets).

The parameter DLLayerInputImageDLLayerInputImagedllayer_input_image determines the feeding input layer which is used to determine the scaling factor of the grid and the size of the anchors. Usually, this is the network input image layer. For instance, if the width and height of DLLayerInputDLLayerInputdllayer_input is half the width and height of the DLLayerInputImageDLLayerInputImagedllayer_input_image, the anchor grid and anchor size are scaled by a factor of two. The ratio between the size (width and height) of DLLayerInputImageDLLayerInputImagedllayer_input_image and DLLayerInputDLLayerInputdllayer_input must always be a power of two, for example 1, 2, 4, 8, 16, and so on.

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

The parameter AspectRatiosaspectRatiosaspect_ratios determines the aspect ratios of the anchor boxes (height to width for instance type 'rectangle1'"rectangle1" and length1 to length2 for instance type 'rectangle2'"rectangle2" respectively).

The parameter NumSubscalesnumSubscalesnum_subscales determines the number of different scales at which anchor boxes are generated for each aspect ratio. To determine the anchor scales the base scale of the anchor boxes which is given via the generic parameter 'scale'"scale" is multiplied with each subscale. The subscales are computed as follows

\[\begin{eqnarray*} subscale_{i} = 2^{i/ \textrm{NumSubscales} } \end{eqnarray*}\]

where \(i \in [0, \textrm{NumSubscales}-1]\).

The parameter Anglesanglesangles determines the orientation of the anchor boxes in case of instance type 'rectangle2'"rectangle2". The values must be given in radian. If Anglesanglesangles is an empty tuple, the instance type is implicitly set to 'rectangle1'"rectangle1", if not specified otherwise via the generic parameter 'instance_type'"instance_type". For each point in the anchor grid and each combination of aspect ratio, subscale and angle an anchor box is generated to cover the input image uniformly. Typically, the output layer DLLayerAnchorsDLLayerAnchorsdllayer_anchors is a feeding input layer to a box target and a box proposal layer to build a detection model. Refer to chapter Deep Learning / Instance Segmentation for further information on anchors and the 'instance_type'"instance_type".

The following generic parameters GenParamNamegenParamNamegen_param_name and the corresponding values GenParamValuegenParamValuegen_param_value are supported:

  • 'instance_type'"instance_type": Instance type of anchors. Possible values:

    • 'rectangle1'"rectangle1": axis-aligned rectangles.

    • 'rectangle2'"rectangle2": oriented rectangles.

    Default: 'rectangle1'"rectangle1".

  • 'is_inference_output'"is_inference_output": Determines whether apply_dl_modelApplyDlModel will include the output of this layer in the dictionary DLResultBatchDLResultBatchdlresult_batch even without specifying this layer in Outputsoutputsoutputs ('true'"true") or not ('false'"false").

    Default: 'false'"false"

  • 'scale'"scale": Base scale of the anchor boxes. See the description above for more information.

    Default: 4.04.0

Certain parameters of layers created using this operator create_dl_layer_anchorsCreateDlLayerAnchors can be set and retrieved using further operators. The following tables give an overview, which parameters can be set using set_dl_model_layer_paramSetDlModelLayerParam and which ones can be retrieved using get_dl_model_layer_paramGetDlModelLayerParam or get_dl_layer_paramGetDlLayerParam. Note, the operators set_dl_model_layer_paramSetDlModelLayerParam and get_dl_model_layer_paramGetDlModelLayerParam require a model created by create_dl_modelCreateDlModel.

Layer Internal Parameters set get
'anchor_angles'"anchor_angles" (Anglesanglesangles) x
'anchor_aspect_ratios'"anchor_aspect_ratios" (AspectRatiosaspectRatiosaspect_ratios) x
'anchor_num_subscales'"anchor_num_subscales" (NumSubscalesnumSubscalesnum_subscales) x
'input_layer'"input_layer" (DLLayerInputDLLayerInputdllayer_input) x
'name'"name" (LayerNamelayerNamelayer_name) x x
'output_layer'"output_layer" (DLLayerAnchorsDLLayerAnchorsdllayer_anchors) x
'shape'"shape" x
'type'"type" x
Generic Layer Parameters set get
'instance_type'"instance_type" x
'is_inference_output'"is_inference_output" x x
'num_trainable_params'"num_trainable_params" x
'scale'"scale" x

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

DLLayerInputDLLayerInputdllayer_input (input_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Feeding layer to determine anchor grid size.

DLLayerInputImageDLLayerInputImagedllayer_input_image (input_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Feeding layer to determine the grid scale and anchor sizes.

LayerNamelayerNamelayer_name (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Name of the output layer.

AspectRatiosaspectRatiosaspect_ratios (input_control) number-array → (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Sequence[Union[float, int]]Htuple (double / Hlong)

Anchor aspect ratios.

Default: [0.5, 1.0, 2.0][0.5, 1.0, 2.0]

NumSubscalesnumSubscalesnum_subscales (input_control) number → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Number of anchor subscales.

Default: 33
Restriction: NumSubscales > 0

Anglesanglesangles (input_control) number-array → (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Sequence[Union[float, int]]Htuple (double / Hlong)

Anchor orientations.

Default: [][]

GenParamNamegenParamNamegen_param_name (input_control) attribute.name(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Generic input parameter names.

Default: [][]
List of values: 'instance_type', 'is_inference_output', 'scale'"instance_type", "is_inference_output", "scale"

GenParamValuegenParamValuegen_param_value (input_control) attribute.value(-array) → (string / integer / real)HTuple (HString / Hlong / double)HTuple (string / int / long / double)MaybeSequence[Union[int, float, str]]Htuple (char* / Hlong / double)

Generic input parameter values.

Default: [][]
Suggested values: 'rectangle1', 'rectangle2', 'true', 'false'"rectangle1", "rectangle2", "true", "false"

DLLayerAnchorsDLLayerAnchorsdllayer_anchors (output_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Anchors layer.

Example🔗

(HDevelop)

* Minimal example for the usage of layers
*  - create_dl_layer_anchors
*  - create_dl_layer_box_proposals
*  - create_dl_layer_box_targets
* for creating a model to perform object detection.
*
* Define the input image layer.
create_dl_layer_input ('image', [224,224,3], [], [], DLLayerInputImage)
* Define the input ground truth box layers.
create_dl_layer_input ('bbox_row1', [1, 1, 10], ['allow_smaller_tuple'], \
                       ['true'], DLLayerInputRow1)
create_dl_layer_input ('bbox_row2', [1, 1, 10], ['allow_smaller_tuple'], \
                       ['true'], DLLayerInputRow2)
create_dl_layer_input ('bbox_col1', [1, 1, 10], ['allow_smaller_tuple'], \
                       ['true'], DLLayerInputCol1)
create_dl_layer_input ('bbox_col2', [1, 1, 10], ['allow_smaller_tuple'], \
                       ['true'], DLLayerInputCol2)
create_dl_layer_input ('bbox_label_id', [1, 1, 10], \
                       ['allow_smaller_tuple'], ['true'], \
                       DLLayerInputLabelID)
* Concatenate all box coordinates.
create_dl_layer_concat ([DLLayerInputRow1, DLLayerInputCol1, \
                        DLLayerInputRow2, DLLayerInputCol2, \
                        DLLayerInputLabelID], 'gt_boxes', \
                        'height', [], [], DLLayerGTBoxes)
*
* Perform some operations on the input image to extract features.
create_dl_layer_convolution (DLLayerInputImage, 'conv', 3, 1, 1, 32, 1, \
                             'half_kernel_size', 'relu', [], [], \
                             DLLayerConvolution)
create_dl_layer_pooling (DLLayerConvolution, 'pool', 2, 2, 'none', \
                         'maximum', [], [], DLLayerPooling)
*
* Create the anchor boxes.
create_dl_layer_anchors (DLLayerPooling, DLLayerInputImage, 'anchor', \
                         [0.5,1.0,2.0], 3, [], [], [], DLLayerAnchors)
*
* Generate the class and box regression targets for the anchors
* according to the ground truth boxes.
Targets := ['cls_target', 'box_target']
NumClasses := 3
create_dl_layer_box_targets (DLLayerAnchors, DLLayerGTBoxes, [], \
                             Targets, 'anchors', Targets, NumClasses, \
                             [], [], DLLayerClassTarget, _, \
                             DLLayerBoxTarget, _, _, _, _)
*
* For this example, we treat the targets as predictions and
* apply them directly to the anchors to get the ground truth
* boxes as output.
create_dl_layer_box_proposals (DLLayerClassTarget, DLLayerBoxTarget, \
                               DLLayerAnchors, DLLayerInputImage, \
                               'box_proposals', [], [], \
                               DLLayerBoxProposals)
*
* Create the model.
OutputLayers := DLLayerBoxProposals
create_dl_model (OutputLayers, DLModelHandle)
*
* Prepare the model for using it as a detection model.
set_dl_model_param (DLModelHandle, 'type', 'detection')
ClassIDs := [0,1,2]
set_dl_model_param (DLModelHandle, 'class_ids', ClassIDs)
*
* Create a sample.
create_dict (DLSample)
gen_image_const (Image, 'real', 224, 224)
gen_circle (Circle, [50., 100.], [50., 120.], [20., 30.])
overpaint_region (Image, Circle, 255, 'fill')
compose3 (Image, Image, Image, Image)
set_dict_object (Image, DLSample, 'image')
smallest_rectangle1 (Circle, Row1, Col1, Row2, Col2)
set_dict_tuple (DLSample, 'bbox_row1', Row1)
set_dict_tuple (DLSample, 'bbox_row2', Row2)
set_dict_tuple (DLSample, 'bbox_col1', Col1)
set_dict_tuple (DLSample, 'bbox_col2', Col2)
set_dict_tuple (DLSample, 'bbox_label_id', [1,2])
*
* Apply the detection model.
apply_dl_model (DLModelHandle, DLSample, [], DLResult)
*
* Display ground truth and result.
create_dict (DLDatasetInfo)
set_dict_tuple (DLDatasetInfo, 'class_ids', ClassIDs)
set_dict_tuple (DLDatasetInfo, 'class_names', \
                ['class_0', 'class_1', 'class_2'])
create_dict (WindowHandleDict)
dev_display_dl_data (DLSample, DLResult, DLDatasetInfo, \
                     ['image', 'bbox_ground_truth', 'bbox_result'], \
                     [], WindowHandleDict)
stop ()
dev_close_window_dict (WindowHandleDict)

Combinations with other operators🔗

Combinations

Possible successors

create_dl_layer_box_targetsCreateDlLayerBoxTargets, create_dl_layer_box_proposalsCreateDlLayerBoxProposals

Module🔗

Deep Learning Professional