- Tensorflow报错: AttributeError: module 'tensorflow' has no attribute 'reset_efault_graph'
原代码:
import tensorflow as tf
tf.reset_efault_graph()
参考文档
解决:It's possible that you have named a file in your project tensorflow.py and the import statement is importing from this file.
Alternatively, you can try this,
from tensorflow.python.framework import ops
ops.reset_default_graph()
- Tensorflow报错: AttributeError: 'Tensor' object has no attribute 'sparse_read'
原代码:
from tensorflow.python.framework import ops
ops.reset_default_graph()
input_data = tf.placeholder(tf.float32,[batchSize,maxSeqLength])
data = tf.nn.embedding_lookup(wordVectors,input_data) #报错行
解决办法:将input_data的tf.float32改为tf.int32
##修改此行
input_data = tf.placeholder(tf.int32,[batchSize,maxSeqLength])
- Tensorflow报错:ValueError: Shape (16, 24) must have rank at least 3
报错代码:
value, _ = tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float32)
错误说明:错误的意思是传入的数据集data的维度只有二维,而tf.nn.dynamic_rnn()要求传入的数据集的维度是三维(batch_size, squence_length, num_features)。
问题追踪:找到数据集data的定义代码为
data = tf.nn.embedding_lookup(wordVectors,input_data)
#print(data)
>>>Tensor("embedding_lookup_2/Reshape_1:0", shape=(24, 16), dtype=string)
发现shape是(24,16),而正常应该为三维,shape(24,16,50),可见可能是wordVectors的问题,打印wordVectors:
print(wordVectors.shape)
>>>AttributeError: 'list' object has no attribute 'shape'
果然是wordVecotors的问题,竟然不是数组是列表。然后我才发现误写了一个wordVectors.tolist(),好巴,,找到问题了
- TensorFlow报错: ValueError: An initializer for variable rnn/basic_lstm_cell/kernel of <dtype: 'string'> is required
原代码:
value, _ = tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float32)
解决方法:


参考文档
网友评论