Class tf.contrib.rnn.MultiRNNCell  新版

Class tf.nn.rnn_cell.MultiRNNCell

构建多隐层神经网络

__init__(cells, state_is_tuple=True)

cells:rnn cell 的list

state_is_tuple:true,状态Ct和ht就是分开记录,放在一个tuple中,接受和返回的states是n-tuples,其中n=len(cells),False,states是concatenated沿着列轴.后者即将弃用。

BasicLSTMCell 单隐层

BasicLSTMCell 多隐层

代码示例

# encoding:utf-8
import tensorflow as tf batch_size=10
depth=128 inputs=tf.Variable(tf.random_normal([batch_size,depth])) previous_state0=(tf.random_normal([batch_size,100]),tf.random_normal([batch_size,100]))
previous_state1=(tf.random_normal([batch_size,200]),tf.random_normal([batch_size,200]))
previous_state2=(tf.random_normal([batch_size,300]),tf.random_normal([batch_size,300])) num_units=[100,200,300]
print(inputs) cells=[tf.nn.rnn_cell.BasicLSTMCell(num_unit) for num_unit in num_units]
mul_cells=tf.nn.rnn_cell.MultiRNNCell(cells) outputs,states=mul_cells(inputs,(previous_state0,previous_state1,previous_state2)) print(outputs.shape) #(10, 300)
print(states[0]) #第一层LSTM
print(states[1]) #第二层LSTM
print(states[2]) ##第三层LSTM
print(states[0].h.shape) #第一层LSTM的h状态,(10, 100)
print(states[0].c.shape) #第一层LSTM的c状态,(10, 100)
print(states[1].h.shape) #第二层LSTM的h状态,(10, 200)

输出

(10, 300)
LSTMStateTuple(c=<tf.Tensor 'multi_rnn_cell/cell_0/basic_lstm_cell/Add_1:0' shape=(10, 100) dtype=float32>, h=<tf.Tensor 'multi_rnn_cell/cell_0/basic_lstm_cell/Mul_2:0' shape=(10, 100) dtype=float32>)
LSTMStateTuple(c=<tf.Tensor 'multi_rnn_cell/cell_1/basic_lstm_cell/Add_1:0' shape=(10, 200) dtype=float32>, h=<tf.Tensor 'multi_rnn_cell/cell_1/basic_lstm_cell/Mul_2:0' shape=(10, 200) dtype=float32>)
LSTMStateTuple(c=<tf.Tensor 'multi_rnn_cell/cell_2/basic_lstm_cell/Add_1:0' shape=(10, 300) dtype=float32>, h=<tf.Tensor 'multi_rnn_cell/cell_2/basic_lstm_cell/Mul_2:0' shape=(10, 300) dtype=float32>)
(10, 100)
(10, 100)
(10, 200)

tf.nn.rnn_cell.MultiRNNCell的更多相关文章

  1. tf.nn.dynamic_rnn

    tf.nn.dynamic_rnn(cell,inputs,sequence_length=None, initial_state=None,dtype=None, parallel_iteratio ...

  2. tensorflow笔记6:tf.nn.dynamic_rnn 和 bidirectional_dynamic_rnn:的输出,output和state,以及如何作为decoder 的输入

    一.tf.nn.dynamic_rnn :函数使用和输出 官网:https://www.tensorflow.org/api_docs/python/tf/nn/dynamic_rnn 使用说明: A ...

  3. 深度学习原理与框架-递归神经网络-RNN网络基本框架(代码?) 1.rnn.LSTMCell(生成单层LSTM) 2.rnn.DropoutWrapper(对rnn进行dropout操作) 3.tf.contrib.rnn.MultiRNNCell(堆叠多层LSTM) 4.mlstm_cell.zero_state(state初始化) 5.mlstm_cell(进行LSTM求解)

    问题:LSTM的输出值output和state是否是一样的 1. rnn.LSTMCell(num_hidden, reuse=tf.get_variable_scope().reuse)  # 构建 ...

  4. tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别

    tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别 https://blog.csdn.net/u014365862/article/details/78238 ...

  5. TF-卷积函数 tf.nn.conv2d 介绍

    转自 http://www.cnblogs.com/welhzh/p/6607581.html 下面是这位博主自己的翻译加上测试心得 tf.nn.conv2d是TensorFlow里面实现卷积的函数, ...

  6. tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例

    tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例 #!/usr/bin/env python # -*- coding: utf-8 ...

  7. tf.nn.conv2d 和 tf.nn.max_pool 中 padding 分别为 'VALID' 和 'SAME' 的直觉上的经验和测试代码

    这个地方一开始是迷糊的,写代码做比较分析,总结出直觉上的经验. 某人若想看精准的解释,移步这个网址(http://blog.csdn.net/fireflychh/article/details/73 ...

  8. 【TensorFlow基础】tf.add 和 tf.nn.bias_add 的区别

    1. tf.add(x,  y, name) Args: x: A `Tensor`. Must be one of the following types: `bfloat16`, `half`, ...

  9. tf.nn.conv2d。卷积函数

    tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个方法,非常重要 tf.nn.conv2d(input, fil ...

随机推荐

  1. adobe

    使用adobe acrobat pro dc可以处理pdf,自动识别,编辑pdf,将pdf导出为word.(收费可破解)

  2. 小程序用户openid设置放缓存

    wx.setStorageSync('openid', res.data.data.openid),设置     var openid = wx.getStorageSync('openid')获取

  3. JS中循环逻辑和判断逻辑的使用实例

    源代码见: https://github.com/Embrace830/JSExample &&和||的理解 a || b:如果a是true,那么b不管是true还是false,都返回 ...

  4. mac 下配置Android sdk

    1.通过homebrew进行安装  地址:https://brew.sh/index_zh-cn.html 2.homebrew install android sdk 3.找到路径如: /Users ...

  5. 118. Pascal's Triangle (java)

    问题描述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  6. mysql排序的中文首字母排序和自定义排序

    select * FROM organ_new where city_code = 'SZ0755' and organ_type = 'H' and state = '1' ORDER BY FIE ...

  7. Spring Boot 打war包并利用docBase指定根目录为打包的工程

    指定根目录有两种方式 1:直接将打的war包名称定义为ROOT 2:利用docBase 比如笔者war包名为xibu.war,将该war包丢到/Users/archerlj/Library/apach ...

  8. 关于ORA-06508 , ORA-04068异常的详细说明

    参考:程序包调用报ORA-06508: PL/SQL: 无法找到正在调用的程序单元 出现这种情况的原因是因为,对于全局变量,每一个session会生成一个本地copy,如果程序重新编译的话,就会因程序 ...

  9. python, 在信用评级中,计算KS statistic值

    # -*- coding: utf-8 -*- import pandas as pd from sklearn.grid_search import GridSearchCV from sklear ...

  10. LSTM UEBA异常检测——deeplog里其实提到了,就是多分类LSTM算法,结合LSTM预测误差来检测异常参数

    结合CNN的可以参考:http://fcst.ceaj.org/CN/article/downloadArticleFile.do?attachType=PDF&id=1497 除了行为,其他 ...