蒸馏模型训练报错
收藏
用的paddleslim现成的蒸馏函数,训练的时候报错----------------------
Error Message Summary:
----------------------
InvalidArgumentError: The Tensor in the conv2d Op's Input Variable Input(teacher_data) is not initialized.
[Hint: Expected t->IsInitialized() == true, but received t->IsInitialized():0 != true:1.] at (/paddle/paddle/fluid/framework/operator.cc:1289)
[operator < conv2d > error]
#3. 从模型中获取预测程序、输入数据名称列表、分类器
save_path = "/home/aistudio/Best_model2"
[teacher_program, feeded_var_names, predict] = fluid.io.load_inference_model(dirname=save_path, executor=exe)
exe = fluid.Executor(fluid.CUDAPlace(0))
# 4. 合并program (merge)并添加蒸馏loss
data_name_map = {'image': 'image'}
main = slim.dist.merge(teacher_program, student_program, data_name_map, fluid.CUDAPlace(0))
with fluid.program_guard(student_program, student_startup):
l2_loss = slim.dist.fsp_loss('teacher_batch_norm_1.tmp_3', 'teacher_depthwise_conv2d_0.tmp_0','depthwise_conv2d_0.tmp_0','batch_norm_1.tmp_3', student_program)
loss = l2_loss + avg_cost
opt = fluid.optimizer.Momentum(0.01, 0.9)
opt.minimize(loss)
exe.run(student_startup)
# # 5. 模型训练
train_reader = paddle.batch(paddle.reader.shuffle(reader=reader1.train_reader('/home/aistudio/data/data53121/target/train.list', 256, 224), buf_size=128), batch_size=32, drop_last=True)
train_feeder = fluid.DataFeeder(place=place, feed_list=[image, label])
train_step = 0
for epoch in range(20):
print("epoch=",epoch+1)
outputs = [avg_cost.name, acc_top1.name]
for data in train_reader():
train_cost, train_acc = exe.run(student_program, feed=train_feeder.feed(data), fetch_list = outputs)
# 每1个batch打印一次信息
print('Iterate:%d, Cost:%0.5f, Accuracy:%0.5f' %(train_step, train_cost[0], train_acc[0]))
train_step = train_step+1
0
收藏
请登录后评论
使用最新的版本来尝试吧~