keras TimeDistributed 包装器
发布日期:2021-11-21 04:41:37
浏览次数:30
分类:技术文章
本文共 1635 字,大约阅读时间需要 5 分钟。
官方中文文档的说明如下:
输入至少为3D张量,下标为1的维度将被认为是时间维
例如,考虑一个含有32个样本的batch,每个样本都是10个向量组成的序列,每个向量长为16,则其输入维度为(32,10,16)
,其不包含batch大小的input_shape
为(10,16)
我们可以使用包装器TimeDistributed
包装Dense
,以产生针对各个时间步信号的独立全连接:
用途举例:
在搭建需要独立连接时的结构时需要用到,比如在faster rcnn中,在最后fast rcnn的结构中进行类别判断和box框的回归时,需要对num_rois个感兴趣区域ROIs进行回归处理,每一个区域的处理是相对独立的,等价于此时的时间步为num_rois,举例代码如下:
def classifier(base_layers, input_rois, num_rois, nb_classes=21, trainable=False): # compile times on theano tend to be very high, so we use smaller ROI pooling regions to workaround if K.backend() == 'tensorflow': pooling_regions = 14 input_shape = (num_rois, 14, 14, 1024) elif K.backend() == 'theano': pooling_regions = 7 input_shape = (num_rois, 1024, 7, 7) out_roi_pool = RoiPoolingConv(pooling_regions, num_rois)([base_layers, input_rois]) # 该层的输入为feature maps和roi的坐标信息 out = classifier_layers(out_roi_pool, input_shape=input_shape, trainable=True) # 输出的是(None, num_riois, 2048)的feature map out = TimeDistributed(Flatten())(out) # 因为是对num_rois个feature maps分别处理的,所以需要使用timedistributed进行包装 out_class = TimeDistributed(Dense(nb_classes, activation='softmax', kernel_initializer='zero'), name='dense_class_{}'.format(nb_classes))(out) # 我们可以使用包装器TimeDistributed包装Dense,以产生针对各个时间步信号的独立全连接 # note: no regression target for bg class out_regr = TimeDistributed(Dense(4 * (nb_classes - 1), activation='linear', kernel_initializer='zero'), name='dense_regress_{}'.format(nb_classes))(out) return [out_class, out_regr] # 一共有num_riois个out_class和out_regr
注:个人感觉这个思路和功能与slice layer非常相似
转载地址:https://blog.csdn.net/xiaojiajia007/article/details/76665016 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年04月24日 13时58分42秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
微服务学习四--康威定律如何解释微服务的合理性
2019-04-30
微服务学习五--微服务或API网关
2019-04-30
微服务学习六--API网关
2019-04-30
微服务学习七--微服务的好处
2019-04-30
微服务学习八--什么时候用微服务架构
2019-04-30
微服务学习九
2019-04-30
RPC学习一--gRPC的协议
2019-04-30
http/2--http2.0
2019-04-30
SPDY
2019-04-30
云学习--用吃披萨解释
2019-04-30
OneDrive
2019-04-30
Serverless学习
2019-04-30
微服务学习十--
2019-04-30
RFC (一系列以编号排定的文件)
2019-04-30
IETF
2019-04-30
Auto2.0学习二--客户端的授权模式
2019-04-30
C#-TransactionScope
2019-04-30
OLTP/OLAP/HTAP学习一
2019-04-30
easyui.form
2019-04-30