警告:张量流:AutoGraph 无法在0x7f8ff80cd160>处转换<函数_preprocess,并将按原样运行



我正在尝试运行中的代码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)))

我得到的是以下警告:

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

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

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

您可以:

  • 将您的python版本降级到3.8
  • 如本GitHub问题所述,将包gast的版本降级为0.3.3:报告:AutoGraph无法转换,模块"gast"没有属性"Index"#44146

最新更新