淺談keras的深度模型訓(xùn)練過程及結(jié)果記錄方式
記錄訓(xùn)練過程
history=model.fit(X_train, Y_train, epochs=epochs,batch_size=batch_size,validation_split=0.1)
將訓(xùn)練過程記錄在history中
利用時(shí)間記錄模型
import time
model_id = np.int64(time.strftime('%Y%m%d%H%M', time.localtime(time.time())))
model.save('./VGG16'+str(model_id)+'.h5')
保存模型及結(jié)構(gòu)圖
from keras.utils import plot_model
model.save('/opt/Data1/lixiang/letter_recognition/models/VGG16'+str(model_id)+'.h5')
plot_model(model, to_file='/opt/Data1/lixiang/letter_recognition/models/VGG16'+str(model_id)+'.png')
繪制訓(xùn)練過程曲線
import matplotlib.pyplot as plt
fig = plt.figure()#新建一張圖
plt.plot(history.history['acc'],label='training acc')
plt.plot(history.history['val_acc'],label='val acc')
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(loc='lower right')
fig.savefig('VGG16'+str(model_id)+'acc.png')
fig = plt.figure()
plt.plot(history.history['loss'],label='training loss')
plt.plot(history.history['val_loss'], label='val loss')
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(loc='upper right')
fig.savefig('VGG16'+str(model_id)+'loss.png')
文件記錄最終訓(xùn)練結(jié)果
logFilePath = './log.txt'
fobj = open(logFilePath, 'a')
fobj.write('model id: ' + str(model_id)+'\n')
fobj.write('epoch: '+ str(epochs) +'\n')
fobj.write('x_train shape: ' + str(X_train.shape) + '\n')
fobj.write('x_test shape: ' + str(X_test.shape)+'\n')
fobj.write('training accuracy: ' + str(history.history['acc'][-1]) + '\n')
fobj.write('model evaluation results: ' + str(score[0]) + ' ' +str(score[-1])+'\n')
fobj.write('---------------------------------------------------------------------------\n')
fobj.write('\n')
fobj.close()
以字典格式保存訓(xùn)練中間過程
import pickle
file = open('./models/history.pkl', 'wb')
pickle.dump(history.history, file)
file.close()
以上這篇淺談keras的深度模型訓(xùn)練過程及結(jié)果記錄方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
django中使用Celery 布式任務(wù)隊(duì)列過程詳解
這篇文章主要介紹了django中使用Celery 布式任務(wù)隊(duì)列實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07
可視化工具PyVista多線程顯示多窗口的實(shí)例代碼
這篇文章主要介紹了可視化工具PyVista多線程顯示多窗口,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
NetWorkX使用方法及nx.draw()相關(guān)參數(shù)解讀
這篇文章主要介紹了NetWorkX使用方法及nx.draw()相關(guān)參數(shù)解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
Python計(jì)算公交發(fā)車時(shí)間的完整代碼
這篇文章主要介紹了Python計(jì)算公交發(fā)車時(shí)間的完整代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-02-02
uwsgi+nginx部署Django項(xiàng)目操作示例
這篇文章主要介紹了uwsgi+nginx部署Django項(xiàng)目操作,結(jié)合實(shí)例形式簡(jiǎn)單介紹了uwsgi的概念、原理、安裝、項(xiàng)目創(chuàng)建、配置、調(diào)試運(yùn)行等相關(guān)操作技巧,需要的朋友可以參考下2018-12-12
淺談Django QuerySet對(duì)象(模型.objects)的常用方法
這篇文章主要介紹了淺談Django QuerySet對(duì)象(模型.objects)的常用方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03
用Python進(jìn)行基礎(chǔ)的函數(shù)式編程的教程
這篇文章主要介紹了用Python進(jìn)行基礎(chǔ)的函數(shù)式編程的教程,除了面向?qū)ο缶幊桃馔狻ython還可以進(jìn)行簡(jiǎn)單的不依賴外部變量的函數(shù)式編程,本文介紹了其中的一些基礎(chǔ),需要的朋友可以參考下2015-03-03

