0

I would like to train a model with Keras starting from pretrained weights (for example if already 50 epochs are done and I would like to train another 50 epochs, that the second training can start from the weights of the first training). How do I have to include the previous .h5 file with the weights in the fit generator?

callbacks_list = [
ModelCheckpoint(top_weights_path, monitor='val_loss', verbose=1, save_best_only=True),
TensorBoard(log_dir=logs, batch_size=batch_size, histogram_freq=0, write_graph=True, write_grads=True, write_images=True),
ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=500, verbose=1)]


model.fit_generator(train_gen,
                steps_per_epoch=len(listREFPaths[:-val_split]),
                epochs=nb_epoch,
                callbacks=callbacks_list,
                validation_data=val_gen if use_val_gen else (X_val_data, y_val_data),
                validation_steps=len(listREFPaths[-val_split:]),
                shuffle=rnd_shuffle,
                verbose=1)

In this discussion (https://github.com/keras-team/keras/issues/2378), I don't find an answer.

SteC
  • 841
  • 1
  • 6
  • 8
  • not really, if I understand this well, this is meant for loading trained weights for inference, I would like to load weights to continue training – SteC Nov 05 '19 at 10:23
  • I am not too familiar with kears, but I think it should be possible to load the weights and just call the fit afterwards. I mean maybe just test it. Also you know now how to save the weights. – Nils Nov 05 '19 at 10:28
  • Its literally the same thing, you load the pre-trained weights, and then continue training. load_weights and then fit/fit_generator – Dr. Snoopy Nov 05 '19 at 10:30
  • So, for example I just have to write model.load_weights(path,by_name=False) in front of the model.fit_generator(...) command? Thanks! – SteC Nov 05 '19 at 10:39

0 Answers0