"RuntimeError: adaptive_max_pool2d"

abbaahmad: <p>Using the example <a href="https://discuss.pytorch.org/t/rois-size-problem-of-faster-rcnn-roi-pooling/44068">here</a> 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.<br>
Feature map size: [1,512,28,28]<br>
output size: (7,7)</p>

charan_Vjy: <p>Where exactly is the  error poping up? Can you print the trace out?</p>

abbaahmad: <p><img src="https://discuss.pytorch.org/uploads/default/original/3X/5/9/59b6e7207e5a491bee3de0851a8b0aee0f14842b.png" alt="image" data-base62-sha1="cNEmt3dMhPlPyNBvRqY2JRlhbvl" width="130" height="130"> Is this good?</p>

ptrblck: <p>Could you please post the stack trace by wrapping it into three backticks ```?</p>

abbaahmad: <pre><code class="lang-auto"> File "main.py", line 67, in &lt;module&gt; 
 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 ```</code></pre>

charan_Vjy: <p>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?</p>

abbaahmad: <p>Input size is: (1,512,28,28)<br>
Output size: (7,7)</p>

ptrblck: <p>Some layer might decrease the spatial size of the activation, such that it results in an empty tensor.<br>
As <a class="mention" href="/u/charan_vjy">@charan_Vjy</a> suggested, print the shape of the input directly before passing it to the adaptive pooling layer.</p>