class detectron2.config.CfgNode(init_dict=None, key_list=None, new_allowed=False)
源代码:https://detectron2.readthedocs.io/_modules/detectron2/config/config.html#CfgNode
基类:fvcore.common.config.CfgNode
与fvcore.common.config.CfgNode相同,但不同之处在于:
默认情况下使用不安全的Yaml加载。
请注意,这可能会导致不安全代码执行:在手动检查文件内容之前,切勿从不受信任的源中加载配置文件。
支持配置版本控制。
尝试合并旧配置时,它将自动转换旧配置。
merge_from_file(cfg_filename: str, allow_unsafe: bool = True) None
dump(*args, **kwargs)
返回值:str –配置的yaml字符串表示形式
DEPRECATED_KEYS= ‘__deprecated_keys__’
IMMUTABLE= ‘__immutable__’
NEW_ALLOWED= ‘__new_allowed__’
RENAMED_KEYS=’__renamed_keys__’
__init__(init_dict=None, key_list=None, new_allowed=False)
参数:
init_dict(dict)–可能嵌套的字典,用于初始化CfgNode。
key_list(list [ str ])–名称列表,从根目录索引此CfgNode。当前仅用于记录目的。
new_allowed(bool)–与其他配置合并时是否允许添加新密钥。
clear() None,从D删除所有项目
clone()
递归复制此CfgNode。
copy() D的浅副本
defrost()
使此CfgNode及其所有子代可变。
freeze()
使此CfgNode及其所有子代不变。
fromkeys()
使用可迭代的键并将值设置为value创建一个新字典。
get()
如果key在字典中,则返回key的值,否则返回默认值。
is_frozen()
返回可变性。
is_new_allowed()
items() 提供D的项目视图的类集合对象
key_is_deprecated(full_key)
测试是否不支持使用密钥。
key_is_renamed(full_key)
测试密钥是否被重命名。
keys() 提供D键视图的类集合对象
class method load_cfg(cfg_file_obj_or_str)
加载cfg:param cfg_file_obj_or_str:支持从以下对象加载:
由YAML文件支持的文件对象
由Python源文件支持的文件对象,该文件对象导出dict或CfgNode属性”cfg”
可以解析为有效YAML的字符串
static load_yaml_with_base(filename: str, allow_unsafe: bool = False)
就像yaml.load(open(filename))一样,但从其继承属性
参数:
filename(str):当前配置的文件名。将用于查找基本配置文件。
allow_unsafe(bool):是否允许使用yaml.unsafe_load加载配置文件 。
返回值:(字典) 已加载的Yaml
merge_from_list(cfg_list: list)
参数: cfg_list(list):要合并的配置列表。
merge_from_other_cfg(cfg_other)
参数: cfg_other(CfgNode)要合并的配置。
pop(k[, d]) v, remove specified key and return the corresponding value.
如果找不到键,则返回d(如果给出),否则引发KeyError
popitem() (k, v), remove and return some (key, value) pair as a
2元组; 但如果D为空,则引发KeyError。
raise_key_rename_error(full_key)
register_deprecated_key(key)
注册密钥(例如FOO.BAR)已弃用的选项。合并不支持使用的密钥时,将生成警告,并且该密钥将被忽略。
register_renamed_key(old_name, new_name, message=None)
将密钥注册从old_name重命名为new_name。合并重命名的密钥时,会引发异常,警告用户该密钥已被重命名。
setdefault()
如果key不在字典中,则插入具有默认值的key。
如果key在字典中,则返回key的值,否则返回默认值。
update([E, ]**F) None. Update D from dict/iterable E and F.
如果E存在并且具有.keys()方法,则执行:for k in E: D[k] = E[k]
如果E存在并且没有.keys()方法,则执行:for k, v in E: D[k] = v
在任一情况下,都跟着:for k in F: D[k] = F[k]
values() 提供D值视图的对象
detectron2.config.get_cfg() detectron2.config.config.CfgNode
源代码:https://detectron2.readthedocs.io/_modules/detectron2/config/config.html#get_cfg
获取默认配置的副本。
返回值: 一个detectron2 CfgNode实例。
detectron2.config.set_global_cfg(cfg: detectron2.config.config.CfgNode) None
源代码:https://detectron2.readthedocs.io/_modules/detectron2/config/config.html#set_global_cfg
让全局配置指向给定的cfg。
假定给定的”cfg”具有键”KEY”,在调用 set_global_cfg(cfg)之后,可以通过以下方式访问该键:
from detectron2.config import global_cfg
print(global_cfg.KEY)
通过使用hacky全局配置,你可以在任何地方访问这些配置,而不必将配置对象或值传递到代码中。这是为快速原型设计/研究探索而引入的一项功能强大的功能。
detectron2.config.downgrade_config(cfg: detectron2.config.config.CfgNode, to_version: int) detectron2.config.config.CfgNode
源代码:https://detectron2.readthedocs.io/_modules/detectron2/config/compat.html#downgrade_config
将配置从当前版本降级到旧版本。
参数:
cfg(CfgNode)
to_version(int)
注意
由于不同版本中的功能不同,通常无法对任意配置进行普遍降级。降级的目的仅是恢复旧版本中的默认设置,从而允许它加载旧的部分Yaml配置,因此仅当无法进行一般降级时,实现才需要填写旧版本中的默认值。
detectron2.config.upgrade_config(cfg: detectron2.config.config.CfgNode, to_version: Optional[int] = None) detectron2.config.config.CfgNode
源代码:https://detectron2.readthedocs.io/_modules/detectron2/config/compat.html#upgrade_config
将配置从当前版本升级到更高版本。
参数:
cfg(CfgNode)
to_version(int)默认为最新版本。
配置参考
# —————————————————————————–
# Convention about Training / Test specific parameters
# —————————————————————————–
# Whenever an argument can be either used for training or for testing, the
# corresponding name will be post-fixed by a _TRAIN for a training parameter,
# or _TEST for a test-specific parameter.
# For example, the number of images during training will be
# IMAGES_PER_BATCH_TRAIN, while the number of images for testing will be
# IMAGES_PER_BATCH_TEST
# —————————————————————————–
# Config definition
# —————————————————————————–
_C = CN()
# The version number, to upgrade from old configs to new ones if any
# changes happen. It’s recommended to keep a VERSION in your config file.
_C.VERSION = 2
_C.MODEL = CN()
_C.MODEL.LOAD_PROPOSALS = False
_C.MODEL.MASK_ON = False
_C.MODEL.KEYPOINT_ON = False
_C.MODEL.DEVICE = “cuda”
_C.MODEL.META_ARCHITECTURE = “GeneralizedRCNN”
# Path (possibly with schema like catalog:// or detectron2://) to a checkpoint file
# to be loaded to the model. You can find available models in the model zoo.
_C.MODEL.WEIGHTS = “”
# Values to be used for image normalization (BGR order, since INPUT.FORMAT defaults to BGR).
# To train on images of different number of channels, just set different mean & std.
# Default values are the mean pixel value from ImageNet: [103.53, 116.28, 123.675]
_C.MODEL.PIXEL_MEAN = [103.530, 116.280, 123.675]
# When using pre-trained models in Detectron1 or any MSRA models,
# std has been absorbed into its conv1 weights, so the std needs to be set 1.
# Otherwise, you can use [57.375, 57.120, 58.395] (ImageNet std)
_C.MODEL.PIXEL_STD = [1.0, 1.0, 1.0]
# —————————————————————————–
# INPUT
# —————————————————————————–
_C.INPUT = CN()
# Size of the smallest side of the image during training
_C.INPUT.MIN_SIZE_TRAIN = (800,)
# Sample size of smallest side by choice or random selection from range give by
# INPUT.MIN_SIZE_TRAIN
_C.INPUT.MIN_SIZE_TRAIN_SAMPLING = “choice”
# Maximum size of the side of the image during training
_C.INPUT.MAX_SIZE_TRAIN = 1333
# Size of the smallest side of the image during testing. Set to zero to disable resize in testing.
_C.INPUT.MIN_SIZE_TEST = 800
# Maximum size of the side of the image during testing
_C.INPUT.MAX_SIZE_TEST = 1333
# `True` if cropping is used for data augmentation during training
_C.INPUT.CROP = CN({“ENABLED”: False})
# Cropping type:
# – “relative” crop (H * CROP.SIZE[0], W * CROP.SIZE[1]) part of an input of size (H, W)
# – “relative_range” uniformly sample relative crop size from between [CROP.SIZE[0], [CROP.SIZE[1]].
# and [1, 1] and use it as in “relative” scenario.
# – “absolute” crop part of an input with absolute size: (CROP.SIZE[0], CROP.SIZE[1]).
_C.INPUT.CROP.TYPE = “relative_range”
# Size of crop in range (0, 1] if CROP.TYPE is “relative” or “relative_range” and in number of
# pixels if CROP.TYPE is “absolute”
_C.INPUT.CROP.SIZE = [0.9, 0.9]
# Whether the model needs RGB, YUV, HSV etc.
# Should be one of the modes defined here, as we use PIL to read the image:
# https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes
# with BGR being the one exception. One can set image format to BGR, we will
# internally use RGB for conversion and flip the channels over
_C.INPUT.FORMAT = “BGR”
# The ground truth mask format that the model will use.
# Mask R-CNN supports either “polygon” or “bitmask” as ground truth.
_C.INPUT.MASK_FORMAT = “polygon” # alternative: “bitmask”
# —————————————————————————–
# Dataset
# —————————————————————————–
_C.DATASETS = CN()
# List of the dataset names for training. Must be registered in DatasetCatalog
_C.DATASETS.TRAIN = ()
# List of the pre-computed proposal files for training, which must be consistent
# with datasets listed in DATASETS.TRAIN.
_C.DATASETS.PROPOSAL_FILES_TRAIN = ()
# Number of top scoring precomputed proposals to keep for training
_C.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN = 2000
# List of the dataset names for testing. Must be registered in DatasetCatalog
_C.DATASETS.TEST = ()
# List of the pre-computed proposal files for test, which must be consistent
# with datasets listed in DATASETS.TEST.
_C.DATASETS.PROPOSAL_FILES_TEST = ()
# Number of top scoring precomputed proposals to keep for test
_C.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST = 1000
# —————————————————————————–
# DataLoader
# —————————————————————————–
_C.DATALOADER = CN()
# Number of data loading threads
_C.DATALOADER.NUM_WORKERS = 4
# If True, each batch should contain only images for which the aspect ratio
# is compatible. This groups portrait images together, and landscape images
# are not batched with portrait images.
_C.DATALOADER.ASPECT_RATIO_GROUPING = True
# Options: TrainingSampler, RepeatFactorTrainingSampler
_C.DATALOADER.SAMPLER_TRAIN = “TrainingSampler”
# Repeat threshold for RepeatFactorTrainingSampler
_C.DATALOADER.REPEAT_THRESHOLD = 0.0
# if True, the dataloader will filter out images that have no associated
# annotations at train time.
_C.DATALOADER.FILTER_EMPTY_ANNOTATIONS = True
# —————————————————————————- #
# Backbone options
# —————————————————————————- #
_C.MODEL.BACKBONE = CN()
_C.MODEL.BACKBONE.NAME = “build_resnet_backbone”
# Freeze the first several stages so they are not trained.
# There are 5 stages in ResNet. The first is a convolution, and the following
# stages are each group of residual blocks.
_C.MODEL.BACKBONE.FREEZE_AT = 2
# —————————————————————————- #
# FPN options
# —————————————————————————- #
_C.MODEL.FPN = CN()
# Names of the input feature maps to be used by FPN
# They must have contiguous power of 2 strides
# e.g., [“res2”, “res3”, “res4”, “res5”]
_C.MODEL.FPN.IN_FEATURES = []
_C.MODEL.FPN.OUT_CHANNELS = 256
# Options: “” (no norm), “GN”
_C.MODEL.FPN.NORM = “”
# Types for fusing the FPN top-down and lateral features. Can be either “sum” or “avg”
_C.MODEL.FPN.FUSE_TYPE = “sum”
# —————————————————————————- #
# Proposal generator options
# —————————————————————————- #
_C.MODEL.PROPOSAL_GENERATOR = CN()
# Current proposal generators include “RPN”, “RRPN” and “PrecomputedProposals”
_C.MODEL.PROPOSAL_GENERATOR.NAME = “RPN”
# Proposal height and width both need to be greater than MIN_SIZE
# (a the scale used during training or inference)
_C.MODEL.PROPOSAL_GENERATOR.MIN_SIZE =
# —————————————————————————- #
# Anchor generator options
# —————————————————————————- #
_C.MODEL.ANCHOR_GENERATOR = CN()
# The generator can be any name in the ANCHOR_GENERATOR registry
_C.MODEL.ANCHOR_GENERATOR.NAME = “DefaultAnchorGenerator”
# Anchor sizes (i.e. sqrt of area) in absolute pixels w.r.t. the network input.
# Format: list[list[int]]. SIZES[i] specifies the list of sizes
# to use for IN_FEATURES[i]; len(SIZES) == len(IN_FEATURES) must be true,
# or len(SIZES) == 1 is true and size list SIZES[0] is used for all
# IN_FEATURES.
_C.MODEL.ANCHOR_GENERATOR.SIZES = [[32, 64, 128, 256, 512]]
# Anchor aspect ratios. For each area given in `SIZES`, anchors with different aspect
# ratios are generated by an anchor generator.
# Format: list[list[int]]. ASPECT_RATIOS[i] specifies the list of aspect ratios
# to use for IN_FEATURES[i]; len(ASPECT_RATIOS) == len(IN_FEATURES) must be true,
# or len(ASPECT_RATIOS) == 1 is true and aspect ratio list ASPECT_RATIOS[0] is used
# for all IN_FEATURES.
_C.MODEL.ANCHOR_GENERATOR.ASPECT_RATIOS = [[0.5, 1.0, 2.0]]
# Anchor angles.
# list[float], the angle in degrees, for each input feature map.
# ANGLES[i] specifies the list of angles for IN_FEATURES[i].
_C.MODEL.ANCHOR_GENERATOR.ANGLES = [[-90, , 90]]
# Relative offset between the center of the first anchor and the top-left corner of the image
# Units: fraction of feature map stride (e.g., 0.5 means half stride)
# Allowed values are floats in [0, 1) range inclusive.
# Recommended value is 0.5, although it is not expected to affect model accuracy.
_C.MODEL.ANCHOR_GENERATOR.OFFSET = 0.0
# —————————————————————————- #
# RPN options
# —————————————————————————- #
_C.MODEL.RPN = CN()
_C.MODEL.RPN.HEAD_NAME = “StandardRPNHead” # used by RPN_HEAD_REGISTRY
# Names of the input feature maps to be used by RPN
# e.g., [“p2”, “p3”, “p4”, “p5”, “p6”] for FPN
_C.MODEL.RPN.IN_FEATURES = [“res4”]
# Remove RPN anchors that go outside the image by BOUNDARY_THRESH pixels
# Set to -1 or a large value, e.g. 100000, to disable pruning anchors
_C.MODEL.RPN.BOUNDARY_THRESH = -1
# IOU overlap ratios [BG_IOU_THRESHOLD, FG_IOU_THRESHOLD]
# Minimum overlap required between an anchor and ground-truth box for the
# (anchor, gt box) pair to be a positive example (IoU >= FG_IOU_THRESHOLD
# ==> positive RPN example: 1)
# Maximum overlap allowed between an anchor and ground-truth box for the
# (anchor, gt box) pair to be a negative examples (IoU
# ==> negative RPN example: 0)
# Anchors with overlap in between (BG_IOU_THRESHOLD
# are ignored (-1)
_C.MODEL.RPN.IOU_THRESHOLDS = [0.3, 0.7]
_C.MODEL.RPN.IOU_LABELS = [, -1, 1]
# Total number of RPN examples per image
_C.MODEL.RPN.BATCH_SIZE_PER_IMAGE = 256
# Target fraction of foreground (positive) examples per RPN minibatch
_C.MODEL.RPN.POSITIVE_FRACTION = 0.5
# Weights on (dx, dy, dw, dh) for normalizing RPN anchor regression targets
_C.MODEL.RPN.BBOX_REG_WEIGHTS = (1.0, 1.0, 1.0, 1.0)
# The transition point from L1 to L2 loss. Set to 0.0 to make the loss simply L1.
_C.MODEL.RPN.SMOOTH_L1_BETA = 0.0
_C.MODEL.RPN.LOSS_WEIGHT = 1.0
# Number of top scoring RPN proposals to keep before applying NMS
# When FPN is used, this is *per FPN level* (not total)
_C.MODEL.RPN.PRE_NMS_TOPK_TRAIN = 12000
_C.MODEL.RPN.PRE_NMS_TOPK_TEST = 6000
# Number of top scoring RPN proposals to keep after applying NMS
# When FPN is used, this limit is applied per level and then again to the union
# of proposals from all levels
# NOTE: When FPN is used, the meaning of this config is different from Detectron1.
# It means per-batch topk in Detectron1, but per-image topk here.
# See “modeling/rpn/rpn_outputs.py” for details.
_C.MODEL.RPN.POST_NMS_TOPK_TRAIN = 2000
_C.MODEL.RPN.POST_NMS_TOPK_TEST = 1000
# NMS threshold used on RPN proposals
_C.MODEL.RPN.NMS_THRESH = 0.7
# —————————————————————————- #
# ROI HEADS options
# —————————————————————————- #
_C.MODEL.ROI_HEADS = CN()
_C.MODEL.ROI_HEADS.NAME = “Res5ROIHeads”
# Number of foreground classes
_C.MODEL.ROI_HEADS.NUM_CLASSES = 80
# Names of the input feature maps to be used by ROI heads
# Currently all heads (box, mask, …) use the same input feature map list
# e.g., [“p2”, “p3”, “p4”, “p5”] is commonly used for FPN
_C.MODEL.ROI_HEADS.IN_FEATURES = [“res4”]
# IOU overlap ratios [IOU_THRESHOLD]
# Overlap threshold for an RoI to be considered background (if
# Overlap threshold for an RoI to be considered foreground (if >= IOU_THRESHOLD)
_C.MODEL.ROI_HEADS.IOU_THRESHOLDS = [0.5]
_C.MODEL.ROI_HEADS.IOU_LABELS = [, 1]
# RoI minibatch size *per image* (number of regions of interest [ROIs])
# Total number of RoIs per training minibatch =
# ROI_HEADS.BATCH_SIZE_PER_IMAGE * SOLVER.IMS_PER_BATCH
# E.g., a common configuration is: 512 * 16 = 8192
_C.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 512
# Target fraction of RoI minibatch that is labeled foreground (i.e. class > 0)
_C.MODEL.ROI_HEADS.POSITIVE_FRACTION = 0.25
# Only used on test mode
# Minimum score threshold (assuming scores in a [0, 1] range); a value chosen to
# balance obtaining high recall with not having too many low precision
# detections that will slow down inference post processing steps (like NMS)
# A default threshold of 0.0 increases AP by ~0.2-0.3 but significantly slows down
# inference.
_C.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.05
# Overlap threshold used for non-maximum suppression (suppress boxes with
# IoU >= this threshold)
_C.MODEL.ROI_HEADS.NMS_THRESH_TEST = 0.5
# If True, augment proposals with ground-truth boxes before sampling proposals to
# train ROI heads.
_C.MODEL.ROI_HEADS.PROPOSAL_APPEND_GT = True
# —————————————————————————- #
# Box Head
# —————————————————————————- #
_C.MODEL.ROI_BOX_HEAD = CN()
# C4 don’t use head name option
# Options for non-C4 models: FastRCNNConvFCHead,
_C.MODEL.ROI_BOX_HEAD.NAME = “”
# Default weights on (dx, dy, dw, dh) for normalizing bbox regression targets
# These are empirically chosen to approximately lead to unit variance targets
_C.MODEL.ROI_BOX_HEAD.BBOX_REG_WEIGHTS = (10.0, 10.0, 5.0, 5.0)
# The transition point from L1 to L2 loss. Set to 0.0 to make the loss simply L1.
_C.MODEL.ROI_BOX_HEAD.SMOOTH_L1_BETA = 0.0
_C.MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION = 14
_C.MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO =
# Type of pooling operation applied to the incoming feature map for each RoI
_C.MODEL.ROI_BOX_HEAD.POOLER_TYPE = “ROIAlignV2”
_C.MODEL.ROI_BOX_HEAD.NUM_FC =
# Hidden layer dimension for FC layers in the RoI box head
_C.MODEL.ROI_BOX_HEAD.FC_DIM = 1024
_C.MODEL.ROI_BOX_HEAD.NUM_CONV =
# Channel dimension for Conv layers in the RoI box head
_C.MODEL.ROI_BOX_HEAD.CONV_DIM = 256
# Normalization method for the convolution layers.
# Options: “” (no norm), “GN”, “SyncBN”.
_C.MODEL.ROI_BOX_HEAD.NORM = “”
# Whether to use class agnostic for bbox regression
_C.MODEL.ROI_BOX_HEAD.CLS_AGNOSTIC_BBOX_REG = False
# If true, RoI heads use bounding boxes predicted by the box head rather than proposal boxes.
_C.MODEL.ROI_BOX_HEAD.TRAIN_ON_PRED_BOXES = False
# —————————————————————————- #
# Cascaded Box Head
# —————————————————————————- #
_C.MODEL.ROI_BOX_CASCADE_HEAD = CN()
# The number of cascade stages is implicitly defined by the length of the following two configs.
_C.MODEL.ROI_BOX_CASCADE_HEAD.BBOX_REG_WEIGHTS = (
(10.0, 10.0, 5.0, 5.0),
(20.0, 20.0, 10.0, 10.0),
(30.0, 30.0, 15.0, 15.0),
)
_C.MODEL.ROI_BOX_CASCADE_HEAD.IOUS = (0.5, 0.6, 0.7)
# —————————————————————————- #
# Mask Head
# —————————————————————————- #
_C.MODEL.ROI_MASK_HEAD = CN()
_C.MODEL.ROI_MASK_HEAD.NAME = “MaskRCNNConvUpsampleHead”
_C.MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION = 14
_C.MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO =
_C.MODEL.ROI_MASK_HEAD.NUM_CONV = # The number of convs in the mask head
_C.MODEL.ROI_MASK_HEAD.CONV_DIM = 256
# Normalization method for the convolution layers.
# Options: “” (no norm), “GN”, “SyncBN”.
_C.MODEL.ROI_MASK_HEAD.NORM = “”
# Whether to use class agnostic for mask prediction
_C.MODEL.ROI_MASK_HEAD.CLS_AGNOSTIC_MASK = False
# Type of pooling operation applied to the incoming feature map for each RoI
_C.MODEL.ROI_MASK_HEAD.POOLER_TYPE = “ROIAlignV2”
# —————————————————————————- #
# Keypoint Head
# ————————————
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!