警告:tensorflow:AutoGraph 无法转换 <function _preprocess at 0x7f8ff80cd160> 并将按原样运行

The*_*Man 2 python warnings tensorflow

我正在尝试运行https://www.tensorflow.org/probability/examples/Probabilistic_Layers_VAE中找到的代码。

我使用的是 Python 版本 3.9,我的 TensorFlow 版本是 >2.0。代码如下:

import tensorflow.compat.v2 as tf
tf.enable_v2_behavior()

import tensorflow_datasets as tfds
import tensorflow_probability as tfp


tfk = tf.keras
tfkl = tf.keras.layers
tfpl = tfp.layers
tfd = tfp.distributions

datasets, datasets_info = tfds.load(name='mnist', with_info=True, as_supervised=False)

def _preprocess(sample):
    image = tf.cast(sample['image'], tf.float32) / 255 #Scale to [0, 1]
    image = image < tf.random.uniform(tf.shape(image)) #Gives 0, 1 when compared to a random number
    return image, image

train_dataset = (datasets['train']
                .map(_preprocess)
                .batch(256)
                .prefetch(tf.data.experimental.AUTOTUNE)
                .shuffle(int(10e3)))
Run Code Online (Sandbox Code Playgroud)

我得到的是以下警告:

WARNING:tensorflow:AutoGraph could not transform <function _preprocess at 0x7f8ff80cd160> 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: module 'gast' has no attribute 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
Run Code Online (Sandbox Code Playgroud)

该警告与代码的最后部分相关,但我无法判断它是否会潜在地影响代码的运行方式。如果不影响的话,有没有办法持续删除此类警告?

Les*_*rel 5

这是 TensorFlow 和 Python 3.9 之间的 API 冲突。请注意,截至今天(2021-04-07),TensorFlow 官方版本仅支持 Python 版本 3.6 至 3.8。TensorFlow 2.5 应该正式支持 Python 3.9。

您可以: