当前位置:网站首页>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 """
边栏推荐
- [MySQL] understanding and use of indexes
- mysql之Unknown table ‘COLUMN_STATISTICS‘ in information_schema (1109)
- 云网络技术的好处以及类型
- 【OpenCV】—离散傅里叶变换
- To achieve good software testing results, it is a prerequisite to build a good testing environment
- 各种同步学习笔记
- 某次比赛wp
- Exchange:管理日历权限
- A 35 year old Tencent employee was laid off and sighed: a suite in Beijing, with a deposit of more than 7 million, was anxious about unemployment
- Notes on key vocabulary of the original English work biography of jobs (I) [introduction]
猜你喜欢
Check whether the point is within the polygon
About i/o -- the relationship between memory and CPU and disk
How to solve the 10061 error of MySQL in Linux
Unity--Configurable Joint——简单教程,带你入门可配置关节
【操作教程】TSINGSEE青犀视频平台如何将旧数据库导入到新数据库?
C language: count the number of words in a paragraph
UEFI: repair efi/gpt bootloader
Fault: 0x800ccc1a error when outlook sends and receives mail
如何设计测试用例
对常用I/O模型进行比较说明
随机推荐
Check whether the point is within the polygon
nodejs 使用Express框架demo
【期末复习笔记】数字逻辑
自定义注解之编译时注解(RetentionPolicy.CLASS)
Unity--configurable joint -- a simple tutorial to get you started with configurable joints
《乔布斯传》英文原著重点词汇笔记(三)【 chapter one】
【MYSQL】事务的理解
开户券商怎么选择?在线开户是安全么?
【MYSQL】索引的理解和使用
Is it safe for Huatai Securities to open a stock account on it?
How to design test cases
微信小程序_7,项目练习,本地生活
各种同步学习笔记
买股票通过客户经理的开户二维码开户资金是否安全?想开户炒股
声纹技术(七):声纹技术的未来
声纹技术(一):声纹技术的前世今生
《乔布斯传》英文原著重点词汇笔记(五)【 chapter three 】
《乔布斯传》英文原著重点词汇笔记(六)【 chapter three 】
C language "Recursion Series": recursively realizing the n-th power of X
Exchange: manage calendar permissions