# ROI Pooling

{% hint style="info" %}
_Region of interest pooling explained (_[_deepsense.ai_](https://deepsense.ai/region-of-interest-pooling-explained/?ref=blog.paperspace.com)_)_
{% endhint %}

It's a NN layer taking two inputs:

* A fixed-size feature map from a CNN
* A N x 5 matrix of RoIs. With N = #RoI and 5 =  #bbox coordinates + the image index

### How does it work?

For every RoI, it takes the corresponding section of the feature map and scales it to a pre-defined size (eg 5x5). For it,

<figure><img src="https://569842953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LmjpNbCRLUyGiAxD8kn%2Fuploads%2F8fJoYmBlcKzxuU0xRAJd%2Fimage.png?alt=media&#x26;token=69ed6e2c-50fb-40df-a920-ba151f3ac579" alt=""><figcaption><p>given a RoI proposed</p></figcaption></figure>

<figure><img src="https://569842953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LmjpNbCRLUyGiAxD8kn%2Fuploads%2FYZrJyA3NGZhAq4Zrgy59%2Fimage.png?alt=media&#x26;token=b35cf190-06f6-4192-bc35-00869591d41f" alt="divide the RoI into equal-sized sections " width="375"><figcaption><p>divide the RoI into equal-sized sections</p></figcaption></figure>

<figure><img src="https://569842953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LmjpNbCRLUyGiAxD8kn%2Fuploads%2FlnmNExpVbEav58vzyMkJ%2Fimage.png?alt=media&#x26;token=5a1cf9ea-ce00-4ec7-b744-cc2a4ca148e2" alt=""><figcaption><p>apply max-pooling on each section and append it to the output buffer </p></figcaption></figure>

Note: RoI size does not need to be multiple of the grid size (eg a 7x5 region can be divided into a 2x2)
