Is it possible for using 3rd party lib when define loss function?

Hello There?

I want to use 3rd party lib when define loss function , because pytorch can not fulfill all requirments for users ,pseudo code as following:

from shapely.geometry import Polygon  # 3rd party pacakage

loss= iou

Whether pytoch will automatically trace the gradient of “loss” or not ? Thank you in advance

Yes, it’s possible, but Autograd won’t be able to track these operations, so you would need to write the backward pass manually via a custom autograd.Function as described here.