MaskRCNN RPN网络分析

MaskRCNN RPN网络分析在每个锚生成5种大小和3种形状的候选框(每层特征对应一种大小,每个锚点对应3种形状)。并进行两层卷积后,做前景与背景的分类,与候选框的偏移量回归。与目标重叠>=0.7则为前景,与目标重叠<=0.3则为背景,其余框去掉。#############################################################RegionPropos…

大家好,又见面了,我是你们的朋友全栈君。

è¿éåå¾çæè¿°

在每个锚生成5种大小和3种形状的候选框(每层特征对应一种大小,每个锚点对应3种形状)。并进行两层卷积后,做前景与背景的分类,与候选框的偏移量回归。与目标重叠> = 0.7则为前景,与目标重叠<= 0.3则为背景,其余框去掉。

############################################################
#  Region Proposal Network (RPN)
############################################################

def rpn_graph(feature_map, anchors_per_location, anchor_stride):
    """Builds the computation graph of Region Proposal Network.

    feature_map: backbone features [batch, height, width, depth]
    anchors_per_location: number of anchors per pixel in the feature map
    anchor_stride: Controls the density of anchors. Typically 1 (anchors for
                   every pixel in the feature map), or 2 (every other pixel).

    Returns:
        rpn_class_logits: [batch, H * W * anchors_per_location, 2] Anchor classifier logits (before softmax)
        rpn_probs: [batch, H * W * anchors_per_location, 2] Anchor classifier probabilities.
        rpn_bbox: [batch, H * W * anchors_per_location, (dy, dx, log(dh), log(dw))] Deltas to be
                  applied to anchors.
    """
    # TODO: check if stride of 2 causes alignment issues if the feature map
    # is not even.
    # Shared convolutional base of the RPN
    # 对特征图做一个(3, 3)卷积,结果大小[batch, height, width, depth]
    shared = KL.Conv2D(512, (3, 3), padding='same', activation='relu',
                       strides=anchor_stride,
                       name='rpn_conv_shared')(feature_map)

    # Anchor Score. [batch, height, width, anchors per location * 2].
    # anchors_per_location=3,3种锚点比例
    x = KL.Conv2D(2 * anchors_per_location, (1, 1), padding='valid',
                  activation='linear', name='rpn_class_raw')(shared)

    # Reshape to [batch, anchors, 2]
    # 背景和前景做分类
    rpn_class_logits = KL.Lambda(
        lambda t: tf.reshape(t, [tf.shape(t)[0], -1, 2]))(x)

    # Softmax on last dimension of BG/FG.
    # 分类 背景和前景,做softmax处理
    rpn_probs = KL.Activation(
        "softmax", name="rpn_class_xxx")(rpn_class_logits)

    # Bounding box refinement. [batch, H, W, anchors per location * depth]
    # where depth is [x, y, log(w), log(h)]
    # 边框优化,activation='linear'线性激活函数
    x = KL.Conv2D(anchors_per_location * 4, (1, 1), padding="valid",
                  activation='linear', name='rpn_bbox_pred')(shared)

    # Reshape to [batch, anchors, 4]
    # 4个框坐标
    rpn_bbox = KL.Lambda(lambda t: tf.reshape(t, [tf.shape(t)[0], -1, 4]))(x)

    return [rpn_class_logits, rpn_probs, rpn_bbox]


def build_rpn_model(anchor_stride, anchors_per_location, depth):
    """Builds a Keras model of the Region Proposal Network.
    It wraps the RPN graph so it can be used multiple times with shared
    weights.

    anchors_per_location: number of anchors per pixel in the feature map
    anchor_stride: Controls the density of anchors. Typically 1 (anchors for
                   every pixel in the feature map), or 2 (every other pixel).
    depth: Depth of the backbone feature map.

    Returns a Keras Model object. The model outputs, when called, are:
    rpn_class_logits: [batch, H * W * anchors_per_location, 2] Anchor classifier logits (before softmax)
    rpn_probs: [batch, H * W * anchors_per_location, 2] Anchor classifier probabilities.
    rpn_bbox: [batch, H * W * anchors_per_location, (dy, dx, log(dh), log(dw))] Deltas to be
                applied to anchors.
    """
    input_feature_map = KL.Input(shape=[None, None, depth],
                                 name="input_rpn_feature_map")
    outputs = rpn_graph(input_feature_map, anchors_per_location, anchor_stride)
    return KM.Model([input_feature_map], outputs, name="rpn_model")

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/152323.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 《哈佛大学幸福课》笔记

    《哈佛大学幸福课》笔记题外话:2020.7.25-2021.4.24,视频总时长29小时,看了9个月才看完。刚看的时候又是老毛病急于求成,想一口气看完,结果到8月底看到第4课就放弃了,9月整整中断了一个月,10月才重新拾起来。拾起来也是定了个计划,慢下来,每周只看50分钟,上课做笔记记下最有感触的知识,用一年的时间看完,这样才慢慢坚持了下来。花了大概4个小时整理笔记。这门课一共分为10章,每章一个主题。B站最多播放量视频和网易云课堂上的都是33堂课的版本,给每堂课又都分别起了个名字,很混乱且让人觉得莫名其妙,凸现不了主题,这也

    2022年7月18日
    23
  • Git—记录一次自建git服务器和客户端的过程

    Git—记录一次自建git服务器和客户端的过程系统Windows1064BitCentOS7(服务器)步骤服务器部分新建用户useraddgitgroupaddgit(如果已经存在,就不用理会了)cd/home/gitmkdir.sshtouchauthorized_keysyuminstall-ygit安装gityuminstall-ygit建立仓库找个认为合适的位置mkdir/gitrepocd/gitrepogitinit–baretest.gitcd/ch

    2022年10月4日
    5
  • 差异与阵列和阵列结构和链表的区别

    差异与阵列和阵列结构和链表的区别

    2022年1月14日
    42
  • android中的加密算法,Android中加密算法[通俗易懂]

    android中的加密算法,Android中加密算法[通俗易懂]Android中的加密算法可以分为两类:对称加密和非对称加密对称加密(DES、3DES、AES)概念对称加密算法中,发送方将明文和加密密匙经过特殊加密算法处理后,使其形成变成复杂的密文后发送出去。接受方用同样的密匙、同样加密算法的逆算法对密文进行解密。传统的DES加密算法只有56位密匙,最新AES技术拥有128位密匙。大大提高了安全性。优点:算法公开、计算量小、加密速度快、加密效率高缺点:发送…

    2022年5月13日
    41
  • SessionA和pplication网上聊天室的网络范例

    SessionA和pplication网上聊天室的网络范例

    2022年1月2日
    57
  • Linux磁盘管理(命令行)

    Linux磁盘管理(命令行)Linuxfdisk是一个创建和维护分区表的程序,它兼容DOS类型的分区表、BSD或者SUN类型的磁盘列表。

    2022年5月28日
    42

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号