gpt4 book ai didi

python - 警告 :tensorflow:AutoGraph could not transform and will run it as-is

转载 作者:行者123 更新时间:2023-12-04 07:50:58 33 4
gpt4 key购买 nike

我正在尝试运行 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 - 警告 :tensorflow:AutoGraph could not transform <function _preprocess at 0x7f8ff80cd160> and will run it as-is,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66986540/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com