Tnx for your reply, I did those things because I want just a specific pixel of my output to be in the loss cost and not the whole of the output. for that I masked my output.
Is there any option to my code do this work without any error?