【问题标题】:如何禁用所有张量流警告?
【发布时间】:2022-01-22 13:15:16
【问题描述】:

我有一个 for 循环,其中包含几个不同的深度学习模型,会生成此警告:

WARNING:tensorflow:5 out of the last 5 calls to <function Model.make_predict_function.<locals>.predict_function at 0x000001B0A8CC90D0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for  more details.
WARNING:tensorflow:6 out of the last 6 calls to <function Model.make_predict_function.<locals>.predict_function at 0x000001B0A6C01940> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for  more details.

我在 for 循环中尝试了许多不同的方法来阻止它在没有成功的情况下弹出。是否有简单的方法来禁用所有警告?

【问题讨论】:

标签: python tensorflow keras


【解决方案1】:

使用这个:

tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

【讨论】:

    【解决方案2】:

    您可以使用它来避免警告:

    import os
    import tensorflow as tf
    
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    

    【讨论】:

    • 详细说明:- 0 = 记录所有消息(默认行为),1 = 不打印 INFO 消息,2 = 不打印 INFO 和 WARNING 消息,3 = INFO、WARNING 和 ERROR 消息不打印
    【解决方案3】:

    只需将 tensorflow logger 设置为 ERROR:

    import tensorflow as tf
    tf.get_logger().setLevel('ERROR')
    

    【讨论】:

      猜你喜欢
      • 2020-01-02
      • 2010-11-29
      • 1970-01-01
      • 2019-05-19
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      相关资源
      最近更新 更多