打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
包装器Wrapper

包装器Wrapper

TimeDistributed包装器

keras.layers.wrappers.TimeDistributed(layer)

该包装器可以把一个层应用到输入的每一个时间步上

参数

  • layer:Keras层对象

输入至少为3D张量,下标为1的维度将被认为是时间维

例如,考虑一个含有32个样本的batch,每个样本都是10个向量组成的序列,每个向量长为16,则其输入维度为(32,10,16),其不包含batch大小的input_shape(10,16)

我们可以使用包装器TimeDistributed包装Dense,以产生针对各个时间步信号的独立全连接:

# as the first layer in a modelmodel = Sequential()model.add(TimeDistributed(Dense(8), input_shape=(10, 16)))# now model.output_shape == (None, 10, 8)# subsequent layers: no need for input_shapemodel.add(TimeDistributed(Dense(32)))# now model.output_shape == (None, 10, 32)

程序的输出数据shape为(32,10,8)

使用TimeDistributed包装Dense严格等价于layers.TimeDistribuedDense。不同的是包装器TimeDistribued还可以对别的层进行包装,如这里对Convolution2D包装:

model = Sequential()model.add(TimeDistributed(Convolution2D(64, 3, 3), input_shape=(10, 3, 299, 299)))

Bidirectional包装器

keras.layers.wrappers.Bidirectional(layer, merge_mode='concat', weights=None)

双向RNN包装器

参数

  • layer:Recurrent对象
  • merge_mode:前向和后向RNN输出的结合方式,为sum,mul,concat,aveNone之一,若设为None,则返回值不结合,而是以列表的形式返回

例子

model = Sequential()model.add(Bidirectional(LSTM(10, return_sequences=True), input_shape=(5, 10)))model.add(Bidirectional(LSTM(10)))model.add(Dense(5))model.add(Activation('softmax'))model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
get_weights() and set_weights() functions in Keras layers
Optimized RNN Stack | Microsoft Docs
如何用 Keras 搭建深度学习模型
对比学习用 Keras 搭建 CNN RNN 等常用神经网络
什么是CNN
DL框架之Keras:深度学习框架Keras框架的简介、安装(Python库)、相关概念、Keras模型使用、使用方法之详细攻略
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服