给RNN cell加dropout
来源:互联网 发布:苹果手机数据恢复公司 编辑:程序博客网 时间:2024/05/17 10:29
class SwitchableDropoutWrapper(DropoutWrapper): def __init__(self, cell, is_train, input_keep_prob=1.0, output_keep_prob=1.0, seed=None): super(SwitchableDropoutWrapper, self).__init__(cell, input_keep_prob=input_keep_prob, output_keep_prob=output_keep_prob, seed=seed) self.is_train = is_train def __call__(self, inputs, state, scope="dropout_rnn"): outputs_do, new_state_do = super(SwitchableDropoutWrapper, self).__call__(inputs, state, scope=scope) tf.get_variable_scope().reuse_variables() outputs, new_state = self._cell(inputs, state, scope) outputs = tf.cond(self.is_train, lambda: outputs_do, lambda: outputs) if isinstance(state, tuple): new_state = state.__class__(*[tf.cond(self.is_train, lambda: new_state_do_i, lambda: new_state_i) for new_state_do_i, new_state_i in zip(new_state_do, new_state)]) else: new_state = tf.cond(self.is_train, lambda: new_state_do, lambda: new_state) return outputs, new_state
注意tf.get_variable_scope().reuse_variables()
这句可能会引起Variable XXX does not exist, or was not created with tf.get_variable()
的错误,按需调整
阅读全文
0 0
- 给RNN cell加dropout
- RNN变体之dropout
- cell 加 图片
- Dropout
- Dropout
- dropout
- Dropout
- Dropout
- Dropout
- dropout
- Dropout
- Dropout
- 给cell 添加阴影
- 给cell添加动画
- swing JTable学习(五)—中给table中的cell加tips 以及用AbstractTableModel创建表格
- tensorflow1.x版本rnn生成cell 报错解决方案
- tensorflow中rnn内cell的添加操作
- 给TableView Cell 添加动画
- 人之所以痛苦是因为什么?
- 《基于几何成像模型的鱼眼镜头图像校正算法和技术研究》实现
- 动态添加和删除控件
- Python 安装scipy失败
- Lucene学习总结之六:Lucene打分公式的数学推导
- 给RNN cell加dropout
- 2,组合模式
- 持续集成之Jenkins+Gitlab简介 [一]
- sitemesh3配置细节
- eclipse快捷键
- IDEA中Ctrl+Shift+f快捷键无效的解决方式
- I/O
- error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?
- 自媒体批量注册的方法