2016-11-03 5 views
0

すべての類似のスレッドをチェックしましたが、問題を解決できませんでした。ValueError:テンソルフローで配列を使用して配列要素を設定する

実際に私のコードはローカルシステムで正常に動作しますが、サーバーで実行するとこのエラーが発生します。コードスニペット:

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

私はnptfを交換しようとしたが、それは、私は理由がMultiRNNCellコンストラクタの引数state_is_tupleだと思う

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

を与えました。デフォルトではtrueです。この場合、self.cell.state_sizeはタプルです。

更新

MultiRNNCellは、いくつかの他の細胞から作られた細胞です。したがって、内部セルの状態からなるMultiRNNCellの状態。コンストラクタの引数state_is_tupleは、内部セルの状態が単一のテンソルに結合されている場合に制御します。それが真である場合、state_sizeMultiRNNCellは、state_sizeの内部細胞(see source)の合計である。それ以外の場合、state_sizeは、内部セルのサイズの組です。

[self.batch_size, <tuple>]を形状としてtf.zeros(またはnp.zeros)に渡します。

なぜあなたのローカルシステムで動作するのかわかりません。あなたのシステムでは、テンソルフローの他のバージョンで他のデフォルト動作が使用されているとしか推測できません。

+0

ありがとうございましたが、私はそれを理解しませんでした。あなたは精巧にお聞かせください – user123

0

私はそれがnumpyバージョンのためだと思った。私はそれを変更しようとしましたが、助けはありませんでした。また、運がないコードを変更して試しました。

私が見つけたのは、このコードはテンソル0.8.0でうまくいきます。

最新のテンソルフローをインストールしてこのコードを試してみると、このエラーが発生します。

私は最新のバージョンをアンインストールして0.8.0をインストールしましたが、もう一度正常に動作します。

関連する問題