keras中TimeDistributed和RepeatVector的解释

版权声明:著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。 https://blog.csdn.net/ChaoFeiLi/article/details/89323078

1、TimeDistributed和Dense的使用

下面代码是keras里面给出的解释:

  # as the first layer in a model
        model = Sequential()
        model.add(TimeDistributed(Dense(8), input_shape=(10, 16)))
  # now model.output_shape == (None, 10, 8)

从上述代码中可以发现,TimeDistributed和Dense一起配合使用,主要应用于一对多,多对多的情况。
input_shape = (10,16),表示步长是10,每一步的维度为16,(即:每一个数据的属性长度为16))

首先使用TimeDistributed(Dense(8),input_shape = (10,16))把每一步的维度为16变成8,不改变步长的大小

若该层的批输入形状然后(50, 10, 16),则这一层之后的输出为(50, 10, 8)

2、RepeatVector的使用

这个是keras官网给出的解释

        model = Sequential()
        model.add(Dense(32, input_dim=32))
        # now: model.output_shape == (None, 32)
        # note: `None` is the batch dimension

        model.add(RepeatVector(3))
        # now: model.output_shape == (None, 3, 32)

解释:如果输入的形状为(None,32),经过添加RepeatVector(3)层之后,输出变为(None,3,32),RepeatVector不改变我们的步长,改变我们的每一步的维数(即:属性长度)

猜你喜欢

转载自blog.csdn.net/ChaoFeiLi/article/details/89323078