Keras中用到的API总结

目录

 

LSTM

ConvLSTM2D

核初始化  Kernel_initializer

Zeros

Orthogonal

lecun_uniform

he_normal

lecun_normal

he_uniform

扫描二维码关注公众号,回复: 11346263 查看本文章

LSTM

keras.layers.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=1, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)
  • units:输出空间的维度
  • activation:激活函数 默认为 tanh
  • use_bias:偏置项 为bool型 ,是否使用偏置向量
  • kernel_initializer:核初始化  可以查看 Initializer  默认为 glorot_uniform
  • recurrent_initializer: 状态转换的初始化
  • unit_forget_bias::bool型,如果为真,则在初始化时将遗忘门的偏置加1。将其设置为true也将强制bias_initializer="zeros"。这是Jozefowicz等人(2015)推荐的。
  • kernel_regularizer: 应用于核权矩阵的正则化函数(参见正则化函数)。
  • recurrent_regularizer:正则化函数应用于 recurrent_kernel weights matrix (see regularizer).
  • bias_regularizer: 应用于偏置向量的正则化函数 (see regularizer).
  • activity_regularizer: 正则化函数应用于层的输出 (its "activation"). (see regularizer).
  • kernel_constraint: 应用于核权矩阵的约束函数 (see constraints).
  • recurrent_constraint: 约束函数应用于递归核权值矩阵 (see constraints).
  • bias_constraint: 应用于偏置向量的约束函数 (see constraints).
  • dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
  • recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.
  • implementation: 实现模式,1或2。模式1将把它的操作结构为大量更小的点积和加法,而模式2将把它们批量处理成更少、更大的操作。这些模式在不同的硬件和不同的应用程序上具有不同的性能概要。
  • return_sequences: 布尔。是返回输出序列中的最后一个输出,还是返回完整序列。
  • return_state: 布尔。是否返回输出之外的最后一个状态。状态列表返回的元素分别是隐藏状态和单元格状态。
  • go_backwards: Boolean(默认为False)。如果为真,则反向处理输入序列并返回反向序列
  • stateful: 布尔(默认False)。如果为真,则将一个批中的每个索引i处的样本的最后状态用作下一个批中的索引i的样本的初始状态。
  • unroll: 布尔(默认False)。如果为真,将展开网络,否则将使用符号循环。展开可以加快RNN的速度,尽管它往往需要更多的内存。展开只适用于短序列

ConvLSTM2D

keras.layers.ConvLSTM2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, return_sequences=False, go_backwards=False, stateful=False, dropout=0.0, recurrent_dropout=0.0)

卷积LSTM。

它类似于LSTM层,但是输入转换和递归转换都是卷积的。

和传统卷积的参数基本一致再额外增加了LSTM的一些参数,相当于对一个图片序列做卷积,如何再时间维度上做LSTM。

Input shape

  • if data_format='channels_first' 5D tensor with shape: (samples, time, channels, rows, cols)
  • if data_format='channels_last' 5D tensor with shape: (samples, time, rows, cols, channels)

Output shape

  • if return_sequences
    • if data_format='channels_first' 5D tensor with shape: (samples, time, filters, output_row, output_col)
    • if data_format='channels_last' 5D tensor with shape: (samples, time, output_row, output_col, filters)
  • else

    • if data_format='channels_first' 4D tensor with shape: (samples, filters, output_row, output_col)
    • if data_format='channels_last' 4D tensor with shape: (samples, output_row, output_col, filters)

    where o_row and o_col depend on the shape of the filter and the padding

核初始化  Kernel_initializer

太简单的或者基本不用的就不列出来了,可以自己去查keras

Zeros

keras.initializers.Zeros()

Orthogonal

keras.initializers.Orthogonal(gain=1.0, seed=None)

生成随机正交矩阵的初始化器

Arguments

  • gain: 应用于正交矩阵的多重因子。
  • seed:一个Python整数。用于随机生成器的种子。

References

lecun_uniform

keras.initializers.lecun_uniform(seed=None)

LeCun uniform 初始值设定项

它从[-limit, limit]内的均匀分布中抽取样本,其中极限是sqrt(3 / fan_in),其中fan_in是权张量中输入单元的数量

Arguments

  • seed:一个Python整数。用于随机生成器的种子。

Returns

An initializer.

References

he_normal

keras.initializers.he_normal(seed=None)

He normal initializer.

它从以0为中心的截断正态分布中抽取样本,其中stddev = sqrt(2 / fan_in),其中fan_in是权张量中输入单元的数量。

Arguments

  • seed: A Python integer. Used to seed the random generator.

Returns

An initializer.

References


lecun_normal

keras.initializers.lecun_normal(seed=None)

LeCun normal initializer.

它从以0为中心的截断正态分布中抽取样本,其中stddev = sqrt(1 / fan_in),其中fan_in是权张量中输入单元的数量。

Arguments

  • seed: A Python integer. Used to seed the random generator.

Returns

An initializer.

References


he_uniform

keras.initializers.he_uniform(seed=None)

He uniform variance scaling initializer.

它从[-limit, limit]内的均匀分布中抽取样本,其中极限是sqrt(6 / fan_in),其中fan_in是权张量中输入单元的数量

Arguments

  • seed: A Python integer. Used to seed the random generator.

Returns

An initializer.

References

An initializer may be passed as a string (must match one of the available initializers above), or as a callable:

猜你喜欢

转载自blog.csdn.net/qq_26593695/article/details/95637721
今日推荐