I would like to load a model and display it in a plot. Unfortunately I get an error.
Why does this error occur at this point (Usually he should know?) and how do I solve it?
I've already investigated this bug and looked for questions like Python Math - TypeError: 'NoneType' object is not subscriptable
Why am I getting this error here history.history['loss']
? Usually he should know that!
Error:
training_loss = history.history['loss']
TypeError: 'NoneType' object is not subscriptable
Code:
def load_model():
history = tf.keras.models.load_model(path)
return model
def get_loss(history):
# Get training and test loss histories
training_loss = history.history['loss'] # here is the error
test_loss = history.history['val_loss']
# Create count of the number of epochs
epoch_count = range(1, len(training_loss) + 1)
# Visualize loss history
plt.plot(epoch_count, training_loss, 'r--')
plt.plot(epoch_count, test_loss, 'b-')
plt.legend(['Training Loss', 'Test Loss'])
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.show();
get_loss(load_model)
Edit:
history = model.fit(...)
model.save(model_file, overwrite=True)