这实际上不是这个问题...... CNTK python api - continue training a model它们是相关的,但是它们不一样。
我训练了一个模型 1500 个 epoch,平均损失 67% 左右。然后我想继续训练,我编码如下:
def Create_Trainer(train_reader, minibatch_size, epoch_size, checkpoint_path=None, distributed_after=INFINITE_SAMPLES):
#Create Model with Params
lr_per_minibatch = learning_rate_schedule(
[0.01] * 10 + [0.003] * 10 + [0.001], UnitType.minibatch, epoch_size)
momentum_time_constant = momentum_as_time_constant_schedule(
-minibatch_size / np.log(0.9))
l2_reg_weight = 0.0001
input_var = input_variable((num_channels, image_height, image_width))
label_var = input_variable((num_classes))
feature_scale = 1.0 / 256.0
input_var_norm = element_times(feature_scale, input_var)
z = create_model(input_var_norm, num_classes)
#Create Error Functions
if(checkpoint_path):
print('Loaded Checkpoint!')
z.load_model(checkpoint_path)
ce = cross_entropy_with_softmax(z, label_var)
pe = classification_error(z, label_var)
#Create Learner
learner = momentum_sgd(z.parameters,
lr=lr_per_minibatch, momentum=momentum_time_constant,
l2_regularization_weight=l2_reg_weight)
if(distributed_after != INFINITE_SAMPLES):
learner = distributed.data_parallel_distributed_learner(
learner = learner,
num_quantization_bits = 1,
distributed_after = distributed_after
)
input_map = {
input_var: train_reader.streams.features,
label_var: train_reader.streams.labels
}
return Trainer(z, ce, pe, learner), input_map
注意代码行: if(checkpoint_path): 大约一半。
我从以前的培训中加载了 .dnn 文件,该文件是通过此功能保存的...
if current_epoch % checkpoint_frequency == 0:
trainer.save_checkpoint(os.path.join(checkpoint_path + "_{}.dnn".format(current_epoch)))
这实际上会生成一个 .dnn 和一个 .dnn.ckp 文件。显然我只在load_model中加载了.dnn文件。
当我重新开始训练并加载模型时,它似乎正在加载网络架构,但可能不是权重?这样做的正确方法是什么?
谢谢!