当前位置:网站首页>Modelcheckpoint auto save model
Modelcheckpoint auto save model
2022-07-03 10:03:00 【Master Hao】
-- coding: utf-8 --
import tensorflow as tf
import json
import tensorflow.keras.models
from tensorflow.keras.callbacks import *
# This is a separate package
import tensorflow.keras
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=‘relu’),
tf.keras.layers.Dense(10, activation=‘softmax’)
])
model.compile(optimizer=‘adam’,
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),
metrics=[‘sparse_categorical_accuracy’])
#Callbacks Used to specify in each epoch or batch What is the specific operation to be performed at the beginning and the end
‘’’
Parameters monitor You can set {‘val_accuracy’,‘val_loss’,‘accuracy’,‘loss’}.
If monitoring is set {‘val_accuracy’,‘accuracy’}, Then the accuracy of the model is greater than the maximum {‘val_accuracy’,‘accuracy’} The model will be saved when ;
If monitoring is set {‘val_loss’,‘loss’}, So the model loss Less than the minimum {‘val_loss’,‘loss’} The model will be saved when .
‘’’
ModelCheckpoint Used to automatically save the model
filepath You can set the model storage location and model information ,epoch Indicates the number of training cycles ,val_accuracy Indicates the exact value of the validation set
monitor Optional {‘val_accuracy’,‘val_loss’,‘accuracy’,‘loss’}, commonly ’val_accuracy’ Used a lot
verbose=1 It means printing information when saving the model
save_best_only=True Means save only >best_val_accuracy Model of
CSVLogger It's also callbacks, For generating model training log
‘’’
loss: Training set loss value
accuracy: Training set accuracy
val_loss: Test set loss value
val_accruacy: Test set accuracy
‘’’
# The saved variable name should be consistent with the variable name during training
callbacks = [
ModelCheckpoint(filepath=‘C:/Users/25360/Desktop/model/’+’{epoch:02d}-{sparse_categorical_accuracy:.4f}.h5’,
monitor=‘val_sparse_categorical_accuracy’,
verbose=1,
save_best_only=True)
]
model.fit(x_train, y_train, batch_size=32, epochs=5, validation_data=(x_test, y_test),
validation_freq=1,callbacks=callbacks)
model.summary()
边栏推荐
- It is difficult to quantify the extent to which a single-chip computer can find a job
- Gpiof6, 7, 8 configuration
- Uniapp realizes global sharing of wechat applet and custom sharing button style
- JS基础-原型原型链和宏任务/微任务/事件机制
- getopt_ Typical use of long function
- STM32 general timer 1s delay to realize LED flashing
- yocto 技术分享第四期:自定义增加软件包支持
- Simple use of MySQL (addition, deletion, modification and query)
- Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
- My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
猜你喜欢

当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学

Pymssql controls SQL for Chinese queries

Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode

嵌入式系统没有特别明确的定义

There is no specific definition of embedded system

Retinaface: single stage dense face localization in the wild

2. Elment UI date selector formatting problem

Development of intelligent charging pile (I): overview of the overall design of the system

03 FastJson 解决循环引用

My notes on intelligent charging pile development (II): overview of system hardware circuit design
随机推荐
2021-11-11 standard thread library
Project cost management__ Topic of comprehensive calculation
Simple use of MySQL (addition, deletion, modification and query)
Basic knowledge of communication interface
Windows下MySQL的安装和删除
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
51 MCU tmod and timer configuration
CEF download, compile project
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)
MySQL root user needs sudo login
Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?
[combinatorics] combinatorial existence theorem (three combinatorial existence theorems | finite poset decomposition theorem | Ramsey theorem | existence theorem of different representative systems |
单片机学到什么程度能找到工作,这个标准不好量化
内存数据库究竟是如何发挥内存优势的?
Vscode markdown export PDF error
yocto 技术分享第四期:自定义增加软件包支持
嵌入式系统没有特别明确的定义
Problems encountered when MySQL saves CSV files
03 fastjason solves circular references