为张量列表创建占位符时出现负尺寸错误

时间:2018-07-21 22:45:06

标签: python tensorflow

我通过以下方式为张量列表创建占位符:

self.sample_set = [tf.placeholder(tf.int32, [None,self.max_input_right])
      for _ in xrange(3)]

我通过以下方式将值提供给占位符:

for data in datas:
                    feed_dict = {
                        placeholder : value 
                        for placeholder, value in zip(cnn.sample_set, data[6])
                        }

                    feed_dict.update(
                        {cnn.question: data[0],
                        cnn.answer: data[1],
                        cnn.answer_negative:data[2],
                        cnn.q_position:data[3],
                        cnn.a_pos_position:data[4],
                        cnn.a_neg_position:data[5]
                        }
                        )

在进纸前打印值时,根据要求有值,但仍然给我以下错误:

Traceback (most recent call last):
File "Documents/ExisQACNN/train.py", line 227, in <module>
test_pair_wise()
File "Documents/ExisQACNN/train.py", line 171, in test_pair_wise
feed_dict)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 789, in run
run_metadata_ptr)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 997, in _run
feed_dict_string, options, run_metadata)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1132, in _do_run
target_list, options, run_metadata)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1152, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape [-1,1490] has negative dimensions
 [[Node: Placeholder_1 = Placeholder[dtype=DT_INT32, shape=[?,1490], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

Caused by op u'Placeholder_1', defined at:
File "Documents/ExisQACNN/train.py", line 227, in <module>
test_pair_wise()
File "Documents/ExisQACNN/train.py", line 113, in test_pair_wise
cnn.build_graph()
File "/nfs/stak/users/chattepu/Documents/ExisQACNN/QA_CNN_pairwise.py", line 401, in build_graph
self.create_placeholder()
File "/nfs/stak/users/chattepu/Documents/ExisQACNN/QA_CNN_pairwise.py", line 52, in create_placeholder
for _ in xrange(9)]
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1530, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1954, in _placeholder
name=name)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2506, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/nfs/stak/users/chattepu/tensorflow_1/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1269, in __init__
self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Shape [-1,1490] has negative dimensions
 [[Node: Placeholder_1 = Placeholder[dtype=DT_INT32, shape=[?,1490], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

我无法理解导致负尺寸错误的原因。

0 个答案:

没有答案