def mmcfg_from_param(params):
    from mmcv import Config
    cfg = Config.fromfile(params['hyp_param']['base_file'])
    cfg.work_dir = str(params['output_dir'])
    cfg.seed = 2022
    cfg.gpu_ids = range(2)
    cfg.load_from = params['hyp_param']['load_from']
    if (params['hyp_param']['model_type'] == 'faster_rcnn'):
        cfg.model.roi_head.bbox_head.num_classes = 1
        cfg.model.roi_head.bbox_head.loss_bbox.type = params['hyp_param']['loss_fnc']
        cfg.model.rpn_head.loss_bbox.type = params['hyp_param']['loss_fnc']
        if (params['hyp_param']['loss_fnc'] == 'GIoULoss'):
            cfg.model.roi_head.bbox_head.reg_decoded_bbox = True
            cfg.model.rpn_head.reg_decoded_bbox = True
        cfg.model.train_cfg.rpn_proposal.nms.type = params['hyp_param']['nms']
        cfg.model.test_cfg.rpn.nms.type = params['hyp_param']['nms']
        cfg.model.test_cfg.rcnn.nms.type = params['hyp_param']['nms']
        cfg.model.train_cfg.rcnn.sampler.type = params['hyp_param']['sampler']
    elif (params['hyp_param']['model_type'] == 'swin'):
        pass
    elif (params['hyp_param']['model_type'] == 'vfnet'):
        cfg.model.bbox_head.num_classes = 1
    if (params['hyp_param'].get('optimizer', cfg.optimizer.type) == 'AdamW'):
        cfg.optimizer = dict(type='AdamW', lr=params['hyp_param'].get('lr', cfg.optimizer.lr), weight_decay=params['hyp_param'].get('weight_decay', cfg.optimizer.weight_decay))
    else:
        cfg.optimizer.lr = params['hyp_param'].get('lr', cfg.optimizer.lr)
        cfg.optimizer.weight_decay = params['hyp_param'].get('weight_decay', cfg.optimizer.weight_decay)
    cfg.lr_config = dict(policy='CosineAnnealing', by_epoch=False, warmup='linear', warmup_iters=1000, warmup_ratio=(1 / 10), min_lr=1e-07)
    cfg = add_data_pipeline(cfg, params)
    cfg.runner.max_epochs = params['epochs']
    cfg.evaluation.start = 1
    cfg.evaluation.interval = 1
    cfg.evaluation.save_best = 'auto'
    cfg.evaluation.metric = 'bbox'
    cfg.checkpoint_config.interval = (- 1)
    cfg.log_config.interval = 500
    cfg.log_config.with_step = True
    cfg.log_config.by_epoch = True
    cfg.log_config.hooks = [dict(type='TextLoggerHook'), dict(type='TensorboardLoggerHook')]
    cfg.workflow = [('train', 1)]
    logging.info(str(cfg))
    return cfg
def mmcfg_from_param(params):
    from mmcv import Config
    cfg = Config.fromfile(params['hyp_param']['base_file'])
    cfg.work_dir = str(params['output_dir'])
    cfg.seed = 2022
    cfg.gpu_ids = range(2)
    cfg.load_from = params['hyp_param']['load_from']
    if (params['hyp_param']['model_type'] == 'faster_rcnn'):
        cfg.model.roi_head.bbox_head.num_classes = 1
        cfg.model.roi_head.bbox_head.loss_bbox.type = params['hyp_param']['loss_fnc']
        cfg.model.rpn_head.loss_bbox.type = params['hyp_param']['loss_fnc']
        if (params['hyp_param']['loss_fnc'] == 'GIoULoss'):
            cfg.model.roi_head.bbox_head.reg_decoded_bbox = True
            cfg.model.rpn_head.reg_decoded_bbox = True
        cfg.model.train_cfg.rpn_proposal.nms.type = params['hyp_param']['nms']
        cfg.model.test_cfg.rpn.nms.type = params['hyp_param']['nms']
        cfg.model.test_cfg.rcnn.nms.type = params['hyp_param']['nms']
        cfg.model.train_cfg.rcnn.sampler.type = params['hyp_param']['sampler']
    elif (params['hyp_param']['model_type'] == 'swin'):
        pass
    elif (params['hyp_param']['model_type'] == 'vfnet'):
        cfg.model.bbox_head.num_classes = 1
    if (params['hyp_param'].get('optimizer', cfg.optimizer.type) == 'AdamW'):
        cfg.optimizer = dict(type='AdamW', lr=params['hyp_param'].get('lr', cfg.optimizer.lr), weight_decay=params['hyp_param'].get('weight_decay', cfg.optimizer.weight_decay))
    else:
        cfg.optimizer.lr = params['hyp_param'].get('lr', cfg.optimizer.lr)
        cfg.optimizer.weight_decay = params['hyp_param'].get('weight_decay', cfg.optimizer.weight_decay)
    cfg.lr_config = dict(policy='CosineAnnealing', by_epoch=False, warmup='linear', warmup_iters=1000, warmup_ratio=(1 / 10), min_lr=1e-07)
    cfg = add_data_pipeline(cfg, params)
    cfg.runner.max_epochs = params['epochs']
    cfg.evaluation.start = 1
    cfg.evaluation.interval = 1
    cfg.evaluation.save_best = 'auto'
    cfg.evaluation.metric = 'bbox'
    cfg.checkpoint_config.interval = (- 1)
    cfg.log_config.interval = 500
    cfg.log_config.with_step = True
    cfg.log_config.by_epoch = True
    cfg.log_config.hooks = [dict(type='TextLoggerHook'), dict(type='TensorboardLoggerHook')]
    cfg.workflow = [('train', 1)]
    logging.info(str(cfg))
    return cfg