静态与动态RNN函数比较

静态与动态RNN比较

Tensorflow中提供了两种创建RNN结构的函数:

  • tf.nn.static_rnn
  • tf.nn.dynamic_rnn

两个函数的区别如下[1]:

tf.nn.static_rnn creates an unrolled graph for a fixed RNN length. That means, if you call tf.nn.static_rnn with inputs having 200 time steps you are creating a static graph with 200 RNN steps. First, graph creation is slow. Second, you’re unable to pass in longer sequences (> 200) than you’ve originally specified.

tf.nn.dynamic_rnn solves this. It uses a tf.While loop to dynamically construct the graph when it is executed. That means graph creation is faster and you can feed batches of variable size.
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
file_dir = '/Users/wangruidong/Documents/MachineLearning/Dataset/MNIST/'
mnist = input_data.read_data_sets(file_dir, one_hot=True)
train_img = mnist.train.images
train_labels = mnist.train.labels
print(train_img.shape)
print(train_labels.shape)
print('Load data finish.')
Extracting /Users/wangruidong/Documents/MachineLearning/Dataset/MNIST/train-images-idx3-ubyte.gz
Extracting /Users/wangruidong/Documents/MachineLearning/Dataset/MNIST/train-labels-idx1-ubyte.gz
Extracting /Users/wangruidong/Documents/MachineLearning/Dataset/MNIST/t10k-images-idx3-ubyte.gz
Extracting /Users/wangruidong/Documents/MachineLearning/Dataset/MNIST/t10k-labels-idx1-ubyte.gz
(55000, 784)
(55000, 10)
Load data finish.
input_dim = 28
time_step = 28
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值