当前位置:网站首页>3、 Automatically terminate training
3、 Automatically terminate training
2022-06-25 08:51:00 【Beyond proverb】
occasionally , When the model loses the expected effect of the function value , You can finish your training , On the one hand, save time , On the other hand, prevent over fitting
here , Set the loss function value to be less than 0.4, Training stopped
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 """
边栏推荐
- 获取扫码的客户端是微信还是支付宝
- 打新债真的安全吗? 风险大吗
- Unity--Configurable Joint——简单教程,带你入门可配置关节
- Notes on key words in the original English work biography of jobs (V) [chapter three]
- mysql之Unknown table ‘COLUMN_STATISTICS‘ in information_schema (1109)
- 故障:Outlook 收发邮件时的 0x800CCC1A 错误
- 买股票通过客户经理的开户二维码开户资金是否安全?想开户炒股
- Cazy eight trigrams maze of Chang'an campaign
- Sharepoint:sharepoint 2013 with SP1 easy installation
- UEFI:修复 EFI/GPT Bootloader
猜你喜欢

【OpenCV】—输入输出XML和YAML文件

Lvs-dr mode multi segment case

城鏈科技平臺,正在實現真正意義上的價值互聯網重構!

¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!

Meaning of Jieba participle part of speech tagging

2021 "Ai China" selection

C language: count the number of words in a paragraph

LVS-DR模式单网段案例

Emergency administrative suspension order issued Juul can continue to sell electronic cigarette products in the United States for the time being

【无标题】**数据库课设:三天完成学生信息管理系统**
随机推荐
Check whether the point is within the polygon
紧急行政中止令下达 Juul暂时可以继续在美国销售电子烟产品
Le labyrinthe des huit diagrammes de la bataille de cazy Chang'an
某次比赛wp
声纹技术(五):声纹分割聚类技术
(translation) the use of letter spacing to improve the readability of all capital text
View all listening events on the current page by browser
在哪个平台买股票开户安全?求分享
各种同步学习笔记
【强化学习笔记】强化学习中的常见符号
The city chain technology platform is realizing the real value Internet reconstruction!
To achieve good software testing results, it is a prerequisite to build a good testing environment
What is the difference between TP5 and tp6?
声纹技术(二):音频信号处理基础
cazy長安戰役八卦迷宮
Unity发布webGL的时候JsonConvert.SerializeObject()转换失败
Level 6 easy to mix words
Is it really safe to pay new debts? Is it risky
Discrimination of configuration, software configuration items and software configuration management items
tp6自动执行的文件是哪个?tp6核心类库有什么作用呢?