问题:tf.function 引发警告并使用 tf.stack 失败 [英] Issue: tf.function raising a warning and failing with tf.stack
本文介绍了问题:tf.function 引发警告并使用 tf.stack 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 tensorflow 中遇到 tf.function
问题.似乎无法转换包含指令 tf.stack()
的函数.
I am having problems with tf.function
in tensorflow. It seems to fail to convert functions containing the instruction tf.stack()
.
这是我写的一个简单的代码来强调这个问题:
Here a simple code I wrote to highlight the issue:
import tensorflow as tf
c = tf.Variable([[1., 5.], [2., 4.]])
@tf.function
def toy_fct(x):
y = tf.stack([x[0,:], x[1,:]], axis=0)
return y
toy_fct(c)
我收到的消息如下:
WARNING:tensorflow:AutoGraph could not transform <function toy_fct at 0x000001DC9A13A670> 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
WARNING: AutoGraph could not transform <function toy_fct at 0x000001DC9A13A670> 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
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 5.],
[2., 4.]], dtype=float32)>
有人知道吗?
推荐答案
我已经在 tf 2.0
到 tf 2.4
中测试了您的代码,没有任何问题.但是当我使用 gast==0.4.0
时出现.试试这个
I've tested your code in tf 2.0
to tf 2.4
without any issue. But it appears when I used gast==0.4.0
. Try this
pip install --upgrade pip
pip install gast==0.2.2
仅供参考,它在 gast==0.4.0
和最新的 tf 2.5.0-rc0
下运行良好.
FYI, it runs fine with gast==0.4.0
with latest tf 2.5.0-rc0
.
这篇关于问题:tf.function 引发警告并使用 tf.stack 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文