Loss function with Numpy libraries

Hello all,

I am trying to set up a loss function that involves image transform with the skimage library. The skimage library is, however completely in Numpy and I have had no luck converting the arrays into tensors so far. Me converting the tensors to arrays would require me to break the computational graph with detach(). Is there any way I can use the skimage library without detaching the tensors as the use of the library is imperative to my work?

Any help will be highly appreciated.


I’m afraid you won’t be able to use skimage and pytorch’s autograd. To work, the autograd needs definition of the derivatives for everything that happens. So we only support pytorch ops.

If you know how to write the backward for that part though, you can create a custom Function and define the backward yourself. See doc here for more details.

1 Like

Thank you for your help :slight_smile:

Yeah I can try with that. For more reference, I am currently trying to take in some tensors and with the help of those trying to transform the image. I haven’t written backward ever and have a vague intuition this won’t work, but can I use the tensors to transform the Image–then compare the image and the label with a loss and return loss.backward() in backward ? It would still break the link between the input tensors and the Image right?