天天看點

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')      

繼續閱讀