当前位置:网站首页>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()
边栏推荐
- [Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
- 要選擇那種語言為單片機編寫程序呢
- 2021-11-11 standard thread library
- STM32 running lantern experiment - library function version
- LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
- 2021-10-28
- STM32 general timer 1s delay to realize LED flashing
- Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
- My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
- Timer and counter of 51 single chip microcomputer
猜你喜欢
在三线城市、在县城,很难毕业就拿到10K
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
03 fastjason solves circular references
Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
Interruption system of 51 single chip microcomputer
YOLO_ V1 summary
2021-10-27
Development of intelligent charging pile (I): overview of the overall design of the system
Yocto Technology Sharing Phase 4: Custom add package support
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
随机推荐
Do you understand automatic packing and unpacking? What is the principle?
Interruption system of 51 single chip microcomputer
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
(2) New methods in the interface
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~
There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way
is_ power_ of_ 2 judge whether it is a multiple of 2
Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy
使用密钥对的形式连接阿里云服务器
My notes on intelligent charging pile development (II): overview of system hardware circuit design
4G module board level control interface designed by charging pile
Simple use of MySQL (addition, deletion, modification and query)
For new students, if you have no contact with single-chip microcomputer, it is recommended to get started with 51 single-chip microcomputer
Application of external interrupts
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
LeetCode - 673. 最长递增子序列的个数
RESNET code details
嵌入式系统没有特别明确的定义
MySQL的简单使用(增删改查)
MySQL 数据库基础知识(系统化一篇入门)