mmdetction

mmdet/models/detectors/cascade_rcnn.py
关于管道results[‘img’]


    def forward_train(self,
                      img,
                      img_meta,
                      gt_bboxes,
                      gt_labels,
                      gt_bboxes_ignore=None,
                      gt_masks=None,
                      proposals=None):
        """
        Args:
            img (Tensor): of shape (N, C, H, W) encoding input images.
                Typically these should be mean centered and std scaled.

            img_meta (list[dict]): list of image info dict where each dict has:
                'img_shape', 'scale_factor', 'flip', and my also contain
                'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
                For details on the values of these keys see
                `mmdet/datasets/pipelines/formatting.py:Collect`.

            gt_bboxes (list[Tensor]): each item are the truth boxes for each
                image in [tl_x, tl_y, br_x, br_y] format.

            gt_labels (list[Tensor]): class indices corresponding to each box

            gt_bboxes_ignore (None | list[Tensor]): specify which bounding
                boxes can be ignored when computing the loss.

            gt_masks (None | Tensor) : true segmentation masks for each box
                used if the architecture supports a segmentation task.

            proposals : override rpn proposals with custom proposals. Use when
                `with_rpn` is False.

        Returns:
            dict[str, Tensor]: a dictionary of loss components
        """

cofig里 train_config里的rcnn第一个sampler改为OHEMSampler报错
TypreError loss() missing 1 required positional argument ‘pos_bboxes’

原因: mmdet/core/bbox/samplers/ohem_sampler.py里 hardming函数里的loss缺参数pos_boxes=None
loss of bbox_head 见mmdet/models/bbox_head/bbox_heads.py BBoxHead类的loss函数
loss函数里将loss_cls loss_bbox两个key分别存放在字典loss()里

ohem原文

更改loss在 mmdet/models/losses/cross_entropy.py register相关参数然后在__init__.py里更新

更改lr_ 相关的是在mmcv里就有写好的可选的’cosine’ 'step’等学习率

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在mmdetection中添加自定义数据增强,可以按照以下步骤进行操作: 1. 创建自定义数据增强类 在mmdetection的代码中找到`mmdet/datasets/pipelines`文件夹,在该文件夹下面创建一个新的python文件,例如`my_augmentations.py`。在该文件中定义一个自定义的数据增强类,例如: ```python import numpy as np from mmdet.core.evaluation.bbox_overlaps import bbox_overlaps class MyAugmentation: def __init__(self, prob=0.5): self.prob = prob def __call__(self, results): if np.random.rand() < self.prob: # perform some data augmentation operations # ... return results else: return results ``` 在这个例子中,我们定义了一个名为`MyAugmentation`的类,它有一个`prob`参数,表示增强的概率,以及一个`__call__`方法,该方法将在数据增强时被调用。在`__call__`方法中,我们可以实现一些自定义的数据增强操作。这个例子中的操作是随机选择是否对数据进行增强。 2. 在配置文件中添加自定义数据增强 在使用自定义数据增强之前,我们需要在配置文件中添加它。找到你要使用的配置文件,例如`configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py`,并在`train_pipeline`和`test_pipeline`中添加自定义数据增强,例如: ```python train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True), dict(type='RandomFlip', flip_ratio=0.5), dict(type='MyAugmentation', prob=0.5), dict(type='Normalize', **img_norm_cfg), dict(type='Pad', size_divisor=32), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']), ] test_pipeline = [ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=(1333, 800), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='MyAugmentation', prob=0.5), dict(type='Normalize', **img_norm_cfg), dict(type='Pad', size_divisor=32), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']), ] ) ] ``` 在这个例子中,我们在`train_pipeline`和`test_pipeline`中分别添加了一个`MyAugmentation`操作,其概率为0.5。注意,自定义操作需要在其他操作之前进行,因为它们可能会改变图像和标注框的大小和形状。 3. 运行训练和测试 添加自定义数据增强后,我们可以像平常一样运行训练和测试。在运行过程中,自定义数据增强会被应用到输入数据中,从而增加模型的鲁棒性和泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值