当前位置:网站首页>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 .
边栏推荐
- Class head up rate detection based on face recognition
- FOFA-攻防挑战记录
- C language 001: download, install, create the first C project and execute the first C language program of CodeBlocks
- German prime minister says Ukraine will not receive "NATO style" security guarantee
- Kubernetes static pod (static POD)
- How is it most convenient to open an account for stock speculation? Is it safe to open an account on your mobile phone
- QT establish signal slots between different classes and transfer parameters
- Langchao Yunxi distributed database tracing (II) -- source code analysis
- AI遮天传 ML-初识决策树
- Fofa attack and defense challenge record
猜你喜欢
Kubernetes static pod (static POD)
Password recovery vulnerability of foreign public testing
Malware detection method based on convolutional neural network
Service Mesh介绍,Istio概述
Invalid V-for traversal element style
5g NR system messages
5G NR 系统消息
C# 泛型及性能比较
Letcode43: string multiplication
AI遮天传 ML-回归分析入门
随机推荐
Four stages of sand table deduction in attack and defense drill
What is load balancing? How does DNS achieve load balancing?
Kubernetes static pod (static POD)
How is it most convenient to open an account for stock speculation? Is it safe to open an account on your mobile phone
赞!idea 如何单窗口打开多个项目?
22年秋招心得
接口测试进阶接口脚本使用—apipost(预/后执行脚本)
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
丸子官网小程序配置教程来了(附详细步骤)
《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
Malware detection method based on convolutional neural network
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
C# 泛型及性能比较
Cause analysis and solution of too laggy page of [test interview questions]
v-for遍历元素样式失效
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
jemter分布式
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
接口测试要测试什么?
Vscode software