0

I am building my loss function. However, when printing the value of the y_true tensor it is printing values with decimal points (i.e 0.25,0.569,0.958). This should not be true as the y_true should only have two classes 0 or 1. Here is my code:

@tf.function
def weighted_binary_crossentropy(y_true, y_pred):
    y_true= K.reshape(y_true, (K.shape(y_true)[0], -1))
    tf.print("tensors1:", y_true, output_stream=sys.stdout, summarize=50000)

Any reason why I am getting such an output instead of 0 and 1?

devdeep
  • 1
  • 1
  • These decimal points are actually probabilities which ranges from 0 to 1. If you want either 0 or 1 then you have to assign probabilities less than a threshold (normally 0.5) to 0 and 1 otherwise yourself. But normally while calculating loss, you don't have to do this. – user_3pij May 10 '20 at 13:41
  • Yes I understand that should be the output of the y-pred but why for the y_true. Why it should give probability for the groundTruth (y_true)? Grountruth was already 0 or 1. – devdeep May 10 '20 at 21:15
  • Did you check whether `y_true` was correctly labeled in the dataset? – user_3pij May 10 '20 at 23:44
  • Yes I did and it is 0 and 1 – devdeep May 11 '20 at 00:21
  • Now I think its a matter of debugging. May be you are updating `Y_true` value somewhere before the loss function gets called. Can you post your complete code? – user_3pij May 11 '20 at 19:46

1 Answers1

0

I am able to detect the issue which is from my data generator. When I have rotation_range added it mess up the values of the pixels. This is because on rotation new pixels are created

devdeep
  • 1
  • 1