当前位置:网站首页>三、自动终止训练
三、自动终止训练
2022-06-25 07:56:00 【beyond谚语】
有时候,当模型损失函数值预期的效果时,就可以结束训练了,一方面节约时间,另一方面防止过拟合
此时,设置损失函数值小于0.4,训练停止
from tensorflow import keras
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self,epoch,logs={
}):
if(logs.get('loss')<0.4):
print("\nLoss is low so cancelling training!")
self.model.stop_training = True
callbacks = myCallback()
mnist = tf.keras.datasets.fashion_mnist
(training_images,training_labels),(test_images,test_labels) = mnist.load_data()
training_images_y = training_images/255.0
test_images_y = test_images/255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512,activation=tf.nn.relu),
tf.keras.layers.Dense(10,activation=tf.nn.softmax)
])
model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.fit(training_images_y,training_labels,epochs=5,callbacks=[callbacks])
""" Colocations handled automatically by placer. Epoch 1/5 60000/60000 [==============================] - 12s 194us/sample - loss: 0.4729 - acc: 0.8303 Epoch 2/5 59712/60000 [============================>.] - ETA: 0s - loss: 0.3570 - acc: 0.8698 Loss is low so cancelling training! 60000/60000 [==============================] - 11s 190us/sample - loss: 0.3570 - acc: 0.8697 """
边栏推荐
- View all listening events on the current page by browser
- Want to open an account, is it safe to open an online stock account?
- What does openid mean? What does "token" mean?
- 声纹技术(五):声纹分割聚类技术
- 第五天 脚本与UI系统
- wav文件(波形文件)格式分析与详解
- 通过客户经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
- 【总结】1361- package.json 与 package-lock.json 的关系
- How to become a software testing expert? From 3K to 17k a month, what have I done?
- Discrimination of configuration, software configuration items and software configuration management items
猜你喜欢
LVS-DR模式多网段案例
Incluxdb time series database
Unity Addressable批量管理
cazy长安战役八卦迷宫
How to calculate the independence weight index?
What are the indicators of VIKOR compromise?
How to become a software testing expert? From 3K to 17k a month, what have I done?
What are the indicators of entropy weight TOPSIS method?
How to calculate critical weight indicators?
Fault: 0x800ccc1a error when outlook sends and receives mail
随机推荐
The city chain technology platform is realizing the real value Internet reconstruction!
打新债真的安全吗? 风险大吗
GIL问题带来的问题,解决方法
Is there any risk in making new bonds
Check whether the point is within the polygon
声纹技术(一):声纹技术的前世今生
Super simple case: how to do hierarchical chi square test?
To achieve good software testing results, it is a prerequisite to build a good testing environment
《树莓派项目实战》第五节 使用Nokia 5110液晶屏显示Hello World
Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
城链科技平台,正在实现真正意义上的价值互联网重构!
获取扫码的客户端是微信还是支付宝
SwipeRefreshLayout+RecyclerView无法下拉问题排查
InfluxDB时序数据库
QSS 不同风格的按钮
Getting to know the generation confrontation network (11) -- using pytoch to build wgan to generate handwritten digits
Word2vec, phrases, phraser, keyedvectors commonly used in gensim
How to calculate the information entropy and utility value of entropy method?
Go language learning tutorial (13)
初识生成对抗网络(12)——利用Pytorch搭建WGAN-GP生成手写数字