0

I want to save the results of my experiments in keras not the model. For example, I want to save everything that results from:

''' Plots '''
if plot:
    # Plots for training and testing process: loss and accuracy
    plt.figure(0)
    plt.plot(cnn.history['acc'],'r')
    plt.plot(cnn.history['val_acc'],'g')
    plt.xticks(np.arange(0, nb_epochs+1, 2.0))
    plt.rcParams['figure.figsize'] = (8, 6)
    plt.xlabel("Num of Epochs")
    plt.ylabel("Accuracy")
    plt.title("Training Accuracy vs Validation Accuracy")
    plt.legend(['train','validation'])


    plt.figure(1)
    plt.plot(cnn.history['loss'],'r')
    plt.plot(cnn.history['val_loss'],'g')
    plt.xticks(np.arange(0, nb_epochs+1, 2.0))
    plt.rcParams['figure.figsize'] = (8, 6)
    plt.xlabel("Num of Epochs")
    plt.ylabel("Loss")
    plt.title("Training Loss vs Validation Loss")
    plt.legend(['train','validation'])

how do I save all that so I can plot the plots again and inspect what happened during training?

the website:

https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model

doesn't seem to explain it...help?

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323

1 Answers1

1

The pickle module lets you serialize python objects.

You can save the history with:

pkl.dump(cnn.history, file_obj)

If you want to save your plots as an image:

plt.savefig(path)

You can also try to pickle matplotlib Figure/Axes objects to recreate the interactive plots but this feature is experimental. I would suggest just pickling your history dict and then regenerating the plots with your code above.

Primusa
  • 13,136
  • 3
  • 33
  • 53