1

The losses have remained the same and have not fallen as expected. Here is my Code to test if the loss function work well:

def my_loss(y_true, y_pred):
    return tf.reduce_mean(tf.sigmoid(-200 * (y_pred - 1.05)))

model.compile(optimizer=tf.train.AdamOptimizer(),
              loss=ml.my_loss,
              metrics=['mae', ml.my_metrics])

and here is the output:

5000/28976 [====>.........................] - ETA: 0s - loss: 1.0000 - mean_absolute_error: 1.0406 - my_metrics: 0.0000e+00 10000/28976 [=========>....................] - ETA: 0s - loss: 1.0000 - mean_absolute_error: 1.0412 - my_metrics: 0.0000e+00 15000/28976 [==============>...............] - ETA: 0s - loss: 1.0000 - mean_absolute_error: 1.0412 - my_metrics: 0.0000e+00 20000/28976 [===================>..........] - ETA: 0s - loss: 1.0000 - mean_absolute_error: 1.0411 - my_metrics: 0.0000e+00 28976/28976 [==============================] - 0s 10us/step - loss: 1.0000 - mean_absolute_error: 1.0407 - my_metrics: 0.0000e+00

zzm
  • 11
  • 3
  • it keeps 1 in all training time. – zzm Feb 21 '19 at 05:53
  • what's my_ls?, i don't think `tf.reduce_mean` has that parameter, read this: https://www.tensorflow.org/api_docs/python/tf/math/reduce_mean – Daksh M. Feb 21 '19 at 05:57
  • i think it should be `tf.reduce_mean(tf.sigmoid(-200 * (y_pred -1.05)))`, try that and let me know if it's still a problem? – Daksh M. Feb 21 '19 at 05:58
  • yes u r right. ti's still a problem. def my_loss(y_true, y_pred): return tf.reduce_mean(tf.sigmoid(-200 * (y_pred - 1.05))) – zzm Feb 21 '19 at 06:00
  • so did it work? @zzm – Daksh M. Feb 21 '19 at 06:03
  • no, it keep at 1.0000. – zzm Feb 21 '19 at 06:06
  • okay, so your model.compile has an argument, loss=ml.my_loss? why don't you use my_loss instead? – Daksh M. Feb 21 '19 at 06:07
  • because the function defined in the other file, I have import it as ml – zzm Feb 21 '19 at 06:09
  • in my opinion, it will be get zero, because the model can change the y_pred to a large number to get a min loss. – zzm Feb 21 '19 at 06:14
  • check this question out: https://stackoverflow.com/questions/45961428/make-a-custom-loss-function-in-keras – Daksh M. Feb 21 '19 at 06:15
  • Thanks, it not the same reason, that question's problem is to rename loss funcion's parameter's name. but in my code, it is ‘y_true, y_pred’, it not need a wrapper. – zzm Feb 21 '19 at 06:36
  • it works when i change the function to : tf.reduce_mean(tf.sigmoid(-(y_pred - 1.05))), remove coefficient(200) Thanks. – zzm Feb 21 '19 at 07:50
  • glad to know it worked out! – Daksh M. Feb 21 '19 at 08:55

0 Answers0