RNN识别mnist手写数字数据集

本文介绍如何利用循环神经网络(RNN)处理MNIST数据集,实现手写数字的识别。通过训练模型,展示RNN在图像识别领域的应用。
摘要由CSDN通过智能技术生成
# -*- coding: utf-8 -*-


# @Time    : 2018/12/24 11:04
# @Author  : WenZhao
# @Email   : 46546924@qq.com
# @File    : mnistRnn-1.py
# @Software: PyCharm
'''
    RNN识别mnist手写数字数据集
'''

import tensorflow as tf
import numpy as np
# 下载数据集
from tensorflow.examples.tutorials.mnist import input_data
mnist=input_data.read_data_sets("./data/MNIST_data/",one_hot=True)

learning_rate=0.001
batch_size=128


n_input=28
n_steps=28
n_hidden=128
n_classes=10

x=tf.placeholder(tf.float32,[None,n_steps,n_input])
y=tf.placeholder(tf.float32,[None,n_classes])


output,_=tf.nn.dynamic_rnn(
    tf.contrib.rnn.GRUCell(n_hidden),
    x,
    dtype=tf.float32,
    sequence_length=batch_size*[n_input]
)

index=tf.range(0,batch_size)*n_steps+(n_input-1)
flat=tf.reshape(output,[-1,int(output.get_shape()[2])])
last=tf.gather(flat,index)

num_clas
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值