osuossu8 / kaggle_hubmap_2023

1 stars 0 forks source link

Add TTA #1

Open osuossu8 opened 1 year ago

osuossu8 commented 1 year ago

hflip and vflip

osuossu8 commented 1 year ago

https://mmdetection.readthedocs.io/en/3.x/user_guides/test.html?highlight=augmentation#test-time-augmentation-tta

DetTTAModel は segmentation に非対応だった

https://github.com/open-mmlab/mmdetection/blob/ecac3a77becc63f23d9f6980b2a36f86acd00a8a/mmdet/models/test_time_augs/det_tta.py#L16

osuossu8 commented 1 year ago

bbox は ↓ で flip, mask は np.fliplr で flip して自分で TTA https://www.kaggle.com/code/raufyagfarov/mmdetection-yolov4-pipeline-with-tta

osuossu8 commented 1 year ago

detection タスクのみの場合は ↓ でできそう


cfg = Config.fromfile(args.config)
cfg.tta_model = dict(
                type='DetTTAModel',
                tta_cfg=dict(
                    nms=dict(type='nms', iou_threshold=0.5), max_per_img=100))

# model の定義を DetTTAModel で上書きする
cfg.model = ConfigDict(**cfg.tta_model, module=cfg.model)
cfg.test_dataloader.dataset.pipeline = tta_pipeline = [
    dict(type='LoadImageFromNDArray',
        backend_args=None),
    dict(
        type='TestTimeAug',
        transforms=[[
            dict(type='Resize', scale=(1333, 800), keep_ratio=True)
        ], [ # It uses 2 flipping transformations (flipping and not flipping).
            dict(type='RandomFlip', prob=1.),
            dict(type='RandomFlip', prob=0.)
        ], [
            dict(
               type='PackDetInputs',
               meta_keys=('img_id', 'img_path', 'ori_shape',
                       'img_shape', 'scale_factor', 'flip',
                       'flip_direction'))
       ]])]

# config.py を保存
cfg.dump(save_path)
osuossu8 commented 1 year ago

lr のみだとスコア下がった (0.440 -> 0.423)