"RuntimeError: adaptive_max_pool2d"

Using the example here for my RoI Pooling layer of Faster RCNN, I keep encountering a runtime error: “expected input to have non-empty spatial dimensions, but has sizes [1,512,7,0] with dimension 3 being empty”. I need any guidance i can about how to resolve this error as I can’t find anything helpful about it.
Feature map size: [1,512,28,28]
output size: (7,7)

Where exactly is the error poping up? Can you print the trace out?

image Is this good?

Could you please post the stack trace by wrapping it into three backticks ```?

 File "main.py", line 67, in <module> 
 loss = trainer(image,loc,cls,[128,256,512]) 
 File "C:\Users\abbaahmad\Desktop\Projects\meterR-CNN\myenv\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__ 
 result = self.forward(*input, **kwargs) 
 File "C:\Users\abbaahmad\Desktop\Projects\fasterRCNN\V1\FasterRCNNTrain.py", line 52, in forward 
 sample_roi_index) 
 File "C:\Users\abbaahmad\Desktop\Projects\meterR-CNN\myenv\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__ 
 result = self.forward(*input, **kwargs) 
 File "C:\Users\abbaahmad\Desktop\Projects\fasterRCNN\V1\Faster_RCNNVGG16.py", line 88, in forward 
 self.spatial_scale) 
 File "C:\Users\abbaahmad\Desktop\Projects\fasterRCNN\V1\Faster_RCNNVGG16.py", line 110, in _roi_pooling_2d 
 pool = roi_pooling(x,xy_indices_and_rois,out_size,spatial_scale) 
 File "C:\Users\abbaahmad\Desktop\Projects\fasterRCNN\V1\roipooling.py", line 43, in roi_pooling 
 out = op(im) 
 File "C:\Users\abbaahmad\Desktop\Projects\meterR-CNN\myenv\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__ 
 result = self.forward(*input, **kwargs) 
 File "C:\Users\abbaahmad\Desktop\Projects\meterR-CNN\myenv\lib\site-packages\torch\nn\modules\pooling.py", line 932, in forward 
 return F.adaptive_max_pool2d(input, self.output_size, self.return_indices) 
 File "C:\Users\abbaahmad\Desktop\Projects\meterR-CNN\myenv\lib\site-packages\torch\_jit_internal.py", line 181, in fn 
 return if_false(*args, **kwargs) 
 File "C:\Users\abbaahmad\Desktop\Projects\meterR-CNN\myenv\lib\site-packages\torch\nn\functional.py", line 700, in _adaptive_max_pool2d 
 return adaptive_max_pool2d_with_indices(input, output_size)[0] 
 File "C:\Users\abbaahmad\Desktop\Projects\meterR-CNN\myenv\lib\site-packages\torch\nn\functional.py", line 695, in adaptive_max_pool2d_with_indices 
 return torch._C._nn.adaptive_max_pool2d(input, output_size) 
RuntimeError: adaptive_max_pool2d: expected input to have non-empty spatial dimensions, but input has sizes [1, 512, 0, 0] with dimension 2 being empty ```

Seems like the input to the Average Pooling has zero as its spatial dimensions. Could you print the shape of input to the Average Pooling layer?

Input size is: (1,512,28,28)
Output size: (7,7)

Some layer might decrease the spatial size of the activation, such that it results in an empty tensor.
As @charan_Vjy suggested, print the shape of the input directly before passing it to the adaptive pooling layer.