ValueError:使用序列张量流设置数组元素

时间:2017-01-03 11:22:08

标签: python tensorflow

以下是给我错误的代码段 -

for i in xrange(num_gpus):
        self.encoder_inputs.append(tf.placeholder(tf.float32,shape=[None,227,227,3], name="encoder_inputs"))
for j in xrange(num_gpus):
    decoder_input = []
    target_weight = []
    for i in xrange(LSTMConfig.lstm_max_time+1):
        decoder_input.append(tf.placeholder(tf.int32,shape=[None],name="decoder%d"%(i)))
        target_weight.append(tf.placeholder(tf.float32,shape=[None],name="target_weights%d"%(i)))
    target = [decoder_input[i+1] for i in xrange(len(decoder_input)-1)]
    self.decoder_inputs.append(decoder_input)
    self.target_weights.append(target_weight)
    self.targets.append(target)

这是feed_dic:

input_feed = {}
for j in xrange(4): #num_gpus
    batch_x, decoder_input,target_weight = gen_batch.next()
    input_feed[m.encoder_inputs[j].name] = batch_x
    for i in xrange(Config.lstm_max_time+1):
        input_feed[m.decoder_inputs[j][i].name] = decoder_input[:, i]
        input_feed[m.target_weights[j][i].name] = target_weight[i]

if is_train_set:
    loss,_= session.run([m.loss, m.train_op],input_feed) #error occurs
    predict_, = session.run(m.predict,input_feed)

错误详情:

Traceback (most recent call last):
  File "Multi_Gpu_v2.py", line 381, in <module>
    tf.app.run()
  File "/home/rootuser/.virtualenvs/tfpy3/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "Multi_Gpu_v2.py", line 378, in main
    run_epoch(sess, model, reversed_dic,summary_writer,dic,train_set)
  File "Multi_Gpu_v2.py", line 320, in run_epoch
    loss,_= session.run([m.loss, m.train_op],input_feed)
  File "/home/rootuser/.virtualenvs/tfpy3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 767, in run
    run_metadata_ptr)
  File "/home/rootuser/.virtualenvs/tfpy3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 938, in _run
    np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
  File "/home/rootuser/.virtualenvs/tfpy3/lib/python3.5/site-packages/numpy/core/numeric.py", line 482, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.

0 个答案:

没有答案