当前位置:网站首页>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 """
边栏推荐
- What does openid mean? What does "token" mean?
- wav文件(波形文件)格式分析与详解
- 自定义注解之编译时注解(RetentionPolicy.CLASS)
- 通过客户经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
- IC研发常用英文术语缩写
- 从别人库里拷贝的游戏如何再自己的库里显示
- Notes on key words in the original English work biography of jobs (IV) [chapter two]
- How to design test cases
- Le labyrinthe des huit diagrammes de la bataille de cazy Chang'an
- C language "Recursion Series": recursively realizing the n-th power of X
猜你喜欢

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

Various synchronous learning notes

Unity发布webGL的时候JsonConvert.SerializeObject()转换失败

WebGL谷歌提示内存不够(RuntimeError:memory access out of bounds,火狐提示索引超出界限(RuntimeError:index out of bounds)

(翻译)采用字母间距提高全大写文本可读性的方式

How to solve the 10061 error of MySQL in Linux

【无标题】**数据库课设:三天完成学生信息管理系统**

【OpenCV】—离散傅里叶变换

How to design test cases

Check whether the point is within the polygon
随机推荐
openid是什么意思?token是什么意思?
《乔布斯传》英文原著重点词汇笔记(二)【 chapter one】
在华泰证券上面开户好不好,安不安全?
【无标题】**数据库课设:三天完成学生信息管理系统**
Lvs-dr mode multi segment case
cazy長安戰役八卦迷宮
Sharepoint:sharepoint server 2013 and adrms Integration Guide
Notes on key words in the original English work biography of jobs (II) [chapter one]
微信小程序_7,项目练习,本地生活
SharePoint:SharePoint 2013 with SP1 简易安装
云网络技术的好处以及类型
从别人库里拷贝的游戏如何再自己的库里显示
How to increase the monthly salary of software testing from 10K to 30K? Only automated testing can do it
一、单个神经元网络构建
C#启动程序传递参数丢失双引号,如何解决?
Sharepoint:sharepoint 2013 with SP1 easy installation
Is it safe for Huatai Securities to open a stock account on it?
Discrimination of configuration, software configuration items and software configuration management items
[operation tutorial] how does the tsingsee Qingxi video platform import the old database into the new database?
声纹技术(五):声纹分割聚类技术