浅谈keras的深度模型训练过程及结果记录方式

作者:sjtu_leexx 时间:2023-08-11 03:17:46 

记录训练过程


history=model.fit(X_train, Y_train, epochs=epochs,batch_size=batch_size,validation_split=0.1)

将训练过程记录在history中

利用时间记录模型


import time
model_id = np.int64(time.strftime('%Y%m%d%H%M', time.localtime(time.time())))
model.save('./VGG16'+str(model_id)+'.h5')

保存模型及结构图


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

绘制训练过程曲线


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

文件记录最终训练结果


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

以字典格式保存训练中间过程


import pickle
file = open('./models/history.pkl', 'wb')
pickle.dump(history.history, file)
file.close()

来源:https://blog.csdn.net/sjtuxx_lee/article/details/80502775

标签:keras,模型,训练
0
投稿

猜你喜欢

  • python广度搜索解决八数码难题

    2023-01-26 18:12:43
  • mysql如何优化插入记录速度

    2024-01-29 07:44:35
  • Go语言Zap库Logger的定制化和封装使用详解

    2024-04-25 15:18:52
  • ASP短日期格式为长日期

    2009-06-11 12:53:00
  • 九宫格基本布局

    2009-06-18 18:36:00
  • python如何读取和存储dict()与.json格式文件

    2021-12-07 16:13:36
  • IPv6设置后如何解决MySQL无法连接localhost的问题

    2024-01-20 00:50:38
  • 淘宝搜索框研究报告

    2010-07-27 12:49:00
  • sql server 2000阻塞和死锁问题的查看与解决方法

    2024-01-20 01:46:45
  • django的登录注册系统的示例代码

    2021-05-14 23:27:59
  • 如何理解python中数字列表

    2023-01-30 13:29:09
  • Python 通过爬虫实现GitHub网页的模拟登录的示例代码

    2022-04-27 00:26:39
  • Python tkinter三种布局实例详解

    2022-11-28 11:23:44
  • 将ASP纪录集输出成n列表格的方法

    2008-03-19 13:27:00
  • 为你总结一些php系统类函数

    2023-11-15 02:22:35
  • python数据库编程 Mysql实现通讯录

    2024-01-24 17:53:11
  • 详解Django+Uwsgi+Nginx 实现生产环境部署

    2022-11-10 10:37:41
  • 全兼容可高亮二级缓冲折叠菜单

    2010-06-03 16:53:00
  • 获取Dom元素的X/Y坐标

    2009-10-10 12:49:00
  • python使用隐式循环快速求和的实现示例

    2022-10-09 13:04:05
  • asp之家 网络编程 m.aspxhome.com