6

I am trying to write a custom loss function in Keras, as seen in: Custom loss function in Keras

My custom function is supposed to lower the effect of values smaller than 25. To do this the function will first call tf.clip_by_value (thus, any values less than 25 will become 25) on both yTrue and yPred (as seen in the link above). Next, in order to reduce the effect of these values, when a value in yTrue is equal to 25, the corresponding value of yPred will be changed to yPred[i] - (yPred[i] - yTrue[i])/2. Finally, the function will return the result of 'binary_crossentropy' on these two tensors.

I have two main questions:

  1. How do I implement this custom loss function? I am having trouble iterating over the tensors (as seen in Looping over a tensor)
  2. Is the function that I proposed a good implementation to reduce the effect of these values or is there a better option?

Thanks in advance for the help

John
  • 155
  • 1
  • 2
  • 7

0 Answers0