I am working on a custom loss function, as the output of network I am getting x and y coordinates of the image. I am trying to put a constraint that predicted coordinates and ground truth should be close to each other in the 2D domain. But generating an image from coordinates requires me to work in NumPy and OpenCV. This break the computation graph, can somebody help me to get through this:

Screenshot from 2020-01-29 14-39-22699×649 91.7 KB

vis_loss1 is my main function which returns loss and visualize is the function which convert coordinates to an image(this is where I use numpy and openCV). using l1 I want to adjust gt and pred , but this is not happening. Can someone help me?