无法从keras中的检查点模型恢复培训

时间:2018-02-25 12:34:28

标签: model keras resuming-training

我在每个时代保存的模型在精度方面超过了上一个时代。但是当我加载模型时,它不会从保存的模型点恢复。代码如下:

filepath = "weights-improvement-{epoch:02d}-{loss:.2f}.hdf5"
callbacks = ModelCheckpoint(filepath, monitor='loss', verbose=0, save_best_only=True, save_weights_only=True,
                            mode='min')
model = load_model(current_dir + '\\' + 'weights-improvement-45-0.67.hdf5')

#model = load_model(current_dir + '\\' + 'weights-improvement-83-0.01.hdf5')
for j in range(n_repeats):
    csv_logger = CSVLogger('log' + str(i) + '_' + str(j) + '.csv', append=True, separator=';')
    print('training on cell array size' + str(cell_size_array[i]) + 'repeat of ' + str(j))

    history = model.fit_generator(get_input_output_spect_yeild(param_dict['dat_dir_train'],meanAbs,stdAbs,meanPhase,stdPhase ),
                                  validation_data=get_input_output_spect_yeild(param_dict['dat_dir_validation'],meanAbs,stdAbs,meanPhase,stdPhase),
                                  validation_steps=val_per_ep, steps_per_epoch=step_per_ep, epochs=num_epochs,
                                  verbose=1, callbacks=[csv_logger, callbacks])

1 个答案:

答案 0 :(得分:0)

在使用model.fit_generator之前,您必须使用保存的权重加载模型。 model.load_weights('最佳体重的路径')