Solved by KFrank in post #2 
              
              
                Hi Absurd! 

There are two issues here: 
First, using for-loops generally slows pytorch down because they 
prevent pytorch from performing operations on entire tensors using 
its built in (and hopefully optimized) tensor operations. 
Second, in your method you sum over each rectangular ROI separatel…