当前位置:网站首页>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 .
边栏推荐
- C language 001: download, install, create the first C project and execute the first C language program of CodeBlocks
- Kubernetes static pod (static POD)
- Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
- 22年秋招心得
- DNS series (I): why does the updated DNS record not take effect?
- 5G NR 系统消息
- The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log
- Binder core API
- How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary
- Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
猜你喜欢

C# 泛型及性能比较

"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points

What does interface testing test?

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

应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设

Fofa attack and defense challenge record

The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log

接口测试进阶接口脚本使用—apipost(预/后执行脚本)

letcode43:字符串相乘

玩轉Sonar
随机推荐
8道经典C语言指针笔试题解析
Hotel
[C language] objective questions - knowledge points
Is it safe to open an account on the official website of Huatai Securities?
Binder core API
FOFA-攻防挑战记录
51与蓝牙模块通讯,51驱动蓝牙APP点灯
【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的
jemter分布式
What has happened from server to cloud hosting?
Reptile practice (VIII): reptile expression pack
Summary of the third course of weidongshan
Service Mesh介绍,Istio概述
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
Jemter distributed
新库上线 | 中国记者信息数据
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
Solution to the problem of unserialize3 in the advanced web area of the attack and defense world
什么是负载均衡?DNS如何实现负载均衡?
Service mesh introduction, istio overview