浅谈keras的深度模型训练过程及结果记录方式
作者:sjtu_leexx 发布时间:2023-08-11 03:17:46
标签:keras,模型,训练
记录训练过程
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
0
投稿
猜你喜欢
- 1 , javascript字符集:javascript采用的是Unicode字符集编码。为什么要采用这个编码呢?原因很简单,16位的Uni
- 字符串在 Python 中创建字符串对象非常容易。只要将所需的文本放入一对引号中,就完成了一个新字符串的创建(参见清单 1)。如果稍加思考的
- 从官方文档知道linux上面编译安装的mysql默认的连接为100个,这样对于网站的需求来说是远远不够的。 mysql官方告诉我们需要修改m
- 1. 使用readline模块逐行读取流数据1.1. 创建Interface对象在readline模块中,通过Interface对象的使用来
- 在服务器部署时,往往都是在后台运行。当程序发生特定的错误时,我希望能够在日志中查询。因此这里熟悉以下 logging 模块的用法。loggi
- 目录前言typeof是否能正确判断类型?instanceof是否能正确判断类型?Object.prototype.toString.call
- SHOW STATUS 直接在命令行下登陆MySQL运行SHOW STATUS;查询语句,详细如下图 同样的语句还有SHOW V
- 前言XPath,全称XML Path Language,即XML路径语言,它是一门在XML文档中查找信息的语言,它最初是用来搜寻XML文档的
- 本文实现利用python的socketserver这个强大的模块实现套接字的并发,具体内容如下目录结构如下:测试文件请放在server_fi
- 近几天闲着没事开始学了些python,看了看之前写过的代码,把写过的基础的几个程序写进博客,今天是第一个。一个可以说简单的不能再简单的小程序
- 前言在做Vue管理系统的时候,都会遇到的一个需求:每个用户的权限是不一样的,那么他可以访问的页面(路由),可以操作的菜单选项是不一样的,如果
- 1. 安装GO SDK 官方下载地址是:golan.google.cn/dl2. 安装完毕后,会自动在配置文件中加入一些内容,其中比较重要的
- 如下所示:解读: transpose( ) 方法的参数是一个 由 轴编号(轴编号自0 开始) 序列构成的 元组。开始时,数组的轴编号序列是默
- np.zeros()和np.ones()函数由于小阿奇在写代码的时候会碰到一些不清楚的函数和使用方法,所以我决定把自己碰到的问题和解决办法写
- 本文实例讲述了jQuery实现的简单分页。分享给大家供大家参考,具体如下:<!DOCTYPE html PUBLIC "-/
- 问题描述:已经用pip install jieba安装好jieba分词工具,但是在Jupyter 里import jieba运行一直提示Im
- 一、ready函数的实现经常用jQuery类库或其他类库中的ready方法,有时候想想它们到底是怎么实现的,但是看了一下jQuery中的源码
- 昨天打包下载了一个服务器整站,拿到这个*.mdb的文件后,却不知道怎么用,百度了一下,才知道是一种木马打包的形式文件,不能用WINrar来解
- 前言:本博客只是因为我正在上计算机图形学这门课,为了方便复习所写,所以内容的正确性不敢保证,各位观看之前请三思(欢迎大佬提出建议)为VS20
- enumerate函数用于遍历序列中的元素以及它们的下标。enumerate函数说明:函数原型:enumerate(sequence, [s