Hello redamit!



 redamit:

I’m currently working on implementing a GAN, with a custom loss function which uses other Python modules and libraries.
…
I’m able to implement the forward path with no particular issue. I don’t want to calculate gradients for this task but want to use this loss to back propagate GAN whose output I’m using to input to the loss function.
…
Is there a way in which I’m able to accomplish the task of using this loss to back propagate through the GAN?


No, not really.
If I understand you correctly, even though you “don’t want to calculate
gradients for” the parameters used by the face detector in your loss
function, you do want to calculate gradients for the parameters of
the GAN used to generate the image fed to the face detector.
Once you start to pass the generated image through non-pytorch
calculations, you “break the computation graph,” and won’t be able
to backpropagate from one side of the non-pytorch calculations to
the other.
Your best bet will to be to implement the face detector in pytorch (if
it isn’t already) and figure out how to implement your landmark
calculations using differentiable pytorch operations.  If the whole
end-to-end calculation – GAN image generation, face detection,
landmark calculations, and final loss function – is done with (differentiable)
pytorch tensor operations, pytorch’s autograd will work, you can call
loss.backward(), and use the GAN-parameter gradients produced by
autograd to optimize your GAN.
(Other approaches are theoretically possible, but likely to be unworkable.)
Good luck.
K. Frank