本文整理汇总了Python中tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops.CudnnLSTM方法的典型用法代码示例。如果您正苦于以下问题:Python cudnn_rnn_ops.CudnnLSTM方法的具体用法?Python cudnn_rnn_ops.CudnnLSTM怎么用?Python cudnn_rnn_ops.CudnnLSTM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops
的用法示例。
在下文中一共展示了cudnn_rnn_ops.CudnnLSTM方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from tensorflow.contrib.cudnn_rnn.python.ops import cudnn_rnn_ops [as 别名]
# 或者: from tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops import CudnnLSTM [as 别名]
def build(self, input_shape):
super(CuDNNLSTM, self).build(input_shape)
if isinstance(input_shape, list):
input_shape = input_shape[0]
input_dim = input_shape[-1]
from tensorflow.contrib.cudnn_rnn.python.ops import cudnn_rnn_ops
self._cudnn_lstm = cudnn_rnn_ops.CudnnLSTM(
num_layers=1,
num_units=self.units,
input_size=input_dim,
input_mode='linear_input')
self.kernel = self.add_weight(shape=(input_dim, self.units * 4),
name='kernel',
initializer=self.kernel_initializer,
regularizer=self.kernel_regularizer,
constraint=self.kernel_constraint)
self.recurrent_kernel = self.add_weight(
shape=(self.units, self.units * 4),
name='recurrent_kernel',
initializer=self.recurrent_initializer,
regularizer=self.recurrent_regularizer,
constraint=self.recurrent_constraint)
if self.unit_forget_bias:
def bias_initializer(shape, *args, **kwargs):
return K.concatenate([
self.bias_initializer((self.units * 5,), *args, **kwargs),
initializers.Ones()((self.units,), *args, **kwargs),
self.bias_initializer((self.units * 2,), *args, **kwargs),
])
else:
bias_initializer = self.bias_initializer
self.bias = self.add_weight(shape=(self.units * 8,),
name='bias',
initializer=bias_initializer,
regularizer=self.bias_regularizer,
constraint=self.bias_constraint)
self.kernel_i = self.kernel[:, :self.units]
self.kernel_f = self.kernel[:, self.units: self.units * 2]
self.kernel_c = self.kernel[:, self.units * 2: self.units * 3]
self.kernel_o = self.kernel[:, self.units * 3:]
self.recurrent_kernel_i = self.recurrent_kernel[:, :self.units]
self.recurrent_kernel_f = self.recurrent_kernel[:, self.units: self.units * 2]
self.recurrent_kernel_c = self.recurrent_kernel[:, self.units * 2: self.units * 3]
self.recurrent_kernel_o = self.recurrent_kernel[:, self.units * 3:]
self.bias_i_i = self.bias[:self.units]
self.bias_f_i = self.bias[self.units: self.units * 2]
self.bias_c_i = self.bias[self.units * 2: self.units * 3]
self.bias_o_i = self.bias[self.units * 3: self.units * 4]
self.bias_i = self.bias[self.units * 4: self.units * 5]
self.bias_f = self.bias[self.units * 5: self.units * 6]
self.bias_c = self.bias[self.units * 6: self.units * 7]
self.bias_o = self.bias[self.units * 7:]
self.built = True