tf.nn.dynamic_rnn和MultiRNNCell构建多层动态LSTM
2018-09-19 20:45
183 查看
版权声明:微信公众号:数据挖掘与机器学习进阶之路。本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013230189/article/details/82777998
[code]import tensorflow as tf; import numpy as np; X = tf.random_normal(shape=[3, 5, 6], dtype=tf.float32) X = tf.reshape(X, [-1, 5, 6]) stacked_rnn=[] for i in range(3): stacked_rnn.append(tf.contrib.rnn.BasicLSTMCell(24)) # cell = tf.nn.rnn_cell.BasicLSTMCell(10) # 也可以换成别的,比如GRUCell,BasicRNNCell等等 lstm_multi = tf.contrib.rnn.MultiRNNCell(stacked_rnn) # state = lstm_multi.zero_state(3, tf.float32) output, state = tf.nn.dynamic_rnn(lstm_multi, X, time_major=False,dtype=tf.float32) # with tf.Session() as sess: # sess.run(tf.initialize_all_variables()) # print(output.get_shape()) # print(sess.run(state)) print(output.shape) print(len(state))#三个LSTM隐藏层 #第一个LSTM隐藏层 print(state[0].h.shape)#LSTM中的h状态 print(state[0].c.shape)#LSTM中的c状态 #第二个LSTM隐藏层 print(state[1].h.shape) print(state[1].c.shape) #第三个LSTM隐藏层 print(state[2].h.shape) print(state[2].c.shape)
阅读更多
相关文章推荐
- tf.nn.dynamic_rnn()实现的一个例子。
- tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别
- tf.nn.dynamic_rnn
- Tensorflow-tf.nn.dynamic_rnn函数解析
- 使用tflearn 构建多层感知机MLP
- TensorFlow--tf.nn.rnn_cell.DrououtWrapper
- 神经网络的前向传播和误差反向传播(NN,RNN,LSTM)(一)
- tensorflow.nn.bidirectional_dynamic_rnn()函数的用法
- 神经网络的前向传播和误差反向传播(NN,RNN,LSTM)(二)
- 神经网络的前向传播和误差反向传播(NN,RNN,LSTM)(三)
- tensorflow高阶教程:tf.dynamic_rnn
- (四)Building a Dynamic UI with Fragments使用fragment构建动态用户界面
- 动态构建LINQ(Dynamic String based Queries in LINQ - Dynamic Expression API)
- tf.nn.rnn_cell.GRUCell函数的使用
- RNN网络结构理解及多层RNN构建错误的解决方案
- ABAP 动态内表构建 Dynamic internal table
- tensorflow教程:tf.dynamic_rnn
- tensorflow高阶教程:tf.dynamic_rnn
- tf实现多层LSTM
- tf.nn.rnn_cell.BasicLSTMCell函数用法