【问题标题】:How to suppress "WARNING:tensorflow:AutoGraph could not transform <bound method Layer.__call__ of ... >>"?如何抑制“WARNING:tensorflow:AutoGraph could not transform <bound method Layer.__call__ of ... >>”?
【发布时间】:2021-01-20 16:09:49
【问题描述】:

我每次运行 tf.keras.Sequential().predict_on_batch 时都会收到此消息:

WARNING: AutoGraph could not transform <bound method Layer.__call__ of <tensorflow.python.keras.engine.sequential.Sequential object at 0x000001F927581348>> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: 

它完全填满了我的控制台,我找不到抑制它的方法。

Python 版本:3.7.7 张量流版本:2.1.0

【问题讨论】:

标签: python tensorflow


【解决方案1】:

我在自定义层中遇到过这种情况,其中包含 for 循环。我一直在用@tf.autograph.experimental.do_not_convert装饰调用方法

例如:

class DoNothing(tf.keras.layers.Layer):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        
    def get_config(self):
        config = {}
        base_config = super().get_config()
        return {**base_config, **config}

    @tf.autograph.experimental.do_not_convert
    def call(self, args, **kwargs):
       return args # Yes, this layer really doesn't do anything 

【讨论】:

    【解决方案2】:

    使用以下代码设置autograph verbosity 级别

    import os
    import tensorflow as tf
    os.environ['AUTOGRAPH_VERBOSITY'] = 1
    

    您可以通过在程序开始时设置日志级别来抑制警告

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

    【讨论】:

    • 上面的代码返回了错误,下面的代码什么也没做。
    猜你喜欢
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    相关资源
    最近更新 更多