tf-faster-rcnn config.py 参数详解

2023-10-27

import os
import os.path as osp
import numpy as np
# `pip install easydict` if you don't have it
from easydict import EasyDict as edict
 
__C = edict()
# Consumers can get config by:
# 在其他文件使用config要加的命令,例子见train_net.py
#   from fast_rcnn_config import cfg
cfg = __C
 
#
# Training options
# 训练的选项
#
 
__C.TRAIN = edict()
 
# Scales to use during training (can list multiple scales)
# Each scale is the pixel size of an image's shortest side
# 最短边Scale成600
__C.TRAIN.SCALES = (600,)
 
# Max pixel size of the longest side of a scaled input image
# 最长边最大为1000
__C.TRAIN.MAX_SIZE = 1000
 
# Images to use per minibatch
# 一个minibatch包含两张图片
__C.TRAIN.IMS_PER_BATCH = 2
 
# Minibatch size (number of regions of interest [ROIs])
#  Minibatch大小,即ROI的数量
__C.TRAIN.BATCH_SIZE = 128
 
# Fraction of minibatch that is labeled foreground (i.e. class > 0)
# minibatch中前景样本所占的比例
__C.TRAIN.FG_FRACTION = 0.25
 
# Overlap threshold for a ROI to be considered foreground (if >= FG_THRESH)
# 与前景的overlap大于等于0.5认为该ROI为前景样本
__C.TRAIN.FG_THRESH = 0.5
 
# Overlap threshold for a ROI to be considered background (class = 0 if
# overlap in [LO, HI))
# 与前景的overlap在0.1-0.5认为该ROI为背景样本
__C.TRAIN.BG_THRESH_HI = 0.5
__C.TRAIN.BG_THRESH_LO = 0.1
 
# Use horizontally-flipped images during training?
# 水平翻转图像,增加数据量
__C.TRAIN.USE_FLIPPED = True
 
# Train bounding-box regressors
# 训练bb回归器
__C.TRAIN.BBOX_REG = True
 
# Overlap required between a ROI and ground-truth box in order for that ROI to
# be used as a bounding-box regression training example
# BBOX阈值,只有ROI与gt的重叠度大于阈值,这样的ROI才能用作bb回归的训练样本
__C.TRAIN.BBOX_THRESH = 0.5
 
# Iterations between snapshots
# 每迭代1000次产生一次snapshot
__C.TRAIN.SNAPSHOT_ITERS = 10000
 
# solver.prototxt specifies the snapshot path prefix, this adds an optional
# infix to yield the path: <prefix>[_<infix>]_iters_XYZ.caffemodel
# 为产生的snapshot文件名称添加一个可选的infix. solver.prototxt指定了snapshot名称的前缀
__C.TRAIN.SNAPSHOT_INFIX = ''
 
# Use a prefetch thread in roi_data_layer.layer
# So far I haven't found this useful; likely more engineering work is required
# 在roi_data_layer.layer使用预取线程,作者认为不太有效,因此设为False
__C.TRAIN.USE_PREFETCH = False
 
# Normalize the targets (subtract empirical mean, divide by empirical stddev)
# 归一化目标BBOX_NORMALIZE_TARGETS,减去经验均值,除以标准差
__C.TRAIN.BBOX_NORMALIZE_TARGETS = True
# Deprecated (inside weights)
# 弃用
__C.TRAIN.BBOX_INSIDE_WEIGHTS = (1.0, 1.0, 1.0, 1.0)
# Normalize the targets using "precomputed" (or made up) means and stdevs
# (BBOX_NORMALIZE_TARGETS must also be True)
# 在BBOX_NORMALIZE_TARGETS为True时,归一化targets,使用经验均值和方差
__C.TRAIN.BBOX_NORMALIZE_TARGETS_PRECOMPUTED = False
__C.TRAIN.BBOX_NORMALIZE_MEANS = (0.0, 0.0, 0.0, 0.0)
__C.TRAIN.BBOX_NORMALIZE_STDS = (0.1, 0.1, 0.2, 0.2)
 
# Train using these proposals
# 使用'selective_search'的proposal训练!注意该文件来自fast rcnn,下文提到RPN
__C.TRAIN.PROPOSAL_METHOD = 'selective_search'
 
# Make minibatches from images that have similar aspect ratios (i.e. both
# tall and thin or both short and wide) in order to avoid wasting computation
# on zero-padding.
# minibatch的两个图片应该有相似的宽高比,以避免冗余的zero-padding计算
__C.TRAIN.ASPECT_GROUPING = True
 
# Use RPN to detect objects
# 使用RPN检测目标
__C.TRAIN.HAS_RPN = False
# IOU >= thresh: positive example
# RPN的正样本阈值
__C.TRAIN.RPN_POSITIVE_OVERLAP = 0.7
# IOU < thresh: negative example
# RPN的负样本阈值
__C.TRAIN.RPN_NEGATIVE_OVERLAP = 0.3
# If an anchor statisfied by positive and negative conditions set to negative
# 如果一个anchor同时满足正负样本条件,设为负样本(应该用不到)
__C.TRAIN.RPN_CLOBBER_POSITIVES = False
# Max number of foreground examples
# 前景样本的比例
__C.TRAIN.RPN_FG_FRACTION = 0.5
# Total number of examples
# batch size大小
__C.TRAIN.RPN_BATCHSIZE = 256
# NMS threshold used on RPN proposals
# 非极大值抑制的阈值
__C.TRAIN.RPN_NMS_THRESH = 0.7
# Number of top scoring boxes to keep before apply NMS to RPN proposals
# 在对RPN proposal使用NMS前,要保留的top scores的box数量
__C.TRAIN.RPN_PRE_NMS_TOP_N = 12000
# Number of top scoring boxes to keep after applying NMS to RPN proposals
# 在对RPN proposal使用NMS后,要保留的top scores的box数量
__C.TRAIN.RPN_POST_NMS_TOP_N = 2000
# Proposal height and width both need to be greater than RPN_MIN_SIZE (at orig image scale)
# proposal的高和宽都应该大于RPN_MIN_SIZE,否则,映射到conv5上不足一个像素点
__C.TRAIN.RPN_MIN_SIZE = 16
# Deprecated (outside weights)
# 弃用
__C.TRAIN.RPN_BBOX_INSIDE_WEIGHTS = (1.0, 1.0, 1.0, 1.0)
# Give the positive RPN examples weight of p * 1 / {num positives}
# 给定正RPN样本的权重
# and give negatives a weight of (1 - p)
# 给定负RPN样本的权重
# Set to -1.0 to use uniform example weighting
# 这里正负样本使用相同权重
__C.TRAIN.RPN_POSITIVE_WEIGHT = -1.0
 
#
# Testing options
# 测试选项
#
 
__C.TEST = edict()
 
# Scales to use during testing (can list multiple scales)
# Each scale is the pixel size of an image's shortest side
__C.TEST.SCALES = (600,)
 
# Max pixel size of the longest side of a scaled input image
__C.TEST.MAX_SIZE = 1000
 
# Overlap threshold used for non-maximum suppression (suppress boxes with
# IoU >= this threshold)
# 测试时非极大值抑制的阈值
__C.TEST.NMS = 0.3
 
# Experimental: treat the (K+1) units in the cls_score layer as linear
# predictors (trained, eg, with one-vs-rest SVMs).
# 分类不再用SVM,设置为False
__C.TEST.SVM = False
 
# Test using bounding-box regressors
# 使用bb回归
__C.TEST.BBOX_REG = True
 
# Propose boxes
# 不使用RPN生成proposal
__C.TEST.HAS_RPN = False
 
# Test using these proposals
# 使用selective_search生成proposal
__C.TEST.PROPOSAL_METHOD = 'selective_search'
 
## NMS threshold used on RPN proposals
#  RPN proposal的NMS阈值
__C.TEST.RPN_NMS_THRESH = 0.7
## Number of top scoring boxes to keep before apply NMS to RPN proposals
__C.TEST.RPN_PRE_NMS_TOP_N = 6000
## Number of top scoring boxes to keep after applying NMS to RPN proposals
__C.TEST.RPN_POST_NMS_TOP_N = 300
# Proposal height and width both need to be greater than RPN_MIN_SIZE (at orig image scale)
__C.TEST.RPN_MIN_SIZE = 16
 
#
# MISC
#
 
# The mapping from image coordinates to feature map coordinates might cause
# 从原图到feature map的坐标映射,可能会造成在原图上不同的box到了feature map坐标系上变得相同了
# some boxes that are distinct in image space to become identical in feature
# coordinates. If DEDUP_BOXES > 0, then DEDUP_BOXES is used as the scale factor
# for identifying duplicate boxes.
# 1/16 is correct for {Alex,Caffe}Net, VGG_CNN_M_1024, and VGG16
# 缩放因子
__C.DEDUP_BOXES = 1./16.
 
# Pixel mean values (BGR order) as a (1, 1, 3) array
# We use the same pixel mean for all networks even though it's not exactly what
# they were trained with
# 所有network所用的像素均值设为相同
__C.PIXEL_MEANS = np.array([[[102.9801, 115.9465, 122.7717]]])
 
# For reproducibility
__C.RNG_SEED = 3
 
# A small number that's used many times
# 极小的数
__C.EPS = 1e-14
 
# Root directory of project
# 项目根路径
__C.ROOT_DIR = osp.abspath(osp.join(osp.dirname(__file__), '..', '..'))
 
# Data directory
# 数据路径
__C.DATA_DIR = osp.abspath(osp.join(__C.ROOT_DIR, 'data'))
 
# Model directory
# 模型路径
__C.MODELS_DIR = osp.abspath(osp.join(__C.ROOT_DIR, 'models', 'pascal_voc'))
 
# Name (or path to) the matlab executable
# matlab executable
__C.MATLAB = 'matlab'
 
# Place outputs under an experiments directory
# 输出在experiments路径下
__C.EXP_DIR = 'default'
 
# Use GPU implementation of non-maximum suppression
# GPU实施非极大值抑制
__C.USE_GPU_NMS = True
 
# Default GPU device id
# 默认GPU id
__C.GPU_ID = 0
 
def get_output_dir(imdb, net=None):
    #返回输出路径,在experiments路径下
    """Return the directory where experimental artifacts are placed.
    If the directory does not exist, it is created.
 
    A canonical标准 path is built using the name from an imdb and a network
    (if not None).
    """
    outdir = osp.abspath(osp.join(__C.ROOT_DIR, 'output', __C.EXP_DIR, imdb.name))
    if net is not None:
        outdir = osp.join(outdir, net.name)
    if not os.path.exists(outdir):
        os.makedirs(outdir)
    return outdir
 
def _merge_a_into_b(a, b):
    #两个配置文件融合
    """Merge config dictionary a into config dictionary b, clobbering the
    options in b whenever they are also specified in a.
    """
    if type(a) is not edict:
        return
 
    for k, v in a.iteritems():
        # a must specify keys that are in b
        if not b.has_key(k):
            raise KeyError('{} is not a valid config key'.format(k))
 
        # the types must match, too
        old_type = type(b[k])
        if old_type is not type(v):
            if isinstance(b[k], np.ndarray):
                v = np.array(v, dtype=b[k].dtype)
            else:
                raise ValueError(('Type mismatch ({} vs. {}) '
                                'for config key: {}').format(type(b[k]),
                                                            type(v), k))
 
        # recursively merge dicts
        if type(v) is edict:
            try:
                _merge_a_into_b(a[k], b[k])
            except:
                print('Error under config key: {}'.format(k))
                raise
        #用配置a更新配置b的对应项
        else:
            b[k] = v
 
def cfg_from_file(filename):
    """Load a config file and merge it into the default options."""
    # 导入配置文件并与默认选项融合
    import yaml
    with open(filename, 'r') as f:
        yaml_cfg = edict(yaml.load(f))
 
    _merge_a_into_b(yaml_cfg, __C)
 
def cfg_from_list(cfg_list):
    # 命令行设置config
    """Set config keys via list (e.g., from command line)."""
    from ast import literal_eval
    assert len(cfg_list) % 2 == 0
    for k, v in zip(cfg_list[0::2], cfg_list[1::2]):
        key_list = k.split('.')
        d = __C
        for subkey in key_list[:-1]:
            assert d.has_key(subkey)
            d = d[subkey]
        subkey = key_list[-1]
        assert d.has_key(subkey)
        try:
            value = literal_eval(v)
        except:
            # handle the case when v is a string literal
            value = v
        assert type(value) == type(d[subkey]), \
            'type {} does not match original type {}'.format(
            type(value), type(d[subkey]))
        d[subkey] = value

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

tf-faster-rcnn config.py 参数详解 的相关文章

随机推荐

  • osgEarth的Rex引擎原理分析(九十五)地形变形(Terrain morphing)

    目标 十二 中的问题14 morphing翻译为渐变 或混合 比较合适 先看两张图 左图是使用了Image morphing 右图没有使用 morph的作用是使视域边界处的瓦片颜色和高程均匀变化 Image morphing控制颜色 Ter
  • 强大的PropertyGrid

    PropertyGrid 做工具一定要用这东西 把要编辑的对象看成类的话 所有要编辑的属性就是成员 嗯嗯 最近看了几眼Ogitor 它对于PropertyGrid的使用就很不错 所有要编辑的对象 灯光 模型 粒子等等 都有一个共同的基类 每
  • python 安装第三方库,超时报错--Read timed out.

    Traceback most recent call last File home xiaoduc pyenv versions 3 5 0 lib python3 5 site packages pip vendor requests p
  • OpenGL天空盒skybox

    目录 痛彻的感悟 天空盒可能的难题 天空盒代码 痛彻的感悟 今天考完试才发现自己和别人的差距还挺大的 四五六班下午的考试题目 我很快做了出来 但是自己的班级的考试题目 我竟然一道都没有成功 所以我决定把我之前准备的代码公布一下 也希望对一些
  • 用Python写一个植物大战僵尸

    上次写了一个俄罗斯方块 感觉好像大家都看懂了 这次就更新一个植物大战僵尸吧 植物大战僵尸的话 Python源码 问题解答学习交流群 773162165 引入需要的模块 import pygame import random 配置图片地址 I
  • Spring中IOC详解

    一 IOC的原型 IOC 控制反转 比如我们有一个功能是获取用户数据 我们使用Dao层实现这个功能 再在Service层调用这个功能 但是我们每增加一个接口 比如获取mysql中的数据 就要修改原来的代码 如果再增加一个新的接口 又需要去s
  • 优质github项目集合-珍藏版

    这是是一个聚集优质github项目的整合 推荐收藏 宗旨 GitHubDaily 将于每日不定时推送一批 GitHub 上优秀的开源项目给开发者 帮助开发者们发现当下最火的开源项目 令开发者们得以掌控技术脉搏 扩大自己的技术视野 并从开源项
  • sharepoint 工作经验与技能总结

    可能是由于平时工作比较忙 博客也写得少了 最近偶尔被同行的同事朋友问起 我一直在做sharepoint方面的工作 没有打算换asp net C 方面的工作吗 有的还问了句网上很流行的话 你都会啥绝活 哈哈 被问多了之后 我也还真问自己 工作
  • 华为交换机、路由器设备怎样配置console登录密码

    华为交换机路由器设备怎样配置console密码 在对路由器交换机等网络进行管理中 为了安全起见经常需要为设备配置登录密码 尤其是使用串口线直连设备时 console线路密码认证有两种方式 1 只配置password 密码 2 aaa认证模式
  • 【STM32+cubemx】0024 HAL库开发:IAP(在应用编程)的实现

    IAP在应用编程 In Application Programming 指的是MCU在运行应用程序时 能接收新的烧写文件 并更新到自身的程序存储器中 即可以在应用程序运行时在线升级 本节我们通过一个简单的例子 来实现STM32的IAP功能
  • 大数据学习笔记——zookeeper在hadoop集群中的作用

    zookeeper主要是用来搭建高可用的Hadoop集群 即High Availability 简称 HA 测试中集群是可以不需要高可用的 即使用一个namenode即可 但是在生产环境中为了提高集群的可靠性 需要增加一个namenode备
  • 遇到的有关的二进制的题目整理

    前n个数字二进制中1的个数 解答来自评论区大佬 如果正整数 i 是一个偶数 那么 i 相当于将 i 2 左移一位的结果 因此偶数 i 和 i 2 的二进制形式 1 的个数是一样的 如果 i 是奇数 那么 i 相当于将 i 2 左移一位之后再
  • MySQL索引在关联查询中的作用

    索引关联理解 inner join left join 如果是inner join的话 一边有索引就可以了 如果是left join 主表可以不用索引 但另外张就要索引 切记 小表驱动大表 给被驱动表建立索引 EXPLAIN语句分析出来的第
  • 【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点

    目录标题 算法汇总 题目 关键点 代码 1 解体方法 思路 代码 时间和空间复杂度 2 解题方法 如暴力法 思路 代码 时间和空间复杂度 算法汇总 以下是所有算法汇总 包括GitHub源码地址链接 力扣算法练习汇总 持续更新 题目 剑指 O
  • 数据结构学习系列之单向链表的查找与修改

    单向链表的查找 根据单向链表数据结点的位置查找数据 代码如下 示例代码 int search link list node t phead int pos int data if NULL phead NULL data printf 入参
  • lua中使用json:table转json与json转table

    直接上代码 json lua JSON4Lua JSON encoding decoding support for the Lua language json Module Author Craig Mason Jones Homepag
  • 基于mybatis拦截器实现数据权限

    需求场景 业务要求对列表查询功能添加数据权限控制 比如 给用户A针对某些订单模块设置一些查询条件 比如地址 山东 运输方式 空运 商品大类 家电 当用户访问订单模块时 只能访问满足这些条件的数据 需求分析 要实现动态条件拼接 需要在执行查询
  • 解析LDO的基本原理与主要参数

    低压差线性稳压器 LDO 的基本电路如图1 1所示 该电路由串联调整管VT 取样电阻R1和R2 比较放大器A组成 取样电压加在比较器A的同相输入端 与加在反相输入端的基准电压Uref相比较 两者的差值经放大器A放大后 控制串联调整管的压降
  • 过滤器实现网站访问计数

    创建一个过滤器 实现网站访问计数器的功能 并在web xml文件的配置中将网站访问量的初始值设置为5000 创建名称为CountFilter的类 创建名称为CountFilter的类 该类实现javax servlet Filter接口 是
  • tf-faster-rcnn config.py 参数详解

    import os import os path as osp import numpy as np pip install easydict if you don t have it from easydict import EasyDi