Polygon Intersection

username: DerekGloudemans
cooked: <p>Anyone know how to calculate the area of intersection between two (convex) polygons in a differentiable manner so it can be used as a loss function for backpropogation? This is a fairly obvious extension of rectangular bounding box intersection-over-union as a loss function but I haven’t seen anyone do it yet. You could imagine scenarios in which you are attempting to identify a rectangular face of an object within an image; if the object is at an angle the rectangle will be a skewed and become some other quadrilateral. Just thought I’d ask before I attempt it myself.</p>

username: aeffting
cooked: <p>Hello Derek, did you find anyone who implemented this? I’ve had the same thoughts, it would be interesting to test backpropagation with this.</p>

username: DerekGloudemans
cooked: <p>Hey no I never found a good implementation for this. One way you could potentially do it is with a sort of rasterized computation (i.e. define some grid and figure out which grid cells each polygon covers). This would be an approximate method but depending on coarseness of grid could be accurate enough probably. Don’t know if the large number of values in the raster grid would create issues for backpropogation wrt vanishing gradient but I’d guess it would probably work decent with a large enough batch size to smooth things out.</p>

username: DerekGloudemans
cooked: <p>If you do implement something you should post it; would be very interested to see !</p>

username: Anatolii_Korol
cooked: <p>Any updates on this?</p>

username: DerekGloudemans
cooked: <p>No, I’d recommend the rasterized approach. I’d assume that would work pretty well when smoothed out over a relatively fine grid. This would be fairly similar to the loss function used for segmentation I think.</p>

username: DerekGloudemans
cooked: <p>If you were interested in this thread, I managed to implement a differentiable Polygon IOU function and use it to optimize corner points in some trivial toy examples.</p>

username: ywyue
cooked: <p>Hi, very interested in your implementation. Have you already open-sourced it somewhere?</p>

username: DerekGloudemans
cooked: <p>The code for this isn’t made public yet, as I’m trying to submit it for publication later this year. I hope to have a preprint posted within a month or so and will be sure to make the codebase public then</p>

username: ywyue
cooked: <p>Thanks, very much looking forward to that! Could you please post the link here then?</p>

username: caspervanengelenburg
cooked: <p>Yes, I would be very interested in this as well :). Please let us know if you have the link!!</p>

username: DerekGloudemans
cooked: <p>Here’s the arxiv: paper was rejected and I never had the time/effort to resubmit</p><aside class="onebox pdf" data-onebox-src="https://arxiv.org/pdf/2309.07104.pdf">
  <header class="source">

      <a href="https://arxiv.org/pdf/2309.07104.pdf" target="_blank" rel="noopener nofollow ugc">arxiv.org</a>
  </header>

  <article class="onebox-body">
    <a href="https://arxiv.org/pdf/2309.07104.pdf" target="_blank" rel="noopener nofollow ugc"><span class="pdf-onebox-logo"></span></a>

<h3><a href="https://arxiv.org/pdf/2309.07104.pdf" target="_blank" rel="noopener nofollow ugc">2309.07104.pdf</a></h3>

  <p class="filesize">8.53 MB</p>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>And here’s the code:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/Randdl/polygon_iou_loss">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/Randdl/polygon_iou_loss" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/344;"><img src="https://opengraph.githubassets.com/4f7bfbbb64ab8652f40c038b1d170ea4e207844db4707b0ca8bf17c5b070e763/Randdl/polygon_iou_loss" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/Randdl/polygon_iou_loss" target="_blank" rel="noopener nofollow ugc">GitHub - Randdl/polygon_iou_loss</a></h3>

  <p>Contribute to Randdl/polygon_iou_loss development by creating an account on GitHub.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>And here’s my initial dev repo with a MWE of the a differentiable loss expression for convex polygons:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/DerekGloudemans/polygon-IOU">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/DerekGloudemans/polygon-IOU" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/344;"><img src="https://opengraph.githubassets.com/350c2945eeaab9604b27766d2d73e5230fb20bbb4415f90d0291d147d94f8746/DerekGloudemans/polygon-IOU" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/DerekGloudemans/polygon-IOU" target="_blank" rel="noopener nofollow ugc">GitHub - DerekGloudemans/polygon-IOU: Differentiable Polygon IOU loss, for...</a></h3>

  <p>Differentiable Polygon IOU loss, for non-axis aligned and non-orthogonal bounding polygon network training - DerekGloudemans/polygon-IOU</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>