9.RNN应用
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 keras.optimizers import Adam
# 数据长度-一行有28个像素
input_size = 28
# 序列长度-一共有28行
time_steps = 28
# 隐藏层cell个数
cell_size = 50 # 载入数据
(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
# 换one hot格式
y_train = np_utils.to_categorical(y_train,num_classes=10)
y_test = np_utils.to_categorical(y_test,num_classes=10)#one hot # 创建模型
model = Sequential() # 循环神经网络
model.add(SimpleRNN(
units = cell_size, # 输出
input_shape = (time_steps,input_size), #输入
)) # 输出层
model.add(Dense(10,activation='softmax')) # 定义优化器
adam = Adam(lr=1e-4) # 定义优化器,loss function,训练过程中计算准确率
model.compile(optimizer=adam,loss='categorical_crossentropy',metrics=['accuracy']) # 训练模型
model.fit(x_train,y_train,batch_size=64,epochs=10) # 评估模型
loss,accuracy = model.evaluate(x_test,y_test) print('test loss',loss)
print('test accuracy',accuracy)

9.RNN应用的更多相关文章
- RNN求解过程推导与实现
RNN求解过程推导与实现 RNN LSTM BPTT matlab code opencv code BPTT,Back Propagation Through Time. 首先来看看怎么处理RNN. ...
- 在RNN中使用Dropout
dropout在前向神经网络中效果很好,但是不能直接用于RNN,因为RNN中的循环会放大噪声,扰乱它自己的学习.那么如何让它适用于RNN,就是只将它应用于一些特定的RNN连接上. LSTM的长期记 ...
- RNN 入门学习资料整理
建议按序阅读 1. RNN的一些简单概念介绍 A guide to recurrent neural networks and backpropagation Deep learning:四十九(RN ...
- lecture7-序列模型及递归神经网络RNN
Hinton 第七课 .这里先说下RNN有recurrent neural network 和 recursive neural network两种,是不一样的,前者指的是一种人工神经网络,后者指的是 ...
- RNN 入门教程 Part 4 – 实现 RNN-LSTM 和 GRU 模型
转载 - Recurrent Neural Network Tutorial, Part 4 – Implementing a GRU/LSTM RNN with Python and Theano ...
- RNN 入门教程 Part 3 – 介绍 BPTT 算法和梯度消失问题
转载 - Recurrent Neural Networks Tutorial, Part 3 – Backpropagation Through Time and Vanishing Gradien ...
- RNN 入门教程 Part 2 – 使用 numpy 和 theano 分别实现RNN模型
转载 - Recurrent Neural Networks Tutorial, Part 2 – Implementing a RNN with Python, Numpy and Theano 本 ...
- RNN 入门教程 Part 1 – RNN 简介
转载 - Recurrent Neural Networks Tutorial, Part 1 – Introduction to RNNs Recurrent Neural Networks (RN ...
- CNN & RNN 及一些常识知识(不断扩充中)
参考: http://blog.csdn.net/iamrichardwhite/article/details/51089199 一.神经网络的发展历史 五六十年代,提出感知机 八十年代,提出多层感 ...
- 循环神经网络(RNN, Recurrent Neural Networks)介绍(转载)
循环神经网络(RNN, Recurrent Neural Networks)介绍 这篇文章很多内容是参考:http://www.wildml.com/2015/09/recurrent-neur ...
随机推荐
- 解读GitHub EntityComponentSystemSamples
出自Unity官方的ECS项目示例,该项目的第一次Commit是在2018年3月20号,距离现在一年半的时间,这期间ECS本身的生态在快速发展,稳定性也是逐步提升,期待在2020年的Unity版本中作 ...
- 鸟哥私房菜基础篇:Linux 账号管理与 ACL 权限配置习题
猫宁!!! 参考:http://cn.linux.vbird.org/linux_basic/0410accountmanager.php 1-root 的 UID 与 GID 是多少?而基于这个理由 ...
- 解决 ThinkPHP 5 把控制器下的文件夹当做控制器输出的问题
目录结构: application/home/controller/user_info/User.php 输入路由:/home/user_info/user/index 看样子没毛病,但会报错: 这是 ...
- python 爬虫 基于requests模块发起ajax的post请求
基于requests模块发起ajax的post请求 需求:爬取肯德基餐厅查询http://www.kfc.com.cn/kfccda/index.aspx中指定某个城市地点的餐厅数据 点击肯德基餐厅查 ...
- Mac下安装SecureCRT客户端并激活
1. 先下载SecureCRT和破解文件 默认下载到了当前用户的”下载”目录中 2. 在”Finder”中 打开 “scrt-7.3.0-657.osx_x64.dmg” 并将 SecureCRT复制 ...
- Count Different Palindromic Subsequences
Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...
- SpringCloud组件及功能介绍
1.什么是SpringClould? SpringCloud是一个基于SpringBoot实现的微服务架构开发工具.它为微服务架构中涉及的配置管理.服务治理.断路器.智能路由.微代理.控制总线. ...
- 【Python基础】03_Python中的命名和关键字
1.Python中的关键字: ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', ...
- go get 安装一个特定版本的包失败解决方法
场景描述 go get 下载第三方包golang gin框架时,会去下载gopkg.in/go-playground/validator.v8包以及gopkg.in/yaml.v2包,gopkg.in ...
- Fiddler之常用操作(过滤器设置,代理设置,手机抓包设置,手机代理配置)
记录下,工作中常用的一些设置和操作~ 1.过滤“脏”请求 两个下拉框的名词解释: A.内外网过滤 No Zone Filter:不分区域过滤(内网外网都显示) Show only Intranet H ...