Crop_and_resize in PyTorch

Philokey: <p>Hello,</p>
<p>Is there anything like tensorflow’s <a href="https://www.tensorflow.org/api_docs/python/tf/image/crop_and_resize" rel="nofollow noopener">crop_and_resize</a> in torch? I want to use  interpolation instead of roi_pooling.</p>

1114: <p>Maybe you can use <a href="https://github.com/fxia22/stn.pytorch" rel="nofollow noopener">spatial transform layer</a>.</p>

longcw: <p>I ported the crop_and_resize from tensorflow: <a href="https://github.com/longcw/RoIAlign.pytorch" rel="nofollow noopener">https://github.com/longcw/RoIAlign.pytorch</a>.<br>
Hope this is useful for you.</p>

tensorboy1: <p>That RoIAlign worked well. <img src="//discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=5" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

sal: <p>Seriously ???</p>
<p>This is just running C src underneath. And copied from multimodallearnings MRCNN repo. Atleast give original author the credits.</p>
<p>And do not claim to port to pytorch when it is not.</p>

longcw: <p>Seriously??<br>
It was ported from tensorflow source code and I mentioned this everywhere in the readme and here.</p>
<p>I didn’t know what is the multimodallearnings MRCNN repo you mentioned.<br>
And it worked well for pytorch &lt; 0.4. I recommend to use <a href="https://github.com/facebookresearch/maskrcnn-benchmark/tree/master/maskrcnn_benchmark/csrc" rel="nofollow noopener">facebookresearch/maskrcnn-benchmark</a> since the cffi api was changed after pytorch 0.4 and 1.0.<br>
My porting was finished in Dec, 2017 and the maskrcnn_benchmark was starting from Oct, 2018. You can post the repo if you still think I copied any code from there. Your accusation is the biggest insult to a programmer.</p>
<p>And at least, please clarify the facts before posting a comment.</p>

longcw: <p>OK, I found the repo <code>multimodallearning/pytorch-mask-rcnn</code> and actually they are using my code.<br>
This was also mentioned in the <a href="https://github.com/multimodallearning/pytorch-mask-rcnn#installation" rel="noopener nofollow ugc">readme</a></p>
<blockquote>
<p>We use functions from two more repositories that need to be build with the right  <code>--arch</code>  option for cuda support. The two functions are Non-Maximum Suppression from ruotianluo’s <a href="https://github.com/ruotianluo/pytorch-faster-rcnn" rel="noopener nofollow ugc">pytorch-faster-rcnn</a> repository and longcw’s <a href="https://github.com/longcw/RoIAlign.pytorch" rel="noopener nofollow ugc">RoiAlign</a>.</p>
</blockquote>
<p>So this is a misunderstanding, and I am very glad that my code is useful to others.</p>

sal: <p>My bad I apologize. <img src="https://discuss.pytorch.org/images/emoji/apple/sweat_smile.png?v=6" title=":sweat_smile:" class="emoji" alt=":sweat_smile:"><br>
I should have checked the dates.<br>
Yup, sure the code helps.<br>
Is there any implementation more in a “pytorch” way not using C src. ? Say using the functional.interpolate() layer ?</p>
<p>Or could you give an understanding of the geometric transform of how you calculate “y_in”  and “x_in” in the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/crop_and_resize_op.cc#L240" rel="nofollow noopener">loop per box</a> ?</p>
<p>I want to use this for a randomly oriented quadrilateral roi’s, defined as a rotated bounding box, with 8 coordinates as input as opposed to a horizontal box defined by 4 coordinates.</p>

longcw: <p>Check this for the roi pooling of pytorch way: <a href="https://github.com/ruotianluo/pytorch-faster-rcnn/commit/fa88df8c66528afc33cf8f900649504ebbc0335e#diff-69a3170ac05571b54972ad6d8ab782ddL125" rel="nofollow noopener">https://github.com/ruotianluo/pytorch-faster-rcnn/commit/fa88df8c66528afc33cf8f900649504ebbc0335e#diff-69a3170ac05571b54972ad6d8ab782ddL125</a></p>
<p>This repo used <code>F.grid_sample</code> at the first and changed to my <code>crop_and_resize</code> in this commit. Then the newest one used roi_align from <a href="https://github.com/facebookresearch/maskrcnn-benchmark/tree/master/maskrcnn_benchmark/csrc" rel="nofollow noopener">facebookresearch/maskrcnn-benchmark</a></p>

hyesun: <p>Hi, thanks for your great work.<br>
I’ve got one problem. I’ve seen a version of ROI Align, one of whose parameters is the <code>spatial_scale</code>, representing the scale to map the feature coordinate to the original image. For example, if the original image is 224x224 and the feature map is 14x14, then the <code>spatial_scale</code> is 16.<br>
In your version of ROI Align there is no such parameter. So I guess the ROIs being fed to this function should be scaled before hand, e.g., they should be divided by 16 in the example above. Am I right?</p>

viniciusarruda: <p>Hi, I am trying to understand the meaning of the <code>spatial_scale</code> parameter, but the <a href="https://pytorch.org/docs/stable/torchvision/ops.html#torchvision.ops.roi_align" rel="nofollow noopener">documentation</a> is not clear to me.<br>
Reading the <a href="https://github.com/pytorch/vision/blob/e2a8b4185e2b668b50039c91cdcf81eb4175d765/torchvision/csrc/cpu/ROIAlign_cpu.cpp" rel="nofollow noopener">source code</a> the reverse order makes more sense for me, e.g., 14/224 = 0.0625.</p>

yuri: <p>please refer to <a href="https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.functional.resized_crop" class="inline-onebox" rel="noopener nofollow ugc">torchvision.transforms — Torchvision 0.11.0 documentation</a></p>