当前位置:网站首页>Fashion classification case based on keras
Fashion classification case based on keras
2022-04-23 17:53:00 【Stephen_ Tao】
Keras Introduce
Keras It's a use. Python Write an open source neural network library . It can run on TensorFlow,Microsoft Cognitive Toolkit,Theano or PlaidML above .
Introduction to fashion classification dataset

The dataset contains 70000 Gray scale image , Altogether 10 Categories .
Step analysis and code implementation
Reading data sets
from tensorflow.python.keras.datasets import fashion_mnist
class SingleNN(object):
def __init__(self):
(self.train,self.train_label),(self.test,self.test_label) = fashion_mnist.load_data()
self.train = self.train / 255.0
self.test = self.test / 255.0
Training data , The shape of the test data is as follows :
train: (60000, 28, 28)
train_label: (60000,)
test: (10000, 28, 28)
test_label: (10000,)
model building
Model structure : Double layer neural network
- Hidden layer are 128 Neurons , Activate function selection relu
- Full connection layer has 10 Neurons , because fashion_mnist have 10 Categories , Activate function selection softmax
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Flatten,Dense
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
class SingleNN(object):
model = Sequential([
Flatten(input_shape=(28,28)),
Dense(128,activation=tf.nn.relu),
Dense(10,activation=tf.nn.softmax)
])
Compile and define the optimization process
Optimizer selection Adam, The loss function selects the cross entropy loss **( Label data is integer data , It needs to be converted to one-hot code )**
from tensorflow.python.keras.optimizer_v1 import Adam
from tensorflow.python.keras.losses import sparse_categorical_crossentropy
class SingleNN(object):
def compile(self):
SingleNN.model.compile(optimizer=Adam(),
loss=sparse_categorical_crossentropy,
metrics=['accuracy'])
Define training function
epochs Set to 3 Time ,batch_size Set to 32
class SingleNN(object):
def fit(self):
SingleNN.model.fit(self.train,self.train_label,epochs=3,batch_size=32)
return None
Define the evaluation function
Record the loss function value and accuracy of the test set
class SingleNN(object):
def evaluate(self):
test_loss,test_acc = SingleNN.model.evaluate(self.test,self.test_label)
print("test_loss:",test_loss)
print("test_acc:",test_acc)
return None
Open session diagram
with tf.compat.v1.Session() as sess:
cnn = SingleNN()
cnn.compile()
cnn.fit()
cnn.evaluate()
Running results
Train on 60000 samples
Epoch 1/3
60000/60000 [==============================] - 5s 81us/sample - loss: 0.4989 - accuracy: 0.8242
Epoch 2/3
60000/60000 [==============================] - 5s 77us/sample - loss: 0.3749 - accuracy: 0.8635
Epoch 3/3
60000/60000 [==============================] - 5s 78us/sample - loss: 0.3373 - accuracy: 0.8766
test_loss: 0.3732113081932068
test_acc: 0.8629
版权声明
本文为[Stephen_ Tao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230548468731.html
边栏推荐
- 剑指 Offer 03. 数组中重复的数字
- ES6
- 440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
- 高德地图搜索、拖拽 查询地址
- 2022 tea artist (primary) examination simulated 100 questions and simulated examination
- 198. 打家劫舍-动态规划
- [appium] write scripts by designing Keyword Driven files
- Ring back to origin problem - byte jumping high frequency problem
- QT modification UI does not take effect
- Go对文件操作
猜你喜欢

MySQL进阶之索引【分类,性能分析,使用,设计原则】

2022 tea artist (primary) examination simulated 100 questions and simulated examination

Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise

C1小笔记【任务训练篇二】

JS forms the items with the same name in the array object into the same array according to the name

云原生虚拟化:基于 Kubevirt 构建边缘计算实例

Exercise: even sum, threshold segmentation and difference (two basic questions of list object)

48. Rotate image

440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题

Go's gin framework learning
随机推荐
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
198. 打家劫舍-动态规划
402. Remove K digits - greedy
JS parsing and execution process
Detailed deployment of flask project
Applet learning notes (I)
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
402. 移掉 K 位数字-贪心
Tdan over half
Tell the truth of TS
高德地图搜索、拖拽 查询地址
Amount input box, used for recharge and withdrawal
[binary number] maximum depth of binary tree + maximum depth of n-ary tree
Leak detection and vacancy filling (VII)
Halo open source project learning (II): entity classes and data tables
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
剑指 Offer 03. 数组中重复的数字
Learning record of uni app dark horse yougou project (Part 2)
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
开源按键组件Multi_Button的使用,含测试工程