Skip to content

create_dl_layer_roi_poolingCreateDlLayerRoiPoolingCreateDlLayerRoiPoolingcreate_dl_layer_roi_poolingT_create_dl_layer_roi_poolingπŸ”—

Short descriptionπŸ”—

create_dl_layer_roi_poolingCreateDlLayerRoiPoolingCreateDlLayerRoiPoolingcreate_dl_layer_roi_poolingT_create_dl_layer_roi_pooling β€” Create an ROI pooling layer.

SignatureπŸ”—

create_dl_layer_roi_pooling( dl_layer DLLayerInputImage, dl_layer DLLayerRoI, dl_layer DLLayerFeature, dl_layer DLLayerInstanceIndex, string LayerName, string Type, number GridSize, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer DLLayerRoIPooling )void CreateDlLayerRoiPooling( const HTuple& DLLayerInputImage, const HTuple& DLLayerRoI, const HTuple& DLLayerFeature, const HTuple& DLLayerInstanceIndex, const HTuple& LayerName, const HTuple& Type, const HTuple& GridSize, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerRoIPooling )static void HOperatorSet.CreateDlLayerRoiPooling( HTuple DLLayerInputImage, HTuple DLLayerRoI, HTuple DLLayerFeature, HTuple DLLayerInstanceIndex, HTuple layerName, HTuple type, HTuple gridSize, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerRoIPooling )def create_dl_layer_roi_pooling( dllayer_input_image: HHandle, dllayer_ro_i: HHandle, dllayer_feature: MaybeSequence[HHandle], dllayer_instance_index: HHandle, layer_name: str, type: str, grid_size: Sequence[int], gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> HHandle

Herror T_create_dl_layer_roi_pooling( const Htuple DLLayerInputImage, const Htuple DLLayerRoI, const Htuple DLLayerFeature, const Htuple DLLayerInstanceIndex, const Htuple LayerName, const Htuple Type, const Htuple GridSize, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerRoIPooling )

HDlLayer HDlLayer::CreateDlLayerRoiPooling( const HDlLayer& DLLayerRoI, const HDlLayerArray& DLLayerFeature, const HDlLayer& DLLayerInstanceIndex, const HString& LayerName, const HString& Type, const HTuple& GridSize, const HTuple& GenParamName, const HTuple& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerRoiPooling( const HDlLayer& DLLayerRoI, const HDlLayer& DLLayerFeature, const HDlLayer& DLLayerInstanceIndex, const HString& LayerName, const HString& Type, const HTuple& GridSize, const HString& GenParamName, const HString& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerRoiPooling( const HDlLayer& DLLayerRoI, const HDlLayer& DLLayerFeature, const HDlLayer& DLLayerInstanceIndex, const char* LayerName, const char* Type, const HTuple& GridSize, const char* GenParamName, const char* GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerRoiPooling( const HDlLayer& DLLayerRoI, const HDlLayer& DLLayerFeature, const HDlLayer& DLLayerInstanceIndex, const wchar_t* LayerName, const wchar_t* Type, const HTuple& GridSize, const wchar_t* GenParamName, const wchar_t* GenParamValue ) const (Windows only)

HDlLayer HDlLayer.CreateDlLayerRoiPooling( HDlLayer DLLayerRoI, HDlLayer[] DLLayerFeature, HDlLayer DLLayerInstanceIndex, string layerName, string type, HTuple gridSize, HTuple genParamName, HTuple genParamValue )

HDlLayer HDlLayer.CreateDlLayerRoiPooling( HDlLayer DLLayerRoI, HDlLayer DLLayerFeature, HDlLayer DLLayerInstanceIndex, string layerName, string type, HTuple gridSize, string genParamName, string genParamValue )

DescriptionπŸ”—

The operator create_dl_layer_roi_poolingCreateDlLayerRoiPooling creates a region of interest (ROI) pooling layer whose handle is returned in DLLayerRoIPoolingDLLayerRoIPoolingdllayer_ro_ipooling. Features within the given ROIs are pooled to a fixed output spatial dimension for further processing. The output spatial dimension is given by GridSizegridSizegrid_size.

This layer expects several feeding input layers:

  • DLLayerInputImageDLLayerInputImagedllayer_input_image: Determines the feeding input layer which should contain the network input image. It is used to infer the scales (in terms of width and height) of the feature maps with respect to the input image dimension.

  • DLLayerRoIDLLayerRoIdllayer_ro_i: Determines the feeding input layer containing the coordinates of the ROIs. The ROI-coordinates should be given with respect to the input image and are taken as pixel centered coordinates (see Transformations / 2D Transformations). The shape of a layer is of form [width, height, depth, batch_size], where the fourth value for the batch size is alterable. For this layer this leads to [1, NBP + 2, MNR, 'batch_size'"batch_size"] where MNR is the maximum number of ROIs for one image and NBP is the number of box parameters. NBP depends on the 'instance_type'"instance_type": there are 4 parameters for 'rectangle1'"rectangle1" (row1, column1, row2, column2), and 5 parameters for 'rectangle2'"rectangle2" (row, column, phi, length1, length2) respectively. The second dimension contains next to the NBP rectangle parameters two further values: One for the class and one for the score of each ROI. An ROI is ignored if its class value is negative. If fewer than MNR ROIs are available, the coordinates should all be set to zero. This feeding layer typically is the output of a box proposal layer, see create_dl_layer_box_proposalsCreateDlLayerBoxProposals.

  • DLLayerFeatureDLLayerFeaturedllayer_feature: Determines the feeding input layer containing one or more feature maps to be pooled from. If more than one feature map is given they have to be ordered by decreasing spatial dimensions. For example, if a Feature Pyramid Network (FPN) is used, that means the layers are ordered by increasing FPN-level. Refer to chapter Deep Learning / Instance Segmentation or the reference given below for more detailed information on the FPN and its levels.

  • DLLayerInstanceIndexDLLayerInstanceIndexdllayer_instance_index: Determines the feeding input layer containing for each ROI the index of the ground truth instance with highest IoU. See create_dl_layer_box_targetsCreateDlLayerBoxTargets for further information. This input layer is only used if the generic parameter 'mode'"mode" is set to 'mask_target'"mask_target".

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 ROI pooling operation works as follows. A grid is laid over each ROI and the features within each bin of the grid are pooled. How this is done in detail depends on the Typetypetype:

  • 'roi_pool'"roi_pool": Performs a max-pooling, thus the calculated grid coordinates are rounded to pixel-precise coordinates.

  • 'roi_align'"roi_align": For each sampling point the value is determined by bilinear interpolation of the four neighboring pixel-values. The output value for each grid bin is the average of the sampling point values. The number of uniformly distributed sampling points in each output grid bin is determined by 'sampling_ratio'"sampling_ratio".

The pooled features can for example be used to predict object masks within the given ROIs. In this case it may be useful to pool from a slightly larger ROI to increase the probability that the object is completely contained in the ROI. With the generic parameters 'enlarge_box_factor_long'"enlarge_box_factor_long" and 'enlarge_box_factor_short'"enlarge_box_factor_short" the scaling of the longer and shorter box lengths before pooling can be controlled.

For multiple feature maps, the ROIs will be distributed over the feature maps according to their size by the following formula:

\(level = level_{0} + \lfloor\log(scale/scale_{0} + \epsilon)\rfloor\)

where \(scale\) is the ROI scale, calculated as square root of the ROI area. \(level_{0}\) is the canonical FPN level and \(scale_{0}\) is the canonical FPN scale. The canonical FPN level and scale can be set via the generic parameters 'fpn_roi_canonical_level'"fpn_roi_canonical_level" and 'fpn_roi_canonical_scale'"fpn_roi_canonical_scale" respectively. \(\epsilon\) is added for robustness and set to 1e-61e-6.

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

  • 'enlarge_box_factor_long'"enlarge_box_factor_long": Factor with which the longer side of the box is multiplied before pooling.

    Default: 1.01.0.

  • 'enlarge_box_factor_short'"enlarge_box_factor_short": Factor with which the shorter side of the box is multiplied before pooling.

    Default: 1.01.0.

  • 'fpn_roi_canonical_level'"fpn_roi_canonical_level": FPN-level, the ROIs with the canonical scale are assigned to.

    Default: 44.

  • 'fpn_roi_canonical_scale'"fpn_roi_canonical_scale": ROIs with this scale will be assigned to the canonical level.

    Default: 224224.

  • 'instance_type'"instance_type": Type of RoIs. 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"

  • 'mode'"mode": Mode of the layer. Possible values:

    Default: 'feature'"feature".

  • 'num_classes'"num_classes": The number of classes to be predicted by the model. This parameter is only available for 'mode'"mode" 'mask_target'"mask_target".

    Restriction: If set to a value greater than 1, the mask targets are generated class specifically. This also affects the output shape of the layer, i.e., the depth of the mask targets will be equal to 'num_classes'"num_classes".

    Default: 11.

  • 'sampling_ratio'"sampling_ratio": Number of sampling points distributed over the bin height and width in one grid bin. E.g., for 'sampling_ratio'"sampling_ratio" set to two, there are four sampling points in each grid bin. If set to 00, this number is computed automatically.

    Default: 00.

  • 'threshold_value'"threshold_value": This value sets a threshold between zero and one for the outputs. Set to -1-1 in order to switch thresholding off.

    Restriction: Only available for 'mode'"mode" 'mask_target'"mask_target" and Typetypetype 'roi_align'"roi_align".

    Default: 0.50.5.

Some parameters are not supported by create_dl_layer_roi_poolingCreateDlLayerRoiPooling, since they are computed internally using the input DLLayerFeatureDLLayerFeaturedllayer_feature. These are the following:

  • 'fpn_roi_min_level'"fpn_roi_min_level": Minimum FPN-level used for pooling.

    Restriction: Applies only to 'mode'"mode" 'feature'"feature".

    Default: 00.

  • 'fpn_roi_max_level'"fpn_roi_max_level": Maximum FPN-level used for pooling.

    Restriction: Applies only to 'mode'"mode" 'feature'"feature".

    Default: 00.

Certain parameters of layers created using this operator create_dl_layer_roi_poolingCreateDlLayerRoiPooling 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 Parameters set get
'grid_size'"grid_size" (GridSizegridSizegrid_size) x
'input_layer'"input_layer" (DLLayerInputImageDLLayerInputImagedllayer_input_image, DLLayerRoIDLLayerRoIdllayer_ro_i, DLLayerFeatureDLLayerFeaturedllayer_feature, and/or DLLayerInstanceIndexDLLayerInstanceIndexdllayer_instance_index) x
'name'"name" (LayerNamelayerNamelayer_name) x x
'output_layer'"output_layer" (DLLayerRoIPoolingDLLayerRoIPoolingdllayer_ro_ipooling) x
'shape'"shape" x
'roi_pooling_type'"roi_pooling_type" (Typetypetype) x x
'type'"type" x
Generic Layer Parameters set get
'enlarge_box_factor_long'"enlarge_box_factor_long" x x
'enlarge_box_factor_short'"enlarge_box_factor_short" x x
'fpn_roi_canonical_level'"fpn_roi_canonical_level" x x
'fpn_roi_canonical_scale'"fpn_roi_canonical_scale" x x
'fpn_roi_max_level'"fpn_roi_max_level" x
'fpn_roi_min_level'"fpn_roi_min_level" x
'is_inference_output'"is_inference_output" x x
'instance_type'"instance_type" x
'mode'"mode" x
'num_classes'"num_classes" x
'num_trainable_params'"num_trainable_params" x
'sampling_ratio'"sampling_ratio" x x
'threshold_value'"threshold_value" x 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πŸ”—

DLLayerInputImageDLLayerInputImagedllayer_input_image (input_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Feeding layer containing network input image.

Default: 'InputImageLayer'"InputImageLayer"

DLLayerRoIDLLayerRoIdllayer_ro_i (input_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Feeding layer containing ROI coordinates.

Default: 'RoILayer'"RoILayer"

DLLayerFeatureDLLayerFeaturedllayer_feature (input_control) dl_layer(-array) β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)MaybeSequence[HHandle]Htuple (handle)

Feeding layers containing the features/ground truth instance masks to be pooled from.

Default: 'FeatureLayers'"FeatureLayers"

DLLayerInstanceIndexDLLayerInstanceIndexdllayer_instance_index (input_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Feeding layer containing matched instance indices for each ROI.

Default: 'InstanceIndexLayer'"InstanceIndexLayer"

LayerNamelayerNamelayer_name (input_control) string β†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Name of the output layer.

Typetypetype (input_control) string β†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Type of ROI pooling.

Default: 'roi_pool'"roi_pool"
List of values: 'roi_align', 'roi_pool'"roi_align", "roi_pool"

GridSizegridSizegrid_size (input_control) number-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Spatial dimensions of the pooling grid, output spatial dimensions.

Default: [7, 7][7, 7]

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: 'enlarge_box_factor_long', 'enlarge_box_factor_short', 'fpn_roi_canonical_level', 'fpn_roi_canonical_scale', 'instance_type', 'is_inference_output', 'mode', 'num_classes', 'sampling_ratio', 'threshold_value'"enlarge_box_factor_long", "enlarge_box_factor_short", "fpn_roi_canonical_level", "fpn_roi_canonical_scale", "instance_type", "is_inference_output", "mode", "num_classes", "sampling_ratio", "threshold_value"

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: 'feature', 'mask_target', 'rectangle1', 'rectangle2', 'true', 'false', 0.5"feature", "mask_target", "rectangle1", "rectangle2", "true", "false", 0.5

DLLayerRoIPoolingDLLayerRoIPoolingdllayer_ro_ipooling (output_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

ROI pooling layer.

ExampleπŸ”—

(HDevelop)


* Example for create_dl_layer_roi_pooling.
* This model can be trained to classify multiple
* predefined RoIs in an image.
*
* Create simple model.
create_dl_layer_input ('image', [224,224,3], [], [], DLGraphNodeInput)
create_dl_layer_input ('gt_boxes', [1, 5, 5], [], [], DLGraphNodeGTBoxes)
create_dl_layer_input ('rois', [1, 6, 5], [], [], DLGraphNodeRoIs)
*
* Apply two convolution layer to extract features of the image.
create_dl_layer_convolution (DLGraphNodeInput, 'conv1', 3, 1, 2, 32, 1, \
                             'half_kernel_size', 'relu', [], [], \
                             DLGraphNodeConvolution)
create_dl_layer_convolution (DLGraphNodeConvolution, 'conv2', 3, 1, 2, 32, \
                             1, 'half_kernel_size', 'relu', [], [], \
                             DLGraphNodeConvolution2)
*
* Apply RoI pooling to pool the features for each RoI.
GridSize := [7,7]
create_dl_layer_roi_pooling (DLGraphNodeInput, DLGraphNodeRoIs, \
                             DLGraphNodeConvolution2, [], 'roi_pool', \
                             'roi_pool', GridSize, [], [], \
                             DLGraphNodeRoIPooling)
*
* Classify the RoIs according to the pooled features.
NumClasses := 3
create_dl_layer_dense (DLGraphNodeRoIPooling, 'fc1', 64, [], [], \
                       DLGraphNodeDense)
create_dl_layer_activation (DLGraphNodeDense, 'relu1', 'relu', [], \
                            [], Relu1)
create_dl_layer_dense (Relu1, 'cls_score', NumClasses + 1, [], [], \
                       DLGraphNodeScore)
create_dl_layer_softmax (DLGraphNodeScore, 'cls_prob', [], [], \
                          DLGraphNodeSoftMax)
*
* Append a cross entropy loss to train the classifier.
TargetOutputModes := ['cls_target', 'cls_weight']
TargetOutputNames := TargetOutputModes
create_dl_layer_box_targets (DLGraphNodeRoIs, DLGraphNodeGTBoxes, [], \
                             TargetOutputNames, 'box_proposals', \
                             TargetOutputModes, NumClasses, [], [], \
                             DLGraphNodeClsTarget, DLGraphNodeClsWeight, \
                             _, _, _, _, _)
create_dl_layer_loss_cross_entropy (DLGraphNodeSoftMax, \
                                    DLGraphNodeClsTarget, \
                                    DLGraphNodeClsWeight, 'cls_loss', \
                                    1.0, [], [], \
                                    DLGraphNodeLossCrossEntropy)
*
* Append a box proposal layer to get a detection-like output.
GenParamNameBoxProposal := ['input_mode', 'apply_box_regression', \
                        'max_overlap', 'max_overlap_class_agnostic']
GenParamValueBoxProposal := ['dense', 'false', 1.0, 1.0]
create_dl_layer_box_proposals (DLGraphNodeSoftMax, [], DLGraphNodeRoIs, \
                               DLGraphNodeInput, 'box_output', \
                               GenParamNameBoxProposal, \
                               GenParamValueBoxProposal, \
                               DLGraphNodeGenerateBoxProposals)
*
* Create the model.
create_dl_model ([DLGraphNodeLossCrossEntropy, \
                 DLGraphNodeGenerateBoxProposals], \
                 DLModelHandle)
set_dl_model_param (DLModelHandle, 'type', 'detection')
ClassIDs := [1:NumClasses]
set_dl_model_param (DLModelHandle, 'class_ids', ClassIDs)

ReferencesπŸ”—

Tsung-Yi Lin, Piotr DollΓ r, Ross B. Girshick, Kaiming He, Bharath Hariharan, and Serge J. Belongie, β€œFeature Pyramid Networks for Object Detection,” 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Honolulu, HI, USA, 2017, pp. 936–944, doi: 10.1109/CVPR.2017.106.

ModuleπŸ”—

Deep Learning Professional