对faster rcnn的一些修改

2023-11-08

  1. 在network.py中修改anchor_scales,第262行:
    def create_architecture(self, sess, mode, num_classes, tag=None, anchor_scales=(8, 16, 32), anchor_ratios=(0.5, 1, 2)):

修改之前,前三轮训练结果:

改为

    def create_architecture(self, sess, mode, num_classes, tag=None, anchor_scales=(3.125 , 12.5 , 21.875 , 31.25), anchor_ratios=(0.5, 1, 2)):

修改之后,前三轮训练结果:

  1. 将nms改为soft-nms
    记得在所有文件中引入模块函数
    首先,将proposal_layer.py中的第48行改为:
    # keep = nms(np.hstack((proposals, scores)), nms_thresh)
    keep = soft_nms(proposals , scores)

然后,在nms_wrapper.py中,加入:

# soft_nms
def soft_nms(dets, sc, sigma=0.5, Nt=0.3, threshold=0.001, method=2):
    keep = cpu_soft_nms(np.ascontiguousarray(dets, dtype=np.float32),
                        np.ascontiguousarray(sc, dtype=np.float32),
                        np.float32(sigma), 
                        np.float32(Nt),
                        np.float32(threshold),
                        np.uint8(method))
    return keep

最后,在py_cpu_nms.py中,加入:

# soft_nms
def cpu_soft_nms(dets , sc, sigma=0.5, Nt=0.3, thresh=0.001, method=2):
    """
    py_cpu_softnms
    :param dets:   boexs 坐标矩阵 format [y1, x1, y2, x2]
    :param sc:     每个 boxes 对应的分数
    :param Nt:     iou 交叠门限
    :param sigma:  使用 gaussian 函数的方差
    :param thresh: 最后的分数门限
    :param method: 使用的方法
    :return:       留下的 boxes 的 index
    """

    # indexes concatenate boxes with the last column
    N = dets.shape[0]
    indexes = np.array([np.arange(N)])
    dets = np.concatenate((dets, indexes.T), axis=1)

    # the order of boxes coordinate is [y1,x1,y2,x2]
    y1 = dets[:, 0]
    x1 = dets[:, 1]
    y2 = dets[:, 2]
    x2 = dets[:, 3]
    scores = sc
    areas = (x2 - x1 + 1) * (y2 - y1 + 1)

    for i in range(N):
        # intermediate parameters for later parameters exchange
        tBD = dets[i, :].copy()
        tscore = scores[i].copy()
        tarea = areas[i].copy()
        pos = i + 1

        #
        if i != N-1:
            maxscore = np.max(scores[pos:], axis=0)
            maxpos = np.argmax(scores[pos:], axis=0)
        else:
            maxscore = scores[-1]
            maxpos = 0
        if tscore < maxscore:
            dets[i, :] = dets[maxpos + i + 1, :]
            dets[maxpos + i + 1, :] = tBD
            tBD = dets[i, :]

            scores[i] = scores[maxpos + i + 1]
            scores[maxpos + i + 1] = tscore
            tscore = scores[i]

            areas[i] = areas[maxpos + i + 1]
            areas[maxpos + i + 1] = tarea
            tarea = areas[i]

        # IoU calculate
        xx1 = np.maximum(dets[i, 1], dets[pos:, 1])
        yy1 = np.maximum(dets[i, 0], dets[pos:, 0])
        xx2 = np.minimum(dets[i, 3], dets[pos:, 3])
        yy2 = np.minimum(dets[i, 2], dets[pos:, 2])

        w = np.maximum(0.0, xx2 - xx1 + 1)
        h = np.maximum(0.0, yy2 - yy1 + 1)
        inter = w * h
        ovr = inter / (areas[i] + areas[pos:] - inter)

        # Three methods: 1.linear 2.gaussian 3.original NMS
        if method == 1:  # linear
            weight = np.ones(ovr.shape)
            weight[ovr > Nt] = weight[ovr > Nt] - ovr[ovr > Nt]
        elif method == 2:  # gaussian
            weight = np.exp(-(ovr * ovr) / sigma)
        else:  # original NMS
            weight = np.ones(ovr.shape)
            weight[ovr > Nt] = 0
        # print(scores.shape)
        # print(np.array([weight]).T.shape)
        scores[pos:] = scores[pos:] * np.array([weight]).T

    # select the boxes and keep the corresponding indexes
    inds = dets[:, 4][scores.flatten() > thresh]
    keep = inds.astype(int)

    return keep
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

对faster rcnn的一些修改 的相关文章

随机推荐

  • 游戏开发unity编辑器扩展知识系列:自定义快捷键

    参考 https blog csdn net q764424567 article details 108639136 总结 快捷键 指令 CTRL Shift Alt LEFT RIGHT UP DOWN 箭头上下左右 F1 F12 键盘
  • 浩辰CAD 2021 Linux版全球首发,破局双重“封锁”

    2020年9月29日 国产操作系统CAD设计解决方案 浩辰CAD 2021 Linux版正式发布 作为国内领军的工业设计软件企业 苏州浩辰软件股份有限公司 以下简称浩辰软件 自创建以来就一直坚持国产CAD软件的自主研发和技术创新 经过近三十
  • FancyBox.js基于JQuery图集弹层插件用法

    FancyBox是一款基于 jquery 开发的类 Lightbox 插件 支持对放大的图片添加阴影效果 对于一组相关的图片添加导航操作按纽 该 lightbox 除了能够展示图片之外 还可以展示 iframed 内容 通过 css 自定义
  • 小程序页面跳转、带参数跳转以及navigator跳转

    一 单纯的页面跳转 跳转到的页面分 tabBar 页面和 非tabBar 页面 url路径可以写相对和绝对路径 1 跳转到非导航页面 用 wx navigateTo 方法 wx navigateTo url person goldcoin
  • 手把手教你调用百度人脸识别API

    在百度AI开放平台使用百度的人脸识别能力 只需要三个核心步骤即可操作完成 获取接口权限 准备接口调用工具 进行接口调用 全部流程走通只需要十分钟时间 获取接口权限 获取接口权限是调用接口的前提 主要分为以下几步 1 进入百度云的人脸识别控制
  • Android开发——APP ANR治理

    一 背景介绍 ANR Application Not Response 指应用程序无响应 通常出现在主线程被阻塞时 并伴随ANR弹窗出现 ANR发生时要么关闭当前app 要么等待 然而等待的结果大概率还是继续ANR 最终需要杀掉应用进程 A
  • Java HashMap

    无知的我终于深入接触到了HashMap 如果有遇到有任何无法进展问题或者疑惑的地方 应该在讨论区留言 或者 其他途径以寻求及时的帮助 以加快学习效率 或者 培养独立解决问题的能力 扫清盲点 补充细节 目录 HashMap HashMap 机
  • go语言菜单树结构

    GO语言菜单树结构实现 Menu是数据库表映射 MenuTree是树结构菜单 目前只考虑2级菜单 后面附源码 亲测可用 package models import github com astaxie beego orm time type
  • Ecshop如何解决Deprecated: preg_replace()报错 (第二章)

    这些错误主要集中在 upload includes cls template php 文件中 1 line 300 原语句 return preg replace n e this gt select 1 KaTeX parse error
  • STM32引用“CmBacktrace”: ARM Cortex-M 系列 MCU 错误追踪库

    目录 概述 一 使用方法 0 CmBacktrace 是什么 1 为什么选择 CmBacktrace 2 CmBacktrace 如何使用 2 1 演示 2 2 Demo 2 3 移植说明 2 4 API 说明 2 5 常见问题 2 6 许
  • 【树莓派】error: command ‘/usr/bin/arm-linux-gnueabihf-gcc‘ failed with exit code 1(已解决)

    输入以下命令 export CFLAGS fcommon pip3 install RPi GPIO 参考网址 https askubuntu com questions 1290037 error while installing rpi
  • cpu与外设接口,cpu时序控制、电源时序控制(电源IC控制)

    目录 1 cpu与外设和存储器数据交换分别通过两种接口连接 I O接口和存储器接口 2 89C51单片机时钟电路和时序控制 3 CPU 指令周期 时序产生器和控制方式 重要 3 1 时序控制方式 4 使用通用电源IC实现电源时序控制的电路
  • PIP环境复制之requirements.txt

    1 requirements txt介绍 requirements txt顾名思义 程序的依赖 即一个项目所需要的依赖包列表 在项目平移的时候 或者程序所需要的环境过多 而不至于频繁的PIP requirements txt给此工作提供了方
  • 使用function_requires的Boost概念测试程序

    使用function requires的Boost概念测试程序 Boost是一个非常受欢迎的C 库集合 它为开发人员提供了许多实用的工具和库 以增强C 的功能和性能 其中之一是function requires概念 它可以用于在编译时检查函
  • 手把手带你撸zookeeper源码-客户端如何发送数据到zk集群服务端的

    接上篇文章继续分析 手把手带你撸zookeeper源码 zookeeper客户端如何和zk集群创建连接 上篇文章我们分析到了org apache zookeeper ClientCnxn SendThread primeConnection
  • 机器学习--PCA(主成分分析)原理及应用

    众所周知PCA是有效的降维方法 当你的特征非常多维度非常大的时候 为了使机器学习的算法在计算或是训练的时候有更高的效率 通常会进行降维处理 将一个具有m个数据n维的数据降为k维的数据 方法如下 算出一个sigma矩阵 x i 为n 1的矩阵
  • dmg文件 linux,安装和使用Dmg2Img在Linux上创建macOS安装盘

    本文介绍安装和使用Dmg2Img的方法 以在Linux操作系统上创建macOS安装盘 在Linux中安装Dmg2Img 在能够创建新的安装映像之前 必须在计算机上安装Dmg2Img应用程序 Dmg2Img能在众多主流Linux发行版中安装
  • Keil5调试代码时关于警告及错误信息的处理

    图一 Warning 图二 NoWarning Keil中出现warning 160 D unrecognized pragma这样的错误怎么解决 答 每一种开发环境支持的 pragma是不一样的 不支持的就不能用了 例如图一中的messa
  • 安装ubuntu分区设置

    一般来说 在linux系统中都有最少两个挂载点 分别是 根目录 及 swap 交换分区 其中 是必须的 一般来说我们最少需要两个分区 需要一个SWAP分区 和一个 分区 但把一些常用 重要的挂载点分到其它分区 这样便于管理 一般一个 分区
  • 对faster rcnn的一些修改

    在network py中修改anchor scales 第262行 def create architecture self sess mode num classes tag None anchor scales 8 16 32 anch