Home > other >  How to draw learning curve with keras rom best model.h5?
How to draw learning curve with keras rom best model.h5?

Time:05-27

I run my EfficentNet model with keras for 20 epochs and store the result in the best model. please could any help me to use the best model for drawing the learning curve? Model stop runs in 15 epochs and I couldn't draw a learning curve, How I can draw a learning curve from bestModel?

# model checkpoint
model_checkpoint = tf.keras.callbacks.ModelCheckpoint(
     filepath = "/content/drive/MyDrive/best_model.h5",
     monitor='val_accuracy',
     verbose=1,
     save_best_only=True,
     save_weights_only=False,mode='max')  

# load model
model = load_model('/content/drive/MyDrive/best_model.h5')
# summarize model
model.summary()

CodePudding user response:

You can't draw a learning curve for a saved model using that model's file. You will have to train the model again. To retrieve training and validation losses for a model, you can use the History object that is returned by the model.fit() function by default. I've provided some sample code below for your reference:

model_history = model.fit(...)
training_loss = model_history.history['loss'])
validation_loss = model_history.history['val_loss']

After obtaining the training and validation losses, you can plot them with a plotting library such as matplotlib.

CodePudding user response:

Learning curve can be drawn only during learning the model. it cann't be drawn from the best model only.

  • Related