2016-11-03 1 views
0

비슷한 스레드를 모두 확인했지만 문제를 해결할 수 없습니다.ValueError : tensorflow와 함께 배열을 사용하여 배열 요소를 설정하는 중

사실 내 코드는 내 로컬 시스템에서 제대로 작동하지만 서버에서 실행하면이 오류가 발생합니다. 코드 스 니펫 :

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 였으므로 설치 제거하고 설치하십시오. 1.11.1

로컬 시스템의 오류없이 정상적으로 작동하는 1.11.1이 있습니다.

솔루션을 참조 : tensorflow: ValueError: setting an array element with a sequence

내가 nptf를 교체했지만,이

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 

답변

1

을 준 나는 이유는 MultiRNNCell 생성자의 state_is_tuple 인수라고 생각합니다. 기본적으로 true이고이 경우 self.cell.state_size은 튜플입니다.

업데이트

MultiRNNCell 여러 다른 세포로 만든 세포이다. 따라서, 내부 셀의 상태로 구성된 MultiRNNCell의 상태. state_is_tuple constructor의 인수는 내부 셀의 상태가 단일 텐서로 결합되는 경우 제어합니다. 참이면 state_sizeMultiRNNCell이며, 내부 셀의 합계는 state_size입니다 (see source). 그렇지 않은 경우 state_size은 내부 셀 크기의 튜플입니다.

나중에 [self.batch_size, <tuple>]을 모양으로 tf.zeros (또는 np.zeros)으로 전달합니다.

로컬 시스템에서 왜 작동하는지 알 수 없습니다. 나는 여러분의 시스템에서 다른 기본 동작을 가진 다른 버전의 tensorflow를 사용한다고 추측 할 수 있습니다.

+0

감사합니다. 그러나 이해하지 못했습니다. 너는 정교하게 만들어 줄 수 있니? – user123

0

나는 그것이 numpy 버전 때문인 줄 알았는데. 그래서 나는 그것을 바꾸려고 노력했지만 도움은 안된다. 또한 행운을 들이지 않고 코드를 변경하여 시도했습니다.

이 코드는 tensorflow 0.8.0에서 잘 작동합니다.

최신 tensorflow를 설치하고이 코드를 시도하면이 오류가 발생합니다.

최신 버전을 제거하고 0.8.0을 설치 했으므로 이제는 정상적으로 작동합니다.

관련 문제