Python 警告:tensorflow:签名无法转换<;函数_在0x7f8ff80cd160处进行预处理>;并将按原样运行

Python 警告:tensorflow:签名无法转换<;函数_在0x7f8ff80cd160处进行预处理>;并将按原样运行,python,tensorflow,warnings,Python,Tensorflow,Warnings,我正在尝试运行在中找到的代码 我使用的是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

我正在尝试运行在中找到的代码

我使用的是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)))
将tensorflow.compat.v2导入为tf
tf.enable_v2_behavior()
将tensorflow_数据集作为TFD导入
导入tensorflow_概率作为tfp
tfk=tf.keras
tfkl=tf.keras.layers
tfpl=tfp.layers
tfd=tfp
数据集,数据集\u info=tfds.load(name='mnist',其中\u info=True,as\u supervised=False)
def_预处理(示例):
image=tf.cast(样本['image'],tf.float32)/255#缩放到[0,1]
image=image
我得到的是以下警告:

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:AutoGraph无法转换,将按原样运行。
请将此报告给TensorFlow团队。在归档bug时,将详细度设置为10(在Linux上,`export AUTOGRAPH\u verbosity=10`),并附加完整的输出。
原因:模块“gast”没有属性“Index”
要使此警告静音,请使用@tf.autograph.experimental.do\u not\u convert装饰函数

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

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

您可以:

  • 将python版本降级到3.8
  • 将您的软件包
    gast
    版本降级为本期GitHub中提到的
    0.3.3