def add_data_pipeline(cfg, params):
    cfg.dataset_type = 'COCODataset'
    cfg.classes = ('cots',)
    cfg.data_root = str(params['data_path'].resolve())
    params['aug_param']['img_scale'] = (params['img_size'], params['img_size'])
    cfg.img_scale = params['aug_param']['img_scale']
    cfg.dataset_type = 'CocoDataset'
    cfg.filter_empty_gt = False
    cfg.data.filter_empty_gt = False
    cfg.data.train.type = cfg.dataset_type
    cfg.data.train.classes = cfg.classes
    cfg.data.train.ann_file = str((params['cfg_dir'] / 'annotations_train.json'))
    cfg.data.train.img_prefix = (cfg.data_root + '/images/')
    cfg.data.train.filter_empty_gt = False
    cfg.data.test.type = cfg.dataset_type
    cfg.data.test.classes = cfg.classes
    cfg.data.test.ann_file = str((params['cfg_dir'] / 'annotations_valid.json'))
    cfg.data.test.img_prefix = (cfg.data_root + '/images/')
    cfg.data.test.filter_empty_gt = False
    cfg.data.val.type = cfg.dataset_type
    cfg.data.val.classes = cfg.classes
    cfg.data.val.ann_file = str((params['cfg_dir'] / 'annotations_valid.json'))
    cfg.data.val.img_prefix = (cfg.data_root + '/images/')
    cfg.data.val.filter_empty_gt = False
    cfg.data.samples_per_gpu = (params['batch'] // len(cfg.gpu_ids))
    cfg.data.workers_per_gpu = (params['workers'] // len(cfg.gpu_ids))
    albu_train_transforms = get_albu_transforms(params['aug_param'], is_train=True)
    if (params['aug_param']['use_mixup'] or params['aug_param']['use_mosaic']):
        train_pipeline = []
    else:
        train_pipeline = [dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True)]
    if params['aug_param']['use_mosaic']:
        train_pipeline.append(dict(type='Mosaic', img_scale=cfg.img_scale, pad_val=114.0))
    else:
        train_pipeline.append(dict(type='Resize', img_scale=cfg.img_scale, keep_ratio=False))
    train_pipeline = (train_pipeline + [dict(type='Pad', size_divisor=32), dict(type='Albu', transforms=albu_train_transforms, bbox_params=dict(type='BboxParams', format='pascal_voc', label_fields=['gt_labels'], min_visibility=0.0, filter_lost_elements=True), keymap={'img': 'image', 'gt_bboxes': 'bboxes'}, update_pad_shape=False, skip_img_without_anno=False)])
    if params['aug_param']['use_mixup']:
        train_pipeline.append(dict(type='MixUp', img_scale=cfg.img_scale, ratio_range=(0.8, 1.6), pad_val=114.0))
    train_pipeline = (train_pipeline + [dict(type='Normalize', **cfg.img_norm_cfg), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'], meta_keys=('filename', 'ori_filename', 'ori_shape', 'img_shape', 'pad_shape', 'scale_factor', 'img_norm_cfg'))])
    val_pipeline = [dict(type='LoadImageFromFile'), dict(type='MultiScaleFlipAug', img_scale=cfg.img_scale, flip=False, transforms=[dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='Normalize', **cfg.img_norm_cfg), dict(type='Pad', size_divisor=32), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img'])])]
    test_pipeline = [dict(type='LoadImageFromFile'), dict(type='MultiScaleFlipAug', img_scale=[cfg.img_scale], flip=[False], transforms=[dict(type='Resize', keep_ratio=False), dict(type='Pad', size_divisor=32), dict(type='RandomFlip', direction='horizontal'), dict(type='Normalize', **cfg.img_norm_cfg), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img'])])]
    cfg.train_pipeline = train_pipeline
    cfg.val_pipeline = val_pipeline
    cfg.test_pipeline = test_pipeline
    if (params['aug_param']['use_mixup'] or params['aug_param']['use_mosaic']):
        cfg.train_dataset = dict(type='MultiImageMixDataset', dataset=dict(type=cfg.dataset_type, classes=cfg.classes, ann_file=str((params['cfg_dir'] / 'annotations_train.json')), img_prefix=(cfg.data_root + '/images/'), pipeline=[dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True)], filter_empty_gt=False), pipeline=cfg.train_pipeline)
        cfg.data.train = cfg.train_dataset
    else:
        cfg.data.train.pipeline = cfg.train_pipeline
    cfg.data.val.pipeline = cfg.val_pipeline
    cfg.data.test.pipeline = cfg.test_pipeline
    return cfg
def add_data_pipeline(cfg, params):
    cfg.dataset_type = 'COCODataset'
    cfg.classes = ('cots',)
    cfg.data_root = str(params['data_path'].resolve())
    params['aug_param']['img_scale'] = (params['img_size'], params['img_size'])
    cfg.img_scale = params['aug_param']['img_scale']
    cfg.dataset_type = 'CocoDataset'
    cfg.filter_empty_gt = False
    cfg.data.filter_empty_gt = False
    cfg.data.train.type = cfg.dataset_type
    cfg.data.train.classes = cfg.classes
    cfg.data.train.ann_file = str((params['cfg_dir'] / 'annotations_train.json'))
    cfg.data.train.img_prefix = (cfg.data_root + '/images/')
    cfg.data.train.filter_empty_gt = False
    cfg.data.test.type = cfg.dataset_type
    cfg.data.test.classes = cfg.classes
    cfg.data.test.ann_file = str((params['cfg_dir'] / 'annotations_valid.json'))
    cfg.data.test.img_prefix = (cfg.data_root + '/images/')
    cfg.data.test.filter_empty_gt = False
    cfg.data.val.type = cfg.dataset_type
    cfg.data.val.classes = cfg.classes
    cfg.data.val.ann_file = str((params['cfg_dir'] / 'annotations_valid.json'))
    cfg.data.val.img_prefix = (cfg.data_root + '/images/')
    cfg.data.val.filter_empty_gt = False
    cfg.data.samples_per_gpu = (params['batch'] // len(cfg.gpu_ids))
    cfg.data.workers_per_gpu = (params['workers'] // len(cfg.gpu_ids))
    albu_train_transforms = get_albu_transforms(params['aug_param'], is_train=True)
    if (params['aug_param']['use_mixup'] or params['aug_param']['use_mosaic']):
        train_pipeline = []
    else:
        train_pipeline = [dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True)]
    if params['aug_param']['use_mosaic']:
        train_pipeline.append(dict(type='Mosaic', img_scale=cfg.img_scale, pad_val=114.0))
    else:
        train_pipeline.append(dict(type='Resize', img_scale=cfg.img_scale, keep_ratio=False))
    train_pipeline = (train_pipeline + [dict(type='Pad', size_divisor=32), dict(type='Albu', transforms=albu_train_transforms, bbox_params=dict(type='BboxParams', format='pascal_voc', label_fields=['gt_labels'], min_visibility=0.0, filter_lost_elements=True), keymap={'img': 'image', 'gt_bboxes': 'bboxes'}, update_pad_shape=False, skip_img_without_anno=False)])
    if params['aug_param']['use_mixup']:
        train_pipeline.append(dict(type='MixUp', img_scale=cfg.img_scale, ratio_range=(0.8, 1.6), pad_val=114.0))
    train_pipeline = (train_pipeline + [dict(type='Normalize', **cfg.img_norm_cfg), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'], meta_keys=('filename', 'ori_filename', 'ori_shape', 'img_shape', 'pad_shape', 'scale_factor', 'img_norm_cfg'))])
    val_pipeline = [dict(type='LoadImageFromFile'), dict(type='MultiScaleFlipAug', img_scale=cfg.img_scale, flip=False, transforms=[dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='Normalize', **cfg.img_norm_cfg), dict(type='Pad', size_divisor=32), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img'])])]
    test_pipeline = [dict(type='LoadImageFromFile'), dict(type='MultiScaleFlipAug', img_scale=[cfg.img_scale], flip=[False], transforms=[dict(type='Resize', keep_ratio=False), dict(type='Pad', size_divisor=32), dict(type='RandomFlip', direction='horizontal'), dict(type='Normalize', **cfg.img_norm_cfg), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img'])])]
    cfg.train_pipeline = train_pipeline
    cfg.val_pipeline = val_pipeline
    cfg.test_pipeline = test_pipeline
    if (params['aug_param']['use_mixup'] or params['aug_param']['use_mosaic']):
        cfg.train_dataset = dict(type='MultiImageMixDataset', dataset=dict(type=cfg.dataset_type, classes=cfg.classes, ann_file=str((params['cfg_dir'] / 'annotations_train.json')), img_prefix=(cfg.data_root + '/images/'), pipeline=[dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True)], filter_empty_gt=False), pipeline=cfg.train_pipeline)
        cfg.data.train = cfg.train_dataset
    else:
        cfg.data.train.pipeline = cfg.train_pipeline
    cfg.data.val.pipeline = cfg.val_pipeline
    cfg.data.test.pipeline = cfg.test_pipeline
    return cfg