How can I print the intermediate variables in the loss function in TensorFlow and Keras?

前端 未结 3 1280
囚心锁ツ
囚心锁ツ 2021-02-19 10:13

I\'m writing a custom objective to train a Keras (with TensorFlow backend) model but I need to debug some intermediate computation. For simplicity, let\'s say I have:

         


        
3条回答
  •  眼角桃花
    2021-02-19 10:44

    In TensorFlow 2.0, you can use tf.print and print anything inside the definition of your loss function. You can also do something like tf.print("my_intermediate_tensor =", my_intermediate_tensor), i.e. with a message, similar to Python's print. However, you may need to decorate your loss function with @tf.function to actually see the results of the tf.print.

提交回复
热议问题