增量训练中添加optimizer后报错
Created by: leaf918
` with fluid.program_guard(self.train_program, self.startup_program): self.image = fluid.layers.data(name='image', shape=[3, 224, 224], dtype='float32') self.label = fluid.layers.data(name='label', shape=[1], dtype='int64') # model definition ++++++++++++++++++++++++++++++++++++++++++ model = models.dictmodel_name out = model.net(input=self.image, class_dim=class_dim) # 概率数组 # cost, pred = fluid.layers.softmax_with_cross_entropy( out, self.label, return_softmax=True )
avg_cost = fluid.layers.mean(x=cost)
acc_top1 = fluid.layers.accuracy(input=pred,
label=self.label,
k=1)
acc_top5 = fluid.layers.accuracy(input=pred,
label=self.label,
k=5)
optimizer = fluid.optimizer.SGD(learning_rate=0.01)
optimizer.minimize(avg_cost)
self.parallel_program = compiler.CompiledProgram(self.train_program)
self.parallel_program.with_data_parallel(loss_name=avg_cost.name)
# load pretrained vars,load data to default main program
self.exe = fluid.Executor(self.exe_place)
fluid.io.load_persistables(
self.exe,
output_dir if self.mode == 'inference' else pretrain_dir,
main_program=self.startup_program
)
`
``