trainer.restore_from_checkpoint
在 CNTK中调用时出现以下异常。
'This' 函数与从检查点恢复的函数不等价(同构)。
我的恢复代码在下面。这些与本文档中提到的创建训练器和保存方法trainer.dnn
的结构相同。trainer.save_checkpoint("trainer.dnn")
def evaluate(reader, model):
criterion = create_criterion_function(model)
criterion.replace_placeholders({criterion.placeholders[0]: Input(input_dim),
criterion.placeholders[1]: Input(label_dim)})
# training config
epoch_size = 34
minibatch_size = 17
# LR schedule over epochs
lr_per_sample = [0.003]*4+[0.0015]*24+[0.0003]
lr_per_minibatch = [x * minibatch_size for x in lr_per_sample]
lr_schedule = learning_rate_schedule(lr_per_minibatch, UnitType.minibatch, epoch_size)
# Momentum
momentum_as_time_constant = momentum_as_time_constant_schedule(70)
learner = adam_sgd(criterion.parameters,
lr=lr_schedule, momentum=momentum_as_time_constant,
low_memory=True,
gradient_clipping_threshold_per_sample=15, gradient_clipping_with_truncation=True)
trainer = Trainer(model, criterion.outputs[0], criterion.outputs[1], learner)
trainer.restore_from_checkpoint("trainer.dnn")
def do_test():
reader = create_reader('Test.txt', is_training=False)
model = create_model()
evaluate(reader, model)
do_test()