keras服务器用fit_generator跑的代码,loss,acc曲线图的保存

import matplotlib.pyplot as plt


...   //数据处理代码  省略

history = model.fit_generator(
    image_generator, steps_per_epoch=2000 // 32  ,
    epochs=16, verbose=1,
    validation_data=image_generator_TEST, validation_steps=20
)


print(history.history.keys())
plt.switch_backend('agg')    #服务器上面保存图片  需要设置这个
//acc
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.savefig('acc.jpg')
//loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.savefig('loss.jpg')

 

 

 

你可能感兴趣的:(keras)