I have the same question. In my case, I have a tensor which is the output of my model with requires_grad = True and I want to do some process on it using OpenCV in my custom loss. I’m trying to do it on GPU while keeping the requires_grad = True. Do you have any suggestions? I found kornia and it seems they are adding some OpenCV functions, but not the ones I need.