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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • mysql报错注入_mysql报错注入[通俗易懂]

    mysql报错注入_mysql报错注入[通俗易懂]报错注入这里主要介绍3种MySQL数据库报错注入的发法,分别是updatexml、floor和exp。1.updatexmlupdatexml的报错原理从本质上来说就是函数的报错。selectupdatexml(1,concat(0x7e,(selectversion()),0x7e),1);这里还是使用前面的例子,举出一个爆破数据库版本的样例Payload:爆破数据库版本信息?id=1’+…

    2022年9月30日
  • ubuntu CUDA卸载重装[通俗易懂]

    ubuntu CUDA卸载重装[通俗易懂]sudoaptremovenvidia*sudoaptremovecuda*sudoaptremovecudnn*如果之前是deb包安装的,还要操作如下步骤:sudoapt-keylist|grepcudapubrsa40962016-06-24[SC]AE09FE4BBD223A84B2CCFCE3F60F4B3D7FA2AF80uid[未知]cudatools<cudatool

    2022年9月5日
  • react-router4的按需加载实践(基于create-react-app和Bundle组件)

    react-router4的按需加载实践(基于create-react-app和Bundle组件)

    2022年4月2日
  • 项目活动图 – 举例说明

    项目活动图 – 举例说明关键路径:从开始到结束的所有路径中,时间最长的一条为关键路径。(特点:在关键路径上,所有任务的松弛时间都为0);松弛时间:第一种方法:最晚开始时间-最早开始时间;第二种方法:关键路径的总时间-包含该任务的任务路径花的时间;(前提条件:必须不影响该任务以后的任务路径)举例:关键路径:A-B-D-G-I-K-L=22由前向后推可得出…

    2022年5月13日
  • 我用css精灵图拼接了自己的英文名字,不会还有人不知道精灵图技术吧?

    我用css精灵图拼接了自己的英文名字,不会还有人不知道精灵图技术吧?我用css精灵图拼接了自己的英文名字,不会还有人不知道精灵图技术吧?

    2022年5月26日
  • 运行游戏时出现0xc000007b错误的解决方法[通俗易懂]

    运行游戏时出现0xc000007b错误的解决方法[通俗易懂]最后更新:2019-2-28如图,0xc000007b这个错误使无数玩家烦恼。问题描述:出现这个错误,可能是硬件的问题,也可能是软件的问题。但是,由于硬件引起该问题的概率很小,并且除了更换硬件之外没有更好的解决方法,因此本文将详细介绍如何通过软件解决此问题,这也是大家最关心的。由于本文阅读用户众多,大家对于电脑故障解决的熟悉程度也不一样,因此本文致力…

    2022年6月12日

发表回复

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

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