美文网首页
Tensorflow Error

Tensorflow Error

作者: 在努力的Jie | 来源:发表于2020-02-16 01:50 被阅读0次
  1. 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()
  1. 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])
  1. 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(),好巴,,找到问题了

  1. 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)

解决方法:

1.png 其实就是传入的data里的词向量是<U21类型,如下,
2.png 而tf.nn.dynamic_rnn仅接受int/float两种类型,显然我传入的string型是错误的,因此报错。
参考文档

相关文章

网友评论

      本文标题:Tensorflow Error

      本文链接:https://www.haomeiwen.com/subject/xygufhtx.html