对于ConvLSTM的理解

ConvLSTM最早是在《Convolutional LSTM Network: A Machine Learning Approach for Precipitation Nowcasting》论文里提出,目的是为了解决降水临近预报。这个问题可以看做是一个时序问题,于是有学者尝试使用LSTM解决这个问题。但是其使用的事全连接长短期记忆网络(FC-LSTM),没有考虑到空间上的相关性,并且包含了大量冗余的空间数据。

针对上述问题,论文提出一种ConvLSTM结构,不仅可以向LSTM一样建立时序关系,而且可以像CNN一样刻画局部空间特征。并且作者通过实验证明了ConvLSTM在获取时空关系上比LSTM有更好的效果。,而且ConvLSTM不仅可以预测天气,还能够解决其他时空序列的预测问题。比如行为识别。o(╯□╰)o

LSTM

LSTM的公式如下,其中o表示的是Hadamard乘法,表示的是矩阵对应元素相乘

《对于ConvLSTM的理解》

对于LSTM不太理解的可以参考我前面一篇文章:LSTM原理及实现

ConvLSTM

《对于ConvLSTM的理解》

ConvLSTM核心本质还是和LSTM一样,将上一层的输出作下一层的输入。不同的地方在于加上卷积操作之后,为不仅能够得到时序关系,还能够像卷积层一样提取特征,提取空间特征。这样就能够得到时空特征。并且将状态与状态之间的切换也换成了卷积计算。其中”*”表示卷积计算。
《对于ConvLSTM的理解》

需要注意的是这里的 X,C,H,i,f,o X , C , H , i , f , o 都是三维的tensor,他们后两个维度表示行和列的空间信息(第一维应该是时间维)。相对于LSTM的二维。

tensorlayer中的定义

tensorlayer是tensorflow的一个高层API,掩盖了一些细节。更方便的使用tensorflow搭建各种模型,里面也提供了ConvLSTM的定义

class ConvLSTMLayer(Layer):
"""
The :class:`ConvLSTMLayer` class is a Convolutional LSTM layer,
see `Convolutional LSTM Layer <https://arxiv.org/abs/1506.04214>`_ .

Parameters
----------
layer : a :class:`Layer` instance
    The `Layer` class feeding into this layer.
cell_shape : tuple, the shape of each cell width*height
filter_size : tuple, the size of filter width*height
cell_fn : a Convolutional RNN cell as follow.
feature_map : a int
    The number of feature map in the layer.
initializer : initializer
    The initializer for initializing the parameters.
n_steps : a int
    The sequence length.
initial_state : None or ConvLSTM State
    If None, initial_state is zero_state.
return_last : boolen
    - If True, return the last output, "Sequence input and single output"
    - If False, return all outputs, "Synced sequence input and output"
    - In other word, if you want to apply one or more ConvLSTM(s) on this layer, set to False.
return_seq_2d : boolen
    - When return_last = False
    - If True, return 4D Tensor [n_example, h, w, c], for stacking DenseLayer after it.
    - If False, return 5D Tensor [n_example/n_steps, h, w, c], for stacking multiple ConvLSTM after it.
name : a string or None
    An optional name to attach to this layer.

Attributes
--------------
outputs : a tensor
    The output of this RNN.
    return_last = False, outputs = all cell_output, which is the hidden state.
        cell_output.get_shape() = (?, h, w, c])

final_state : a tensor or StateTuple
    When state_is_tuple = False,
    it is the final hidden and cell states,
    When state_is_tuple = True,
    You can get the final state after each iteration during training, then
    feed it to the initial state of next iteration.

initial_state : a tensor or StateTuple
    It is the initial state of this ConvLSTM layer, you can use it to initialize
    your state at the begining of each epoch or iteration according to your
    training procedure.

batch_size : int or tensor
    Is int, if able to compute the batch_size, otherwise, tensor for ``?``.

函数参数:

  • layer:前面一层的神经网络
  • cell_shape:定义的BasicConvLSTMCell的尺寸,width*height,是一个二维的。目前还不清楚要怎么定义RNNCell的大小
  • filter_size:过滤器的尺寸,可以理解为卷积核的大小
  • cell_fn:ConvLSTM的细胞,初始化时可为空。
  • feature map:特征图的个数,等价于fliter的个数
  • initial_state:初试细胞的状态,如果为空,则为zero_state。
  • return_last:一个bool值,如果为true,最后结果只有一个输出。如果为假返回一个序列。
  • return_seq_2d:当return_last为false时有效,当return_seq_2d=true,返回一个四维张量[n_example, h, w, c],并且后面跟着一个全连接层,当return_seq_2d为false时,返回一个五维张量[n_example,n_steps, h, w, c],并且后面连接的还是ConvLSTM层。

关于ConvLSTM的shape的理解

在tensorlayer里面ConvLSTM的cell为BasicConvLSTMCell,而这个类是继承的ConvLSTMCell
下面是它的初始化方法:

__init__(
   conv_ndims,
   input_shape,
   output_channels,
   kernel_shape,
   use_bias=True,
   skip_connection=False,
   forget_bias=1.0,
   initializers=None,
   name='conv_lstm_cell'
)

其中shape对应的是input_shape, Shape of the input as int tuple, excluding the batch size.也就是输入数据的二维大小,即上层神经元传递过来的feature map的大小。

    原文作者:分支限界法
    原文地址: https://blog.csdn.net/gzj_1101/article/details/79586579
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞