自定义数据集与官方文档输出一致,却报The last dimensions of the 'Ids' tensor must be 1
Created by: 131250208
使用的自定义数据集,依照官方文档的数据定义如下:
# 自定义的生成器
def my_reader(features, labels):
def gen():
for ind, f in enumerate(features):
yield f, labels[ind]
return gen
BATCH_SIZE = 20
train_reader = paddle.batch(
paddle.reader.shuffle(
my_reader(features_train, labels_train), buf_size=500),
batch_size=BATCH_SIZE)
test_reader = paddle.batch(
paddle.reader.shuffle(
my_reader(features_dev, labels_dev), buf_size=500),
batch_size=BATCH_SIZE)
reader的输出:
next(train_reader())[0]
# (array([0.8967, 0.7465, 0.8835]), 2)
我尝试了一下官方案例的手写数字识别数据的输出,输出的格式是一致的,不知道为什么会报错。 这是我的variable定义:
feed_order = ['confs', 'label']
confs = fluid.data(name = feed_order[0], shape = [None, 3], dtype = "float32")
label = fluid.data(name = feed_order[1], shape = [None, 1], dtype = "int64")
报错代码的行:
for batch_id, data in enumerate(train_reader()):
metrics = exe.run(main_program,
feed = feeder.feed(data),
fetch_list = [avg_loss, accuracy])