How to get the same RandomResizedCrop result of img and gt

haoran-hash: <p>my code snippet is below<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/b/5be9873152b3d0866495842d0ca68322a7f06080.png" data-download-href="https://discuss.pytorch.org/uploads/default/5be9873152b3d0866495842d0ca68322a7f06080" title="TIM图片20210919214656"><img src="https://discuss.pytorch.org/uploads/default/original/3X/5/b/5be9873152b3d0866495842d0ca68322a7f06080.png" alt="TIM图片20210919214656" data-base62-sha1="d75MrTmY2Mq5jkLIVV8lZ995X6o" width="690" height="76" data-dominant-color="EFEFF0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">TIM图片20210919214656</span><span class="informations">1466×162 11.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/5/75a2010a5356321df886c8350058b2eebb84bd8b.png" data-download-href="https://discuss.pytorch.org/uploads/default/75a2010a5356321df886c8350058b2eebb84bd8b" title="TIM图片20210919214702"><img src="https://discuss.pytorch.org/uploads/default/original/3X/7/5/75a2010a5356321df886c8350058b2eebb84bd8b.png" alt="TIM图片20210919214702" data-base62-sha1="gMCXhqX3IEUL7OVJ6vPmH79NTEn" width="690" height="449" data-dominant-color="CCD4D4"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">TIM图片20210919214702</span><span class="informations">862×561 28.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
Now ,the img ,gt do different RandomResizedCrop. But I want they do the same, because the img and gt must be correspond.<br>
How should I modify the code?</p>

arya47: <p>This thread might be relevant</p><aside class="quote" data-post="1" data-topic="10606">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zeakey/48/4341_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/torchvision-transfors-how-to-perform-identical-transform-on-both-image-and-target/10606">Torchvision.transfors: How to perform identical transform on both image and target?</a> <a class="badge-category__wrapper " href="/c/vision/5"><span data-category-id="5" data-drop-close="true" class="badge-category " title="Topics related to either pytorch/vision or vision research related topics"><span class="badge-category__name">vision</span></span></a>
  </div>
  <blockquote>
    How can I perform an identical transform on both image and target? 
For example, in Semantic segmentation and Edge detection where the input image and target ground-truth are both 2D images, one must perform the same transform on both input image and target ground-truth.
  </blockquote>
</aside>


haoran-hash: <blockquote>
<p><a href="https://discuss.pytorch.org/t/torchvision-transfors-how-to-perform-identical-transform-on-both-image-and-target/10606">https://discuss.pytorch.org/t/torchvision-transfors-how-to-perform-identical-transform-on-both-image-and-target/10606</a></p>
</blockquote>
<p>Read the topic above, and then read some Github issues. Now, I think the best solution is to write own transform(take both image and target as arguments).<br>
For example, my initial question can be solved as below.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/8/a899542b62b1c3c98c678673a8ebdf935c3b6118.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/a899542b62b1c3c98c678673a8ebdf935c3b6118" title="屏幕截图 2021-09-22 153812"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a899542b62b1c3c98c678673a8ebdf935c3b6118_2_690x205.jpeg" alt="屏幕截图 2021-09-22 153812" data-base62-sha1="o3uIFoArCTJ4jCGzY0GPsf8ZydO" width="690" height="205" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a899542b62b1c3c98c678673a8ebdf935c3b6118_2_690x205.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a899542b62b1c3c98c678673a8ebdf935c3b6118_2_1035x307.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/a/8/a899542b62b1c3c98c678673a8ebdf935c3b6118.jpeg 2x" data-dominant-color="EEEFF0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">屏幕截图 2021-09-22 153812</span><span class="informations">1170×349 68 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/c/3c4bb5862723091c4d457d3ad69d0195ad92605b.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/3c4bb5862723091c4d457d3ad69d0195ad92605b" title="屏幕截图 2021-09-22 153830"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/c/3c4bb5862723091c4d457d3ad69d0195ad92605b_2_690x56.jpeg" alt="屏幕截图 2021-09-22 153830" data-base62-sha1="8BoQXsMmajwEVfFkO7qBzOAau83" width="690" height="56" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/c/3c4bb5862723091c4d457d3ad69d0195ad92605b_2_690x56.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/3/c/3c4bb5862723091c4d457d3ad69d0195ad92605b_2_1035x84.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/c/3c4bb5862723091c4d457d3ad69d0195ad92605b.jpeg 2x" data-dominant-color="EFEEEF"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">屏幕截图 2021-09-22 153830</span><span class="informations">1302×106 22.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/8/a8979c0a85d0752745446264447bf300cbff3b0b.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/a8979c0a85d0752745446264447bf300cbff3b0b" title="屏幕截图 2021-09-22 153844"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a8979c0a85d0752745446264447bf300cbff3b0b_2_690x466.jpeg" alt="屏幕截图 2021-09-22 153844" data-base62-sha1="o3r2i6lAZuyzfd6e4Vmqo7BzJRF" width="690" height="466" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/8/a8979c0a85d0752745446264447bf300cbff3b0b_2_690x466.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/a/8/a8979c0a85d0752745446264447bf300cbff3b0b.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/a/8/a8979c0a85d0752745446264447bf300cbff3b0b.jpeg 2x" data-dominant-color="CED0D3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">屏幕截图 2021-09-22 153844</span><span class="informations">822×556 42.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Now, the transform result of image and target are same. Here, mainly use <code>torchvision.Transform.get_params()</code> and <code>torchvision.transforms.functional.xxx</code>.</p>
<p>The Github Issue link mentioned above: <a href="https://github.com/pytorch/vision/issues/230" rel="noopener nofollow ugc">https://github.com/pytorch/vision/issues/230</a>.<br>
If you want convenience, you can <code>git clone</code> <a href="https://github.com/pytorch/vision/blob/main/references/segmentation/transforms.py" rel="noopener nofollow ugc">https://github.com/pytorch/vision/blob/main/references/segmentation/transforms.py</a> to your workspace.(My solution is also mimic him)</p>