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)
上一篇 2022年6月23日 下午2:36
下一篇 2022年6月23日 下午2:36


相关推荐

  • 电脑不读硬盘,电脑不读硬盘,硬盘未损坏

    电脑不读硬盘,电脑不读硬盘,硬盘未损坏

    2026年3月13日
    2
  • linux修改环境变量的方法

    linux修改环境变量的方法方式 1 exportPATH PAHT home 路径 临时修改 只对当前终端生效 立即生效终端一关闭 就失效了方式 2 修改家目录下的 bashrc 文件这个文件每个用户都有 都放在自己的家目录下用户每次登录时 都会加载 执行 这个文件所以 将 expo

    2026年3月19日
    3
  • 百度智能云千帆AppBuilder实战教程:从零搭建AI应用并部署至微信生态

    百度智能云千帆AppBuilder实战教程:从零搭建AI应用并部署至微信生态

    2026年3月12日
    3
  • DB2 DECODE函数

    DB2 DECODE函数DB2DECODE函数的用法:在查询数据,需要进行条件判断时,一般我们使用CASE…WHEN实现,当判断条件为相等时,除了使用CASE…WHEN实现,还可以使用DECODE函数。若要使用like、>、DECODE()使用方法: decode(条件,值1,翻译值1,值2,翻译值2,…值n,翻译值n,缺省值)DECODE()含义说明:IF条件=值1THEN

    2022年7月25日
    39
  • nessus怎么安装_还原魔方步骤带图

    nessus怎么安装_还原魔方步骤带图0x01实验原理:利用漏洞扫描器能够自动应用漏洞扫描原理,对目标主机安全漏洞进行检测,附带识别主机漏洞的特征库的功能,从而完成网络中大量主机的漏洞识别工作。(有相应的缺点)0x02实验拓扑:0x03实验步骤:一、下载安装漏洞扫描器nessus1.下载Nessus在官方网站下载对应的Nessus版本:http://www.tenable….

    2022年8月30日
    8
  • pycharm linux激活码_ubuntu python安装

    pycharm linux激活码_ubuntu python安装这里只介绍采用激活码激活的方法。如果是window系统则hosts文件路径为:C:\Windows\System32\drivers\etc,将0.0.0.0account.jetbrains.com添加到末尾即可。如下图所示:如果是linux系统 Linux的hosts文件路径为:/etc命令行输入:第一步:cd/etc第二步:sudogedithosts输…

    2022年8月28日
    4

发表回复

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

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