Python 警告:tensorflow:实体<;函数get_tensorlist位于…>;无法转换,将按原样执行

Python 警告:tensorflow:实体<;函数get_tensorlist位于…>;无法转换,将按原样执行,python,tensorflow,Python,Tensorflow,在Spyder 4.0.1中,当我运行以下代码时 import tensorflow as tf @tf.function def get_tensorlists(m,n,max=7): list1 = tf.random.uniform([m,n],0,max,seed=0) list2 = tf.random.uniform([m,n],0,max,seed=0) return list1,list2 @tf.function def get_dataset(X,Y,epoc

在Spyder 4.0.1中,当我运行以下代码时

import tensorflow as tf

@tf.function
def get_tensorlists(m,n,max=7):
  list1 = tf.random.uniform([m,n],0,max,seed=0)
  list2 = tf.random.uniform([m,n],0,max,seed=0)
  return list1,list2

@tf.function
def get_dataset(X,Y,epochs):
  set = tf.data.Dataset.from_tensor_slices((X,Y))
  # adjust it the way we need
  set = set.shuffle(100).repeat(epochs).batch(1)
  return set

temp = get_tensorlists(10,1)
X = temp[0]
Y = temp[1]
dataset = get_dataset(X,Y,1)

print(dataset)
i = 0
for (x,y) in dataset:
  i+=1
  print(i)
  print(x,y)
我得到这个错误打印:

WARNING:tensorflow:Entity <function get_tensorlists at 0x000001DA9852C798> could not be transformed and will be executed as-is.
Please report this to the AutgoGraph team.
警告:tensorflow:实体无法转换,将按原样执行。
请将此报告给AUTGOGRAPHER团队。
我发现的唯一建议是安装
pip install gast==0.2.2
并重新启动Spyder。但这对我来说没有任何改变

那么,我如何才能消除这个错误呢?

这对我来说很有效:

  • 通过手动删除每个包含“tensor”(属于TensorFlow)的文件来卸载TensorFlow
  • 使用
    conda卸载gast卸载gast
  • 使用
    conda安装TensorFlow重新安装TensorFlow
  • 使用conda install gast重新安装TensorFlow
错误现在不再出现


除此之外,我得到的输出仍然是毫无意义的,而不是应该打印的内容。 我最终也解决了输出问题,我需要降级TF:
pip install tensorflow==2.0.0

编辑:我不建议任何人手动删除这些文件,这通常会造成很多麻烦-尽管在这里它对我有效。

这对我有效:

  • 通过手动删除每个包含“tensor”(属于TensorFlow)的文件来卸载TensorFlow
  • 使用
    conda卸载gast卸载gast
  • 使用
    conda安装TensorFlow重新安装TensorFlow
  • 使用conda install gast重新安装TensorFlow
错误现在不再出现


除此之外,我得到的输出仍然是毫无意义的,而不是应该打印的内容。 我最终也解决了输出问题,我需要降级TF:
pip install tensorflow==2.0.0


编辑:我不建议任何人手动删除文件,这通常会造成很多麻烦-尽管我在这里工作。

CPU中的TensorFlow 2.2.0-rc4(我的gast版本是0.3.3)没有收到任何警告。您使用哪个Spyder版本?我不使用Spyder,我刚刚在一个独立的IPython控制台中测试了你的代码。CPU中的TensorFlow 2.2.0-rc4(我的gast版本是0.3.3)没有任何警告。你使用哪个Spyder版本?我没有使用Spyder,我只是在一个独立的IPython控制台中测试了你的代码。