5

I have a tensorflow model that saves checkpoints, but I need to to load the weights and save the Kereas .h5 model. How can I do that?

1 Answers1

1

I am assuming you need to convert your previous checkpoint into .h5

Given an already trained model, you want to load its weights and save as .h5. I am assuming you have it saved as a .model file. Lets say it was called first.model

In your script, you will want to use load_model, loading your checkpoint with

model = load_model('first.model')

then you will simply need to use

model.save('goal.h5')

to save as a .h5 file.

For future reference, you can avoid this conversion process by saving checkpoints as .h5:

When using the Checkpoints feature, you have the option to save as either a .model .h5, or .hdf5. The line might look something like this:

checkpoint = ModelCheckpoint("**FILE_NAME_HERE**.model",monitor='val_loss',verbose=1,mode='min',save_best_only=True,save_weights_only=False,period=1)

That is how you save your checkpoint as a .model, but to save it as a h5 as you are looking to do:

checkpoint = ModelCheckpoint("**FILE_NAME_HERE**.h5",monitor='val_loss',verbose=1,mode='min',save_best_only=True,save_weights_only=False,period=1)
George
  • 120
  • 8