detectron2的数据在线增强


前言

关于一些detectron2的学习记录和分享,有问题可留言交流。

一、训练数据的在线增强

使用visualize_data.py观察dataloader里增强后用于训练的图片和标注。

train_data_loader = build_detection_train_loader(cfg) #构建训练数据loader

到data/build.py里找到build_detection_train_loader()

def build_detection_train_loader(cfg, mapper=None):
    if mapper is None:
        mapper = DatasetMapper(cfg, True) 

到dataset_mapper.py里

    def from_config(cls, cfg, is_train: bool = True):
    	#这个函数里可以增加数据增强方法
        augs = utils.build_augmentation(cfg, is_train)
        #对训练的数据做裁剪
        if cfg.INPUT.CROP.ENABLED and is_train:
            augs.insert(0, T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE))

到detection_utils.py里,做了resize和flip。

def build_augmentation(cfg, is_train):
    """
    Create a list of default :class:`Augmentation` from config.
    Now it includes resizing and flipping.

    Returns:
        list[Augmentation]
    """
    if is_train:
        min_size = cfg.INPUT.MIN_SIZE_TRAIN
        max_size = cfg.INPUT.MAX_SIZE_TRAIN
        sample_style = cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING
    else:
        min_size = cfg.INPUT.MIN_SIZE_TEST
        max_size = cfg.INPUT.MAX_SIZE_TEST
        sample_style = "choice"
    augmentation = [T.ResizeShortestEdge(min_size, max_size, sample_style)]
    if is_train and cfg.INPUT.RANDOM_FLIP != "none":
        augmentation.append(
            T.RandomFlip(
                horizontal=cfg.INPUT.RANDOM_FLIP == "horizontal",
                vertical=cfg.INPUT.RANDOM_FLIP == "vertical",
            )
        )
    return augmentation

一些自带的增强方法函数在augmentation_impl.py里

from .augmentation import Augmentation, _transform_to_aug
from .transform import ExtentTransform, ResizeTransform, RotationTransform
__all__ = [
    "RandomApply",
    "RandomBrightness",
    "RandomContrast",
    "RandomCrop",
    "RandomExtent",
    "RandomFlip",
    "RandomSaturation",
    "RandomLighting",
    "RandomRotation",
    "Resize",
    "ResizeShortestEdge",
    "RandomCrop_CategoryAreaConstraint",
]

不够用的话,可以在transform.py里,自己外面包一层就是上面的那些。
all = [
“ExtentTransform”,
“ResizeTransform”,
“RotationTransform”,
“ColorTransform”,
“PILColorTransform”,
]
暂时就这些

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值