【发布时间】:2016-11-03 06:53:12
【问题描述】:
我检查了所有类似的线程,但无法解决我的问题。
实际上我的代码在我的本地系统上运行良好,但是当我在服务器上执行它时,它给出了这个错误。代码sn-p:
with tf.variable_scope("lstm") as scope:
# The RNN cell
single_cell = rnn_cell.DropoutWrapper(
rnn_cell.LSTMCell(hidden_size, hidden_size, initializer=tf.random_uniform_initializer(-1.0, 1.0)),
input_keep_prob=self.dropout_keep_prob_lstm_input,
output_keep_prob=self.dropout_keep_prob_lstm_output)
self.cell = rnn_cell.MultiRNNCell([single_cell] * num_layers)
# Build the recurrence. We do this manually to use truncated backprop
self.initial_state = tf.zeros([self.batch_size, self.cell.state_size]) # ERROR IS IN THIS LINE
self.encoder_states = [self.initial_state]
self.encoder_outputs = []
追溯:
WARNING:tensorflow:<tensorflow.python.ops.rnn_cell.LSTMCell object at 0x7f56e6c2cb10>: The input_size parameter is deprecated.
Traceback (most recent call last):
File "train.py", line 194, in <module>
main()
File "train.py", line 63, in main
model = create_model(sess, hyper_params, vocab_size)
File "train.py", line 124, in create_model
hyper_params["batch_size"])
File "/home/datametica/karim/deeplearning/neural-sentiment/models/sentiment.py", line 73, in __init__
self.initial_state = tf.zeros([self.batch_size, self.cell.state_size])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 1184, in zeros
shape = ops.convert_to_tensor(shape, dtype=dtypes.int32, name="shape")
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 657, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 180, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 163, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 354, in make_tensor_proto
nparray = np.array(values, dtype=np_dt)
ValueError: setting an array element with a sequence.
这里是实际代码的链接 - https://github.com/inikdom/neural-sentiment/blob/master/train.py
这个错误是由于 numpy 版本造成的吗?之前我的服务器 numpy 版本是 1.11.2,所以我卸载并安装了 numpy 1.11.1
我的本地系统有 1.11.1,可以正常工作,没有任何错误。
参考解决方案:tensorflow: ValueError: setting an array element with a sequence
我尝试用np 替换tf,但它给了
WARNING:tensorflow:<tensorflow.python.ops.rnn_cell.LSTMCell object at 0x7f84f6f8e890>: The input_size parameter is deprecated.
Traceback (most recent call last):
File "train.py", line 194, in <module>
main()
File "train.py", line 63, in main
model = create_model(sess, hyper_params, vocab_size)
File "train.py", line 124, in create_model
hyper_params["batch_size"])
File "/home/datametica/karim/deeplearning/neural-sentiment/models/sentiment.py", line 73, in __init__
self.initial_state = np.zeros([self.batch_size, self.cell.state_size])
TypeError: an integer is required
【问题讨论】:
标签: python numpy tensorflow