MultiLSTM预测Mnist

本文使用TensorFlow实现了一个基于MultiLSTM的模型,用于预测MNIST数据集的手写数字。通过动态RNN搭建LSTM网络,设置LSTM层数、隐藏单元数等参数,并使用Adam优化器进行训练。最终模型在测试集上进行预测并展示结果。
摘要由CSDN通过智能技术生成
#!/usr/bin/python3
# -*-coding:utf-8 -*-
# @Time   :2018/3/14 
# @Author :machuanbin

"""
tensorflow :1.3.0
pandas:    0.19.2

"""
import tensorflow as tf
import os
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.contrib import rnn
import numpy as np

config=tf.ConfigProto()
# config.gup_options.allow_growth=True
sess=tf.Session(config=config)


current_dir = os.path.abspath('.\MNIST_data')

mnist=input_data.read_data_sets(current_dir,one_hot=True)

# print(mnist.train.images.shape)
lr=1e-3

#在训练和测试的时候,我们想用不同的batch_size所以采用占位符

batch_size=tf.placeholder(tf.int32,[])
keep_prob=tf.placeholder(tf.float32,[])

# 每个时刻的输入特征是28维的,就是每个时刻输入一行,一行有 28 个像素
input_size=28
# 时序持续长度为28,即每做一次预测,需要先输入28<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值