Using Polygons instead of Boxes

Ian_Coetzer: <p>Hi</p>
<p>How do I load data into a standard PyTorch Dataset, specifying labels with corresponding points representing polygon regions, instead of simple xmin,xmax,ymin,ymax boxes?</p>

nwn: <p>Hello Ian,<br>
pls specify your question and tell us what you want to do, so that we can understand what you mean.</p>

Ian_Coetzer: <p>Hi Luis</p>
<p>Thank you for the reply.<br>
I have since written a script to ‘cut-out’ images - based on polygon points into standard to rectangles which I then load into a dataset. Therefore, I did not have to adapt the dataset, instead the bounding box is now the full size of the image 0,0,width,height.</p>
<p>Example of images that have been ‘cut-out’</p>
<p>However, my ML model performs poorly - I am still learning how to ues these im<br>
ages properly, also not sure if I should use those with a black or white background or not.</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/d/bdf6a6d621e37c3764c84f31982d9eef289fcf3d.jpeg" alt="Formal_4_9_CROPPED" data-base62-sha1="r6uGPgmuojKWiTN2YR4OrRnAeeN" width="90" height="64"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/7/1/71a80cdebb3606d9314c2556685199dfd781c389.jpeg" alt="Formal_4_9_MASK" data-base62-sha1="gds00OogMK86QDhmxhEu08NhgMx" width="90" height="64"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/7/4/74a182ed39e9b91a133eb6d734f8cc9cd6c5ff37.jpeg" alt="Formal_4_9_MASK_ONLY" data-base62-sha1="gDLqeR8NNFuUrZNEFAMgA3dHYBV" width="90" height="64"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/8/d/8d53dc9680fb719134bac7591c1d459678f5f900.jpeg" alt="Formal_4_9_MASK_White_BG" data-base62-sha1="kaeZL94pHSYlCwhrLzrwbW2JG0w" width="90" height="64"></p>

Ian_Coetzer: <aside class="quote no-group" data-username="Ian_Coetzer" data-post="3" data-topic="168227">
<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/ian_coetzer/48/55590_2.png" class="avatar"> Ian_Coetzer:</div>
<blockquote>
<p>a script to ‘cut-out’ images - based on polygon points into standard to rectangle</p>
</blockquote>
</aside>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/0/3/03a695e8c0bc42475a66368e93ea1c6c8c674684.jpeg" alt="Formal_2_4_CROPPED" data-base62-sha1="wil6pe7QfTpzz8G2g8EiOWFPBG" width="90" height="64"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/d/4/d44f301aefec1de8c45103986a0df00df000bb12.jpeg" alt="Formal_2_4_MASK" data-base62-sha1="uiaSKs2O5XpqUwcbJtrvt4bphjc" width="90" height="64"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/9/5/95abf1e82fa7a39978c3465624cfd301ff412689.jpeg" alt="Formal_2_4_MASK_ONLY" data-base62-sha1="lm3x4ApqQC242RgyUUqmAfzDH3b" width="90" height="64"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/8/a/8a1eda5689a6e34e42092df4b6c79757b825cf23.jpeg" alt="Formal_2_4_MASK_White_BG" data-base62-sha1="jHRZyMmAS9uMmC322QNzK34Xdon" width="90" height="64"></p>

edgarriba: <p>For four point defined polygons you can use Kornia <a href="https://kornia.readthedocs.io/en/latest/geometry.transform.html#kornia.geometry.transform.warp_perspective" rel="noopener nofollow ugc">warp_perspective</a></p>
<p>Tutorial here: <a href="https://kornia-tutorials.readthedocs.io/en/latest/warp_perspective.html" class="inline-onebox" rel="noopener nofollow ugc">Warp image using perspective transform - Kornia Tutorials documentation</a></p>