Polygon Intersection

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.

1 Like

Hello Derek, did you find anyone who implemented this? I’ve had the same thoughts, it would be interesting to test backpropagation with this.

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.

If you do implement something you should post it; would be very interested to see !

Any updates on this?

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.

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.