Right way to access input when computing loss?

I’m trying to replicate a paper that outputs a mask for an image (similar to the carvana challenge).

Part of the loss requires applying the predicted mask to the input image (ie, we’re not just comparing the ground-truth mask to the predicted mask, we actually want the apply them to the original image).

I’m stumped at how to access the original image when computing the loss function during training. I’ve tried hacking it by concatenating the original image to the ground truth masks and letting them get carried all the way through, but this seems like extreme overkill and requires a lot more memory.

Is there a convenient way to do this?

You should use a Callback. You can access the last input at any event, and modify the loss according to your need.

1 Like

Thanks for the quick reply, I knew I was missing something.