Hi,
I am building an image segmentation model. However, some of the pixels are not labeled and I wish for these to be ignored during training/validation process. To do this, I add a matrix w which is the same size as the image to my generator (i.e. generator returns x, y, w).
When I compare the output of the backprop loss (or running model.eval), I get different numbers for tf.keras.losses.categorical_crossentropy than when I use weighted_metrics=[tf.keras.metrics.CategoricalCrossentropy()]
It appears that the metrics version is correct from my by-hand computations. What I noticed with respect to tf.keras.losses.categorical_crossentropy is that the loss normalizes the mean by (w.sum() / number_of_pixels). Why would it do this and how do I remove it?
For example, suppose my image is 262144 pixels (i.e. 512x512) with a mask that is 221185 pixels and I compute the cross entropy via [tf.keras.metrics.CategoricalCrossentropy(), I get 1.6678107976913452 which is exactly what I get by hand if i compute the loss USING ONLY THE RELEVANT PIXELS (i.e. w =1).
However, when I examine the loss from model.eval(), i get 1.4072216 which is ( 221185 / 262144 ) * 1.6678107976913452. I don't understand why this normalization factor exists.
Thank you,
Isaac