首页 > 解决方案 > 我想了解为什么会出现这个特定的张量流警告......?

问题描述

我认为这可能会由于 tensorflow-gpu 包和 tensorflow 包中的一些复杂性而受到影响,这就是我得到这个的原因......

我只是想用两个隐藏层训练一个普通的 softmax 分类器,并以 tf.float32 格式输入所需的张量,但我收到了这个错误......

WARNING: Entity <bound method Dense.call of <tensorflow.python.layers.core.Dense object at 0x000002F4EC7C8AC8>> could not be transformed and will be executed as-is. Please report this to the AutgoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: converting <bound method Dense.call of <tensorflow.python.layers.core.Dense object at 0x000002F4EC7C8AC8>>: AttributeError: module 'gast' has no attribute 'Index'
WARNING: Entity <bound method Dense.call of <tensorflow.python.layers.core.Dense object at 0x000002F4ECE5AE48>> could not be transformed and will be executed as-is. Please report this to the AutgoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: converting <bound method Dense.call of <tensorflow.python.layers.core.Dense object at 0x000002F4ECE5AE48>>: AttributeError: module 'gast' has no attribute 'Index'
WARNING: Entity <bound method Dense.call of <tensorflow.python.layers.core.Dense object at 0x000002F4ECE5AE48>> could not be transformed and will be executed as-is. Please report this to the AutgoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: converting <bound method Dense.call of <tensorflow.python.layers.core.Dense object at 0x000002F4ECE5AE48>>: AttributeError: module 'gast' has no attribute 'Index'

我不明白这是什么意思,甚至我也试图忽略警告,但我仍然得到这个,我只想了解这个警告是如何出现的..?

代码片段如下:

import tensorflow as tf
n_features = X_train_centered.shape[1]
n_classes = 10
random_seed = 123
np.random.seed(random_seed)

g = tf.Graph()
with g.as_default():
    tf.set_random_seed(random_seed)
    tf_x = tf.placeholder(dtype = tf.float32,shape = (None,n_features),name = 'tf_x')
    tf_y = tf.placeholder(dtype = tf.int32,shape = None,name = 'tf_y')
    y_onehot = tf.one_hot(indices = tf_y,depth = n_classes)
    h1 = tf.layers.dense(inputs = tf_x,units = 50,activation = tf.tanh,name = 'layer1')
    h2 = tf.layers.dense(inputs = h1,units = 50,activation = tf.tanh,name = 'layer2')
    logits = tf.layers.dense(inputs = h2,units = 10,activation = None,name = 'layer3')
    predictions = {'classes': tf.argmax(logits,axis = 1,name = 'predicted_classes'),'probabilities' : tf.nn.softmax(logits,name = 'softmax_tensor')}

标签: pythontensorflow

解决方案


这似乎是 gast 的一个问题,一个 tf 依赖项。降级到 gast 0.2.2 已经为大多数开发人员解决了这个问题。所以运行: pip install gast==0.2.2 应该可以解决。

(供参考:https ://github.com/tensorflow/tensorflow/issues/32859 )


推荐阅读