DataFeeder使用报错
Created by: WangTaoSpace
使用DataFeeder报错。设置batch_size为1时能够正常执行,超过1便报如下错误。
File "C:/Users/86151/PycharmProjects/cluster_icnet/resnet_hermes.py", line 340, in train_loop
results = exe.run(program= main_program,feed = feeder.feed(data), fetch_list=[reduced_loss])
File "C:\install\python_3.6\lib\site-packages\paddle\fluid\data_feeder.py", line 198, in feed
ret_dict[each_name] = each_converter.done()
File "C:\install\python_3.6\lib\site-packages\paddle\fluid\data_feeder.py", line 73, in done
arr = numpy.array(self.data, dtype=self.dtype)
ValueError: setting an array element with a sequence.
具体程序如下
image = fluid.layers.data(name='image', shape=data_shape, dtype='float32')
label_0 = fluid.layers.data(name='label_0', shape=[data_shape[1],data_shape[2]], dtype='int32')
label_1 = fluid.layers.data(name='label_1', shape=[data_shape[1],data_shape[2]], dtype='int32')
mask_0 = fluid.layers.data(name='mask_0', shape=[-1], dtype='int32')
mask_1 = fluid.layers.data(name='mask_1', shape=[-1], dtype='int32')
model = resnet()
predict = model.net(image,num_classes,(data_shape[1],data_shape[2]))
loss_0 = create_loss(predict,label_0, num_classes,mask_0)
loss_1 = create_loss(predict,label_1, num_classes,mask_1)
reduced_loss = k0*loss_0 + k1*loss_1
regularizer = fluid.regularizer.L2Decay(0.0001)
optimizer = fluid.optimizer.SGD(learning_rate=0.2,regularization=regularizer)
# optimizer = fluid.optimizer.Momentum(
# learning_rate=poly_decay(), momentum=0.9, regularization=regularizer)
_, params_grads = optimizer.minimize(reduced_loss, no_grad_set=no_grad_set)
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
if training_role == "PSERVER":
place = fluid.CPUPlace()
exe = fluid.Executor(place)
def train_loop(main_program):
"""
train_loop
"""
train_reader = paddle.batch(data_create(),
batch_size = batch_size)
feeder = fluid.DataFeeder(place=place,feed_list=[image,label_0,label_1,mask_0,mask_1])
exe.run(fluid.default_startup_program())
if init_model is not None:
print("load model from: %s" % init_model)
sys.stdout.flush()
fluid.io.load_params(exe, init_model)
for pass_id in range(PASS_NUM):
batch_id = 1
for data in train_reader(): #here train_reader is function ,so
#####这里添加对data数据的查看
results = exe.run(program= main_program,feed = feeder.feed(data), fetch_list=[reduced_loss])
if batch_id % LOG_PERIOD == 0:
print("Pass[%d];Iter[%d]; train loss: %.3f"% (pass_id,batch_id, results[0]))
sys.stdout.flush()