Search code examples
pythontensorflowmetrics

How to plot accuracy with a trained model


I have a Tensorflow model already trained in my notebook, and I want to plot accuracy and loss after that.

Here is my code:

myGene = trainGenerator(2,'/content/data/membrane/train','image','label',
                       data_gen_args,save_to_dir = None)
model = unet()
model_checkpoint = ModelCheckpoint('unet_membrane.hdf5', 
                             monitor='loss',verbose=1, save_best_only=True)
model.fit_generator(myGene,steps_per_epoch=2000,
                    epochs=5,callbacks=[model_checkpoint])

Is there a way to plot anything? Because I tried with matplotlib and it doesn't work.

import matplotlib.pyplot as plt

plt.plot(history['accuracy'])
plt.plot(history['loss'])

Solution

  • Try this:

    history = model.fit_generator(myGene,
                  steps_per_epoch=2000,
                  epochs=5,callbacks=[model_checkpoint])
    

    and then, for plotting:

    plt.plot(history.history['accuracy'])
    plt.plot(history.history['loss'])