当前位置:网站首页>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 .
边栏推荐
- ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
- 什么是负载均衡?DNS如何实现负载均衡?
- From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
- The method of server defense against DDoS, Hangzhou advanced anti DDoS IP section 103.219.39 x
- STL -- common function replication of string class
- Summary of the third course of weidongshan
- ABAP ALV LVC模板
- How to insert highlighted code blocks in WPS and word
- Summary of weidongshan phase II course content
- [reprint] solve the problem that CONDA installs pytorch too slowly
猜你喜欢

Malware detection method based on convolutional neural network

Redis, do you understand the list

新库上线 | CnOpenData中国星级酒店数据

Jouer sonar

基于微信小程序开发的我最在行的小游戏

SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)

How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary

英雄联盟胜负预测--简易肯德基上校
![[note] common combined filter circuit](/img/2f/a8c2ef0d76dd7a45b50a64a928a9c8.png)
[note] common combined filter circuit

letcode43:字符串相乘
随机推荐
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
Service Mesh介绍,Istio概述
Four stages of sand table deduction in attack and defense drill
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
接口测试要测试什么?
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
Redis, do you understand the list
The weight of the product page of the second level classification is low. What if it is not included?
What is load balancing? How does DNS achieve load balancing?
Cve-2022-28346: Django SQL injection vulnerability
Interface test advanced interface script use - apipost (pre / post execution script)
Which securities company has a low, safe and reliable account opening commission
Summary of the third course of weidongshan
Letcode43: string multiplication
Is it safe to open an account on the official website of Huatai Securities?
Marubeni official website applet configuration tutorial is coming (with detailed steps)
A brief history of information by James Gleick
New library launched | cnopendata China Time-honored enterprise directory