Main Content


Neural network layer used to output fixed-size feature maps for rectangular ROIs


An ROI max pooling layer outputs fixed size feature maps for every rectangular ROI within the input feature map. Use this layer to create a Fast or Faster R-CNN object detection network.

Given an input feature map of size [H W C N], where C is the number of channels and N is the number of observations, the output feature map size is [height width C sum(M)], where height and width are the output size. M is a vector of length N and M(i) is the number of ROIs associated with the i-th input feature map.

There are two inputs to this layer:

  • 'in' — The input feature map that will be cropped

  • 'roi' — A list of ROIs to pool

Use the input names when connecting or disconnecting the ROI max pooling layer to other layers using connectLayers (Deep Learning Toolbox) or disconnectLayers (Deep Learning Toolbox) (requires Deep Learning Toolbox™).



layer = roiMaxPooling2dLayer(outputSize) creates a max pooling layer for ROIs and sets the OutputSize property.


layer = roiMaxPooling2dLayer(outputSize,'Name',Name) creates a max pooling layer for ROIs and sets the optional Name property. To create a network containing an ROI max pooling layer, you must specify a layer name.


expand all

Pooled output size, specified as a two-element vector of positive integers of the form [height width].

Layer name, specified as a character vector or a string scalar. For Layer array input, the trainnet (Deep Learning Toolbox) and dlnetwork (Deep Learning Toolbox) functions automatically assign names to layers with the name "".

The ROIMaxPooling2DLayer object stores this property as a character vector.

Data Types: char | string

Number of inputs of the layer. This layer has two inputs.

Data Types: double

Input names of the layer. This layer has two inputs, named 'in' and 'roi'.

Data Types: cell

This property is read-only.

Number of outputs from the layer, returned as 1. This layer has a single output only.

Data Types: double

This property is read-only.

Output names, returned as {'out'}. This layer has a single output only.

Data Types: cell


collapse all

Create a dlnetwork object.

net = dlnetwork;

Create an array of layers that includes an ROI input layer and an ROI max pooling layer with output size [4 4]. Add the layers to the network.

outputSize = [4 4];
layers = [
layers = 
  2x1 Layer array with layers:

     1   'roi_input'   ROI Input         M-by-4 rectangular ROIs
     2   'roi_pool'    ROI Max Pooling   ROI Max Pooling with pooled output size [4 4]
net = addLayers(net,layers);

Connect the output of the ROI input layer with the "roi" input of the ROI max pooling layer. Remove the connection between the ROI input layer and the "in" input of the ROI max pooling layer.

net = connectLayers(net,"roi_input","roi_pool/roi");
net = disconnectLayers(net,"roi_input","roi_pool/in");

Version History

Introduced in R2018b