当前位置:网站首页>12. RNN is applied to handwritten digit recognition
12. RNN is applied to handwritten digit recognition
2022-07-08 00:55:00 【booze-J】
The code running platform is jupyter-notebook, Code blocks in the article , According to jupyter-notebook Written in the order of division in , Run article code , Glue directly into jupyter-notebook that will do . The comments given by the overall code are quite simple . Here we use
SimpleRNN
For example . 1. Import third-party library
import numpy as np
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense
from keras.layers.recurrent import SimpleRNN
from tensorflow.keras.optimizers import Adam
2. Loading data and data preprocessing
# Load data
# Data length - The line has 28 Pixel
input_size=28
# Sequence length - Altogether 28 That's ok
time_steps=28
# Hidden layer cell Number
cell_size=50
# Load data
(x_train,y_train),(x_test,y_test) = mnist.load_data()
# (60000,28,28)
x_train = x_train/255.0
x_test = x_test/255.0
# in one hot Format
y_train = np_utils.to_categorical(y_train,num_classes=10)
y_test = np_utils.to_categorical(y_test,num_classes=10)
3. Training models
# Creating models
model = Sequential()
# Cyclic neural network
model.add(SimpleRNN(
units=cell_size,# Output
input_shape=(time_steps,input_size),# Input
))
# Output layer
model.add(Dense(10,activation="softmax"))
# Define optimizer Set the learning rate to 1e-4
adam = Adam(lr=1e-4)
# Define optimizer ,loss function, The accuracy of calculation during training
model.compile(optimizer=adam,loss="categorical_crossentropy",metrics=["accuracy"])
# Training models
model.fit(x_train,y_train,batch_size=64,epochs=10)
# Evaluation model
loss,accuracy=model.evaluate(x_test,y_test)
print("test loss:",loss)
print("test accuracy:",accuracy)
Code run results :
Some points needing attention in the code , Explanations and reminders are also given in the code comments . You can see from the run results RNN The accuracy of the trained model on the test set is relative to 10.CNN Applied to handwritten numeral recognition in CNN The accuracy effect of the trained model on the test set is worse .
边栏推荐
- [note] common combined filter circuit
- 大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
- Deep dive kotlin synergy (XXII): flow treatment
- How to add automatic sorting titles in typora software?
- Lecture 1: the entry node of the link in the linked list
- Leetcode brush questions
- How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary
- 基于人脸识别实现课堂抬头率检测
- 深潜Kotlin协程(二十三 完结篇):SharedFlow 和 StateFlow
- Service mesh introduction, istio overview
猜你喜欢
Deep dive kotlin synergy (XXII): flow treatment
Fofa attack and defense challenge record
《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
What has happened from server to cloud hosting?
jemter分布式
他们齐聚 2022 ECUG Con,只为「中国技术力量」
ReentrantLock 公平锁源码 第0篇
How to learn a new technology (programming language)
Malware detection method based on convolutional neural network
What if the testing process is not perfect and the development is not active?
随机推荐
How to insert highlighted code blocks in WPS and word
Play sonar
51与蓝牙模块通讯,51驱动蓝牙APP点灯
Kubernetes static pod (static POD)
What has happened from server to cloud hosting?
STL -- common function replication of string class
赞!idea 如何单窗口打开多个项目?
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
[note] common combined filter circuit
Redis, do you understand the list
手写一个模拟的ReentrantLock
Hotel
Reentrantlock fair lock source code Chapter 0
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
基于微信小程序开发的我最在行的小游戏
哪个券商公司开户佣金低又安全,又靠谱
Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
RPA cloud computer, let RPA out of the box with unlimited computing power?