首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何禁用所有tensorflow警告?

如何禁用所有tensorflow警告?
EN

Stack Overflow用户
提问于 2021-12-21 02:18:30
回答 3查看 5.1K关注 0票数 4

我有一个for循环,其中包含几个不同的深度学习模型,这些模型产生了以下警告:

代码语言:javascript
复制
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循环中尝试了许多不同的东西来阻止它弹出,但没有成功。是否有一种简单的方法来禁用所有警告?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-12-21 03:07:58

用这个:

代码语言:javascript
复制
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
票数 6
EN

Stack Overflow用户

发布于 2021-12-21 07:52:38

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

代码语言:javascript
复制
import os
import tensorflow as tf

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
票数 5
EN

Stack Overflow用户

发布于 2021-12-21 14:36:57

只需将tensorflow记录器设置为错误:

代码语言:javascript
复制
import tensorflow as tf
tf.get_logger().setLevel('ERROR')
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70429982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档