1

当模型在准确性方面超过前一个时期时,我会在每个时期保存模型。但是当我加载模型时,它不会从保存的模型点恢复。代码如下:

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])
4

1 回答 1

0

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

于 2019-07-11T17:15:59.057 回答