I had been trying to implement Precision roi pooling from this repository into my pytorch model. It turned out to be much harder than I anticipated so I ended up not using it. I read somewhere that Precision roi pooling does the same thing as Roi Align if you set the sampling ratio to 0, so I decided to just use that instead.
Now I just found out I can install Precision roi pooling through Open-lab's mmcv. Because of this, I decided to test whether the two Roi poolers are actually the same.
Here is the test code:
from mmcv.ops.prroi_pool import PrRoIPool
from torchvision.ops.roi_align import RoIAlign
import torch
import numpy as np
import config
align = RoIAlign(28, sampling_ratio=0, spatial_scale=1, aligned=False)
prpool = PrRoIPool(28)
features = torch.rand(1,256,800,800).to(config.DEVICE)
box = torch.as_tensor([[0,100,100,400,400]], dtype=torch.float32, device=config.DEVICE)
roi1 = align(features, box)
roi2 = prpool(features, box)
This is the output:
As you can see the outputs are almost the same. Looking at the source code for the Precision roi pooler, I noticed the function has a method called backward and it also calls ctx.save_for_backward() in forward(). Does RoI align in pytorch have a backward method? Are the two poolers actually the same?