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


相关推荐

  • 和第三方接口对接总结

    和第三方接口对接总结接口对接分为两种形式:我方A公司提供接口给B公司,B公司进行一些操作时调用我们的接口进行实现。例:A开发会员等级同步接口,供B同步会员等级到B系统。B会员等级的变动需要调用A接口主动推送给A(即更新会员卡等级)。我们首先要做的就是按照对方的要求,在对方调用我们的接口,我方成功处理之后,按照对方所需要的返回数据以及格式反馈给他们信息。在写本接口中,因为我们会员卡等级的字段是不一样的,所…

    2022年5月2日
    52
  • MySQL百万级数据量分页查询方法及其优化「建议收藏」

    MySQL百万级数据量分页查询方法及其优化

    2022年2月14日
    48
  • 线程池ThreadPool中QueueUserWorkItem的使用

    线程池ThreadPool中QueueUserWorkItem的使用先看代码://设置可以同时处于活动状态的线程池的请求数目。boolpool=ThreadPool.SetMaxThreads(8,8);if(pool){ThreadPool.QueueUserWorkItem(o=>this.DoSomethingLong(“参数1”));ThreadPool

    2022年9月24日
    3
  • 修改python的pip源为国内源[通俗易懂]

    修改python的pip源为国内源[通俗易懂]由于网络原因,访问国外的pip源超级慢,因此可将源改为国内源(都是pipy官网的镜像),就能体验到流的飞起的速度了可临时修改,也可永久修改临时修改:在后边加个-i参数指定pip源,如下所示:pipinstallpackage_name-ihttps://pypi.tuna.tsinghua.edu.cn/simple永久修改:需要修改配置文件Windows:进入%…

    2022年5月4日
    41
  • tensorflow pycharm教程_tensorflow支持python3.8吗

    tensorflow pycharm教程_tensorflow支持python3.8吗pycharm使用tensorflow流程最近在学人工智能与大数据管理,环境是python+tensorflow。但配置有些麻烦,记录一下。其实主要分为两个部分,配置tnsorflow和在pycharm中使用tensorflow。首次尝试平常安装python包都是去pycharm的setting里面,在设置ProjectInterpreter中点小加号去装的,但这次却报了错。想来应该是有些…

    2022年8月25日
    4
  • android图片资源加密,Android平台图像文件加密

    android图片资源加密,Android平台图像文件加密传统计算机平台下的图像加密技术已经得到了广泛的研究和应用,但移动平台受限于当前的硬件架构,无法直接继承传统平台的安全性技术。针时智能手机等移动平台中的图像信息安全问题,提出了一种基于Android移动平台的图像加密方案。一、图像加密技术1、传统图像加密技术分析传统的图像加密技术主要基于现代密码体制。通常将图像像素信息看作一维数据流,在密钥的控制下,利用加密算法(常用加密算法如EDS、AES、RC6…

    2022年5月17日
    44

发表回复

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

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