Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

fluid python预测报错

Open Angus07 opened this issue 8 years ago • 4 comments

我的data格式是: data1 = fluid.layers.data( name="title1", shape=[1], dtype="int64", lod_level=1)

使用了https://github.com/PaddlePaddle/models/blob/develop/fluid/text_classification/utils.py 这个例子中使用的函数,我理解和这个任务是非常相似的。

def to_lodtensor(data, place): """ convert to LODtensor """ seq_lens = [len(seq) for seq in data] cur_len = 0 lod = [cur_len] for l in seq_lens: cur_len += l lod.append(cur_len) print >> sys.stderr, lod flattened_data = np.concatenate(data, axis=0).astype("int64") flattened_data = flattened_data.reshape([len(flattened_data), 1]) print >> sys.stderr, flattened_data res = fluid.LoDTensor() res.set(flattened_data, place) res.set_lod([lod]) print >> sys.stderr, res return res

其中我data打印出来是 data:[[1764, 44097, 12517]] lod :[0, 3] flattened_data:[[ 1764] [44097] [12517]]

但是结果却报错了 File "/home/du/chenliangyu/python27-gcc482/lib/python2.7/site-packages/paddle/fluid/executor.py", line 470, in run self.executor.run(program.desc, scope, 0, True, True) paddle.fluid.core.EnforceNotMet: Enforce failed. Expected table_dims.size() == 2, but received table_dims.size():1 != 2:2. at [/paddle/paddle/fluid/operators/lookup_table_op.cc:37]

Angus07 avatar Oct 11 '18 09:10 Angus07

应该是embedding layer的size给错了,应该是两维而不是一维

kuke avatar Oct 11 '18 10:10 kuke

那这个要怎么解决呢?是哪一步操作有问题?

Angus07 avatar Oct 11 '18 10:10 Angus07

@Angus07 https://github.com/PaddlePaddle/Paddle/blob/f90c7865f0ababccd89332604e7e181c85cf9b60/benchmark/fluid/models/machine_translation.py#L83

请检查一下embedding的size是不是这么给的

kuke avatar Nov 10 '18 04:11 kuke

Closed due to inactivity

kuke avatar Nov 22 '18 07:11 kuke