How do I print inside the loss function during training in Keras?

后端 未结 1 1682
情深已故
情深已故 2021-01-04 01:50

I am trying to create a loss function in Keras (Tensorflow Backend) but I am a little stuck to check the inside of the custom loss function. In fact, the print appears on th

相关标签:
1条回答
  • 2021-01-04 02:21

    The only thing you can do is not use python's print function, but for example, tensorflow's tf.Print function that is part of the computational graph. The documentation says the operation does nothing but each time it is evaluated it prints a message that you can specify.

    You just need to be careful to place it correctly in the graph, something like:

    def loss(y_true, y_pred):
        d = y_true - y_pred
        d = tf.Print(d, [d], "Inside loss function")
        return tf.reduce_mean(tf.square(d))
    

    A better option to look inside what is going on internally is to use the tensorflow debugger.

    0 讨论(0)
提交回复
热议问题