Why can't save model when 'save_best_only=True' in ModelCheckpoint function?

时间:2019-06-01 14:03:29

标签: python keras checkpoint

I use keras to build an autoencoder model.

I want to save my model by using ModelCheckpoint function.

When I set the parameter 'save_best_only=True', the model can't be saved.

autoencoder.compile(optimizer='adam', 
                    loss='mean_squared_error', 
                    metrics=['accuracy'])

AE_checkpointer = ModelCheckpoint(filepath="AE_simulation.h5",
                               verbose=0,
                               save_best_only=True,
                               mode=max)
history = autoencoder.fit(X_normal_train,X_normal_train,
                    epochs=nb_epoch,
                    batch_size=batch_size,
                    shuffle=True,  
                    verbose=1,
                    callbacks=[AE_checkpointer])  
autoencoder = load_model('AE_simulation.h5')  
OSError: Unable to open file (unable to open file: name 
= 'AE_simulation.h5', errno = 2, 
error message = 'No such file or directory', flags = 0, o_flags = 0)

But when I set the parameter 'save_best_only=False', the model can be saved.

autoencoder.compile(optimizer='adam', 
                    loss='mean_squared_error', 
                    metrics=['accuracy'])

AE_checkpointer = ModelCheckpoint(filepath="AE_simulation.h5",
                               verbose=0,
                               save_best_only=False,
                               mode=max)
history = autoencoder.fit(X_normal_train,X_normal_train,
                    epochs=nb_epoch,
                    batch_size=batch_size,
                    shuffle=True,  
                    verbose=1,
                    callbacks=[AE_checkpointer])  
autoencoder = load_model('AE_simulation.h5')  

WHY???

0 个答案:

没有答案