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应用的更多相关文章

  1. RNN求解过程推导与实现

    RNN求解过程推导与实现 RNN LSTM BPTT matlab code opencv code BPTT,Back Propagation Through Time. 首先来看看怎么处理RNN. ...

  2. 在RNN中使用Dropout

    dropout在前向神经网络中效果很好,但是不能直接用于RNN,因为RNN中的循环会放大噪声,扰乱它自己的学习.那么如何让它适用于RNN,就是只将它应用于一些特定的RNN连接上.   LSTM的长期记 ...

  3. RNN 入门学习资料整理

    建议按序阅读 1. RNN的一些简单概念介绍 A guide to recurrent neural networks and backpropagation Deep learning:四十九(RN ...

  4. lecture7-序列模型及递归神经网络RNN

    Hinton 第七课 .这里先说下RNN有recurrent neural network 和 recursive neural network两种,是不一样的,前者指的是一种人工神经网络,后者指的是 ...

  5. RNN 入门教程 Part 4 – 实现 RNN-LSTM 和 GRU 模型

    转载 - Recurrent Neural Network Tutorial, Part 4 – Implementing a GRU/LSTM RNN with Python and Theano ...

  6. RNN 入门教程 Part 3 – 介绍 BPTT 算法和梯度消失问题

    转载 - Recurrent Neural Networks Tutorial, Part 3 – Backpropagation Through Time and Vanishing Gradien ...

  7. RNN 入门教程 Part 2 – 使用 numpy 和 theano 分别实现RNN模型

    转载 - Recurrent Neural Networks Tutorial, Part 2 – Implementing a RNN with Python, Numpy and Theano 本 ...

  8. RNN 入门教程 Part 1 – RNN 简介

    转载 - Recurrent Neural Networks Tutorial, Part 1 – Introduction to RNNs Recurrent Neural Networks (RN ...

  9. CNN & RNN 及一些常识知识(不断扩充中)

    参考: http://blog.csdn.net/iamrichardwhite/article/details/51089199 一.神经网络的发展历史 五六十年代,提出感知机 八十年代,提出多层感 ...

  10. 循环神经网络(RNN, Recurrent Neural Networks)介绍(转载)

    循环神经网络(RNN, Recurrent Neural Networks)介绍    这篇文章很多内容是参考:http://www.wildml.com/2015/09/recurrent-neur ...

随机推荐

  1. office web apps安装部署,配置https,负载均衡(一)背景介绍

    Office Web Apps,简称owa,是微软开发的在线预览office 文件服务.只要是做web开发技术的技术人员都知道,office文件预览,对于网站来说,绝对是一个难点,目前常见的预览off ...

  2. 使用Postman如何做接口自动化测试

    师从‘百测’! 一.简介 Postman是一款非常流行的API调试工具,很多攻城狮都应该用过,或听说过,这里不做过多介绍. 官方网站:http://www.getpostman.com 二.接口自动化 ...

  3. 企业证书发布app到七牛云服务

    ---恢复内容开始--- 最近在做企业证书发布app,从申请企业证书,到测试程序发布到七牛云存储.整了几天终于实现了,整理一下资料. 1.首先,申请企业证书. 到苹果开发网站申请企业证书 https: ...

  4. SpringCloud+Eureka快速搭建微服架构

    什么是springcloud? Springcloud是一个微服务框架,相比dubbo等,springcloud提供全套的分布式系统解决方案. Eureka是什么? Eureka是netflix的一个 ...

  5. airflow的web任务管理

    ariflow里绿的代表都跑完了:红的表示有问题:点红的图标进去: 点tree view 红色表示那一天失败: 点进去看可以看log: 点clear则是重跑任务:

  6. Redis(1.11)Redis4.0.11 cluster 分布式集群搭建

    概念与了解:Redis(1.7)Redis高可用架构(理论篇) [0]试验环境 结构图如下: (这里试验没有那么多机器,就用3台机器搭建试验) redis1是redis集群的一个节点A,上面运行了两个 ...

  7. 解决Win7上的连接access数据库的问题

    最近做了一个win桌面程序,没有用sql 数据库,而是用access数据库,因为access比sql用起来方便多了,最主要是不要安装sql server,直接放在程序里面,然后创建连接字符就可以了,s ...

  8. Oracle的基本操作-修改表结构、数据的增删改查

    创建一个person表 create table person( pid ), pname ) ); 添加一列 ); 修改列类型 ); 修改列名称 alter table person rename ...

  9. springboot系列:使用缓存

    前言:springboot已经为我们实现了抽象的api接口,因此当我们使用不同的缓存时,只是配置有可能有点区别(比如ehcache和Redis),但是在程序中使用缓存的方法是一样的. 1.spring ...

  10. PHP读取xml并写入数据库示例

    <?php $xml = simplexml_load_file('books.xml'); // print_r($xml); // echo "<br/>"; ...