################################
#多尺度特征融合
#不同ROI特征融合
###############################
x = KL.Add(name=“mrcnn_mask_add_2_3”)([x2, x3])
x = KL.Add(name=“mrcnn_mask_add_2_4”)([x, x4])
x = KL.Add(name=“mrcnn_mask_add_2_5”)([x, x5])

def fpn_classifier_graph(rois, feature_maps, image_meta,pool_size, num_classes, train_bn=True,fc_layers_size=1024):"""Builds the computation graph of the feature pyramid network classifierand regressor heads.rois: [batch, num_rois, (y1, x1, y2, x2)] Proposal boxes in normalizedcoordinates.feature_maps: List of feature maps from different layers of the pyramid,[P2, P3, P4, P5]. Each has a different resolution.image_meta: [batch, (meta data)] Image details. See compose_image_meta()pool_size: The width of the square feature map generated from ROI Pooling.num_classes: number of classes, which determines the depth of the resultstrain_bn: Boolean. Train or freeze Batch Norm layersfc_layers_size: Size of the 2 FC layersReturns:logits: [batch, num_rois, NUM_CLASSES] classifier logits (before softmax)probs: [batch, num_rois, NUM_CLASSES] classifier probabilitiesbbox_deltas: [batch, num_rois, NUM_CLASSES, (dy, dx, log(dh), log(dw))] Deltas to apply toproposal boxes"""# ROI Pooling# Shape: [batch, num_rois, POOL_SIZE, POOL_SIZE, channels]x2 = PyramidROIAlign_AFN([pool_size, pool_size],2,name="roi_align_classifier_2")([rois, image_meta] + feature_maps)# Two 1024 FC layers (implemented with Conv2D for consistency)x2 = KL.TimeDistributed(KL.Conv2D(fc_layers_size, (pool_size, pool_size), padding="valid"),name="mrcnn_class_conv1_2")(x2)x2 = KL.TimeDistributed(BatchNorm(), name='mrcnn_class_bn1_2')(x2, training=train_bn)x2 = KL.Activation('relu')(x2)#3x3 = PyramidROIAlign_AFN([pool_size, pool_size], 3,name="roi_align_classifier_3")([rois, image_meta] + feature_maps)# Two 1024 FC layers (implemented with Conv2D for consistency)x3 = KL.TimeDistributed(KL.Conv2D(fc_layers_size, (pool_size, pool_size), padding="valid"),name="mrcnn_class_conv1_3")(x3)x3 = KL.TimeDistributed(BatchNorm(), name='mrcnn_class_bn1_3')(x3, training=train_bn)x3 = KL.Activation('relu')(x3)#4x4 = PyramidROIAlign_AFN([pool_size, pool_size], 4,name="roi_align_classifier_4")([rois, image_meta] + feature_maps)# Two 1024 FC layers (implemented with Conv2D for consistency)x4 = KL.TimeDistributed(KL.Conv2D(fc_layers_size, (pool_size, pool_size), padding="valid"),name="mrcnn_class_conv1_4")(x4)x4 = KL.TimeDistributed(BatchNorm(), name='mrcnn_class_bn1_4')(x4, training=train_bn)x4 = KL.Activation('relu')(x4)#5x5 = PyramidROIAlign_AFN([pool_size, pool_size], 5,name="roi_align_classifier_5")([rois, image_meta] + feature_maps)# Two 1024 FC layers (implemented with Conv2D for consistency)x5 = KL.TimeDistributed(KL.Conv2D(fc_layers_size, (pool_size, pool_size), padding="valid"),name="mrcnn_class_conv1_5")(x5)x5 = KL.TimeDistributed(BatchNorm(), name='mrcnn_class_bn1_5')(x5, training=train_bn)x5 = KL.Activation('relu')(x5)#################################多尺度特征融合#不同ROI特征融合###############################x = KL.Add(name="mrcnn_mask_add_2_3")([x2, x3])x = KL.Add(name="mrcnn_mask_add_2_4")([x, x4])x = KL.Add(name="mrcnn_mask_add_2_5")([x, x5])x = KL.TimeDistributed(KL.Conv2D(fc_layers_size, (1, 1)),name="mrcnn_class_conv2")(x)x = KL.TimeDistributed(BatchNorm(), name='mrcnn_class_bn2')(x, training=train_bn)x = KL.Activation('relu')(x)shared = KL.Lambda(lambda x: K.squeeze(K.squeeze(x, 3), 2),name="pool_squeeze")(x)# Classifier headmrcnn_class_logits = KL.TimeDistributed(KL.Dense(num_classes),name='mrcnn_class_logits')(shared)mrcnn_probs = KL.TimeDistributed(KL.Activation("softmax"),name="mrcnn_class")(mrcnn_class_logits)# BBox head# [batch, num_rois, NUM_CLASSES * (dy, dx, log(dh), log(dw))]x = KL.TimeDistributed(KL.Dense(num_classes * 4, activation='linear'),name='mrcnn_bbox_fc')(shared)# Reshape to [batch, num_rois, NUM_CLASSES, (dy, dx, log(dh), log(dw))]s = K.int_shape(x)mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)return mrcnn_class_logits, mrcnn_probs, mrcnn_bbox
  for i, level in enumerate(range(2, 6)):ix = tf.where(tf.equal(roi_level, level))level_boxes = tf.gather_nd(boxes, ix)# Box indices for crop_and_resize.box_indices = tf.cast(ix[:, 0], tf.int32)# Keep track of which box is mapped to which levelbox_to_level.append(ix)# Stop gradient propogation to ROI proposalslevel_boxes = tf.stop_gradient(level_boxes)box_indices = tf.stop_gradient(box_indices)# Crop and Resize# From Mask R-CNN paper: "We sample four regular locations, so# that we can evaluate either max or average pooling. In fact,# interpolating only a single value at each bin center (without# pooling) is nearly as effective."## Here we use the simplified approach of a single value per bin,# which is how it's done in tf.crop_and_resize()# Result: [batch * num_boxes, pool_height, pool_width, channels]pooled.append(tf.image.crop_and_resize(feature_maps[i], level_boxes, box_indices, self.pool_shape,method="bilinear"))# Pack pooled features into one tensorpooled = tf.concat(pooled, axis=0)

def build_fpn_mask_graph(rois, feature_maps, image_meta,pool_size, num_classes, train_bn=True):"""Builds the computation graph of the mask head of Feature Pyramid Network.rois: [batch, num_rois, (y1, x1, y2, x2)] Proposal boxes in normalizedcoordinates.feature_maps: List of feature maps from different layers of the pyramid,[P2, P3, P4, P5]. Each has a different resolution.image_meta: [batch, (meta data)] Image details. See compose_image_meta()pool_size: The width of the square feature map generated from ROI Pooling.num_classes: number of classes, which determines the depth of the resultstrain_bn: Boolean. Train or freeze Batch Norm layersReturns: Masks [batch, num_rois, MASK_POOL_SIZE, MASK_POOL_SIZE, NUM_CLASSES]"""# ROI Pooling# Shape: [batch, num_rois, MASK_POOL_SIZE, MASK_POOL_SIZE, channels]x = PyramidROIAlign([pool_size, pool_size],name="roi_align_mask")([rois, image_meta] + feature_maps)# Conv layersx = KL.TimeDistributed(KL.Conv2D(256, (3, 3), padding="same"),name="mrcnn_mask_conv1")(x)x = KL.TimeDistributed(BatchNorm(),name='mrcnn_mask_bn1')(x, training=train_bn)x = KL.Activation('relu')(x)x = KL.TimeDistributed(KL.Conv2D(256, (3, 3), padding="same"),name="mrcnn_mask_conv2")(x)x = KL.TimeDistributed(BatchNorm(),name='mrcnn_mask_bn2')(x, training=train_bn)x = KL.Activation('relu')(x)x = KL.TimeDistributed(KL.Conv2D(256, (3, 3), padding="same"),name="mrcnn_mask_conv3")(x)x = KL.TimeDistributed(BatchNorm(),name='mrcnn_mask_bn3')(x, training=train_bn)x = KL.Activation('relu')(x)x1 = KL.TimeDistributed(KL.Conv2D(256, (3, 3), padding="same"),name="mrcnn_mask_conv4_fc")(x)x1 = KL.TimeDistributed(BatchNorm(),name='mrcnn_mask_conv4bn')(x1, training=train_bn)x1 = KL.Activation('relu')(x1)x1 = KL.TimeDistributed(KL.Conv2D(256, (3, 3),strides=(2,2), padding="same"),name="mrcnn_mask_conv5_fc")(x1)x1 = KL.TimeDistributed(BatchNorm(),name='mrcnn_mask_conv5bn')(x1, training=train_bn)x1 = KL.Activation('relu')(x1)#x1 = KL.TimeDistributed(KL.Dense(256*4*4,activation="sigmoid"),#                       name="mrcnn_mask_fc")(x1)x1 = KL.TimeDistributed(KL.Flatten())(x1)x1 = KL.TimeDistributed(KL.Dense(28*28*num_classes),name='mrcnn_mask_fc_logits')(x1)x1 = KL.Activation("softmax",name="mrcnn_class_fc")(x1)s = K.int_shape(x1)x1 = KL.Reshape(( s[1],28,28, num_classes), name="mrcnn_mask_fc_reshape")(x1)#x1 = KL.TimeDistributed(KL.Reshape((14,14)),name="mrcnn_mask_fc_reshape")(x1)x = KL.TimeDistributed(KL.Conv2D(256, (3, 3), padding="same"),name="mrcnn_mask_conv4")(x)x = KL.TimeDistributed(BatchNorm(),name='mrcnn_mask_bn4')(x, training=train_bn)x = KL.Activation('relu')(x)x = KL.TimeDistributed(KL.Conv2DTranspose(256, (2, 2), strides=2, activation="relu"),name="mrcnn_mask_deconv")(x)x = KL.TimeDistributed(KL.Conv2D(num_classes, (1, 1), strides=1, activation="softmax"),name="mrcnn_mask")(x)x = KL.Add(name="mrcnn_mask_add")([x, x1])x = KL.Activation('tanh',name="mrcnn_masksoftmax")(x)return x

PANET代码 特征融合相关推荐

  1. 算法笔记(六)多尺度特征融合之FPN/PANet

    前言 最近论文快deadline了,一直没空更新-今天复习一下多尺度特征融合的常用操作. 1. FPN 特征金字塔 论文:feature pyramid networks for object det ...

  2. 多模态特征融合机制(含代码):TFN(Tensor Fusion Network)和LMF(Low-rank Multimodal Fusion)

    文章目录 写在前面 简单的concat TFN融合策略 LWF融合策略 论文全称: <Tensor Fusion Network for Multimodal Sentiment Analysi ...

  3. ECCV2022 | 人大提出轻量级基于注意力的特征融合机制,在多个公开数据集上有效!代码已开源!

    ECCV2022 | 人大提出轻量级基于注意力的特征融合机制,在多个公开数据集上有效!代码已开源! [写在前面] 本文在文本到视频检索的新背景下,作者重新探讨了特征融合这一古老的课题.与以往的研究只考 ...

  4. 掌纹与掌静脉融合matlab代码,手形、掌纹和掌静脉多特征融合识别

    1引言当前,众多研究学者在基于手部特征的生物特征识别技术进行了大量的研究,包括指纹识别[1-2].手形识别[3-4].掌纹识别[5-6].静脉识别[7-8]等,在理论研究和实际系统应用都取得了一定的成 ...

  5. 目标检测中特征融合技术(YOLO v4)(上)

    目标检测中特征融合技术(YOLO v4)(上) 论文链接:https://arxiv.org/abs/1612.03144 Feature Pyramid Networks for Object De ...

  6. 目标检测 | 盘点目标检测中的特征融合技巧(根据YOLO v4总结)

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 特征融合分类 在深度学习的很多工作中(例如目标检测.图像分割),融 ...

  7. 【CV】CSPNet:通过分层特征融合机制增强 CNN 学习能力的骨干网络

    论文名称:CSPNet: A New Backbone that can Enhance Learning Capability of CNN 论文下载:https://arxiv.org/abs/1 ...

  8. CVPR2020论文笔记——EfficientDet---双尺度特征融合BiFPN目标检测

    代码:https://github.com/google/automl/tree/ master/efficientdet. 摘要:提出了提高效率的几个关键优化 提出了一种加权的双向特征金字塔网络,它 ...

  9. 目标检测中特征融合技术(YOLO v4)(下)

    目标检测中特征融合技术(YOLO v4)(下) ASFF:自适应特征融合方式 ASFF来自论文:<Learning Spatial Fusion for Single-Shot Object D ...

最新文章

  1. 人工智能及其应用(第5版).蔡自兴-3章课后习题。【参考答案】
  2. python自学路线-Python最佳学习路线
  3. 超图桌面版使用模板创建数据源
  4. 算法提高课-搜索-DFS之搜索顺序-AcWing 1116. 马走日:dfs
  5. java swing最小化_Java swing 窗口最小化到任务栏 点击右键显示菜单(复制代码即可运行查看效果)...
  6. Remoting系列(二)----建立第一个入门程序
  7. 学习笔记(09):Python网络编程并发编程-模拟ssh远程执行命令-代码实现
  8. 云上应用系统数据存储架构演进
  9. ffmpeg运行在服务器上,FFMPEG安装在服务器上
  10. virtualbox macos_MacOS 终于可以完美使用 Podman 了!
  11. qt设置顶层窗口_Python快速入门系列:PyQt5 快速开发GUI-窗口类型以及主窗口创建...
  12. Datawhale 社区黑板报(第1期)
  13. UT000054: The maximum size 1048576 for an individual file in a multipart req
  14. Centos 7 安装 TEMPO2
  15. 守望先锋地图英文和英雄英文
  16. OneZero第一次站立会议Sprint Planning Meeting(2016.3.21)
  17. 利用Grafana为你的Loki添加告警
  18. 扬州大学计算机软件工程博士,0836 软件工程博士点
  19. python批量修改文件名
  20. 根据分割符分割字符串成数组

热门文章

  1. 百度核心团队招募云计算产品经理
  2. [iOS]PDF格式的矢量图作为图片资源自动适配
  3. getattr 函数详讲
  4. java headless_J2SE中的HeadLess工作模式
  5. Vuex的作用、使用、核心概念(State、Mutations、Getters、Actions、Modules)、文件抽离
  6. 3大简历难题,你是否也曾遭遇?
  7. android 远程控制实例(基于Socket通信)
  8. 【PHP入门】一、注释与变量及2022phpstorm最新版激活码
  9. java键盘监听事件代码_JavaScript监听键盘事件代码实现
  10. Mac 安装 Java jdk 环境配置