Timeline for How to wrap a custom TensorFlow loss function in Keras?
Current License: CC BY-SA 3.0
2 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 2, 2018 at 6:57 | comment | added | John Ladasky |
I actually tried that a few hours after posting. And I was puzzled by what I saw. Keras did not give me an error, but the loss went immediately to NaN. Eventually I solved the problem. The calling convention for a Keras loss function is first y_true, then y_pred -- or as I call them, tgt and pred. But the calling convention for a TensorFlow loss function is pred first, then tgt. So this fix works: def keras_l2_angle_distance(tgt, pred): return l2_angle_distance(pred, tgt) . Maybe Theano or CNTK uses the same order as Keras, I don't know. But I'm back in business.
|
|
Jan 1, 2018 at 10:24 | history | answered | Dr. Snoopy | CC BY-SA 3.0 |