當前位置: 首頁>>代碼示例>>Python>>正文


Python runner.obj_from_dict方法代碼示例

本文整理匯總了Python中mmcv.runner.obj_from_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python runner.obj_from_dict方法的具體用法?Python runner.obj_from_dict怎麽用?Python runner.obj_from_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mmcv.runner的用法示例。


在下文中一共展示了runner.obj_from_dict方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_dataset

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def get_dataset(data_cfg):
    if data_cfg['type'] == 'RepeatDataset':
        return RepeatDataset(
            get_dataset(data_cfg['dataset']), data_cfg['times'])

    if isinstance(data_cfg['ann_file'], (list, tuple)):
        ann_files = data_cfg['ann_file']
        num_dset = len(ann_files)
    else:
        ann_files = [data_cfg['ann_file']]
        num_dset = 1

    if 'proposal_file' in data_cfg.keys():
        if isinstance(data_cfg['proposal_file'], (list, tuple)):
            proposal_files = data_cfg['proposal_file']
        else:
            proposal_files = [data_cfg['proposal_file']]
    else:
        proposal_files = [None] * num_dset
    assert len(proposal_files) == num_dset

    if isinstance(data_cfg['img_prefix'], (list, tuple)):
        img_prefixes = data_cfg['img_prefix']
    else:
        img_prefixes = [data_cfg['img_prefix']] * num_dset
    assert len(img_prefixes) == num_dset

    dsets = []
    for i in range(num_dset):
        data_info = copy.deepcopy(data_cfg)
        data_info['ann_file'] = ann_files[i]
        data_info['proposal_file'] = proposal_files[i]
        data_info['img_prefix'] = img_prefixes[i]
        dset = obj_from_dict(data_info, datasets)
        dsets.append(dset)
    if len(dsets) > 1:
        dset = ConcatDataset(dsets)
    else:
        dset = dsets[0]
    return dset 
開發者ID:dingjiansw101,項目名稱:AerialDetection,代碼行數:42,代碼來源:utils.py

示例2: __init__

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def __init__(self, dataset, interval=1):
        if isinstance(dataset, Dataset):
            self.dataset = dataset
        elif isinstance(dataset, dict):
            self.dataset = obj_from_dict(dataset, datasets,
                                         {'test_mode': True})
        else:
            raise TypeError(
                'dataset must be a Dataset object or a dict, not {}'.format(
                    type(dataset)))
        self.interval = interval 
開發者ID:dingjiansw101,項目名稱:AerialDetection,代碼行數:13,代碼來源:eval_hooks.py

示例3: __init__

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def __init__(self, dataset, interval=1):
        if isinstance(dataset, Dataset):
            self.dataset = dataset
        elif isinstance(dataset, dict):
            self.dataset = obj_from_dict(dataset, datasets,
                                         {'test_mode': True})
        else:
            raise TypeError(
                'dataset must be a Dataset object or a dict, not {}'.format(
                    type(dataset)))
        self.interval = interval
        self.lock_dir = None 
開發者ID:chanyn,項目名稱:Reasoning-RCNN,代碼行數:14,代碼來源:eval_hooks.py

示例4: transform_from_dict

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def transform_from_dict(self, **kwargs):
        if 'transforms' in kwargs:
            kwargs['transforms'] = [self.transform_from_dict(**transform) for transform in kwargs['transforms']]
        try:
            return obj_from_dict(kwargs, transforms)
        except AttributeError:
            return obj_from_dict(kwargs, A) 
開發者ID:amirassov,項目名稱:kaggle-imaterialist,代碼行數:9,代碼來源:extra_aug.py

示例5: get_untrimmed_dataset

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def get_untrimmed_dataset(data_cfg):
    if isinstance(data_cfg['ann_file'], (list, tuple)):
        ann_files = data_cfg['ann_file']
        num_dset = len(ann_files)
    else:
        ann_files = [data_cfg['ann_file']]
        num_dset = 1

    if 'proposal_file' in data_cfg.keys():
        if isinstance(data_cfg['proposal_file'], (list, tuple)):
            proposal_files = data_cfg['proposal_file']
        else:
            proposal_files = [data_cfg['proposal_file']]
    else:
        proposal_files = [None] * num_dset
    assert len(proposal_files) == num_dset

    if isinstance(data_cfg['img_prefix'], (list, tuple)):
        img_prefixes = data_cfg['img_prefix']
    else:
        img_prefixes = [data_cfg['img_prefix']]
    assert len(img_prefixes) == num_dset

    dsets = []
    for i in range(num_dset):
        data_info = copy.deepcopy(data_cfg)
        data_info['ann_file'] = ann_files[i]
        data_info['proposal_file'] = proposal_files[i]
        data_info['img_prefix'] = img_prefixes[i]
        dset = obj_from_dict(data_info, datasets)
        dsets.append(dset)

    if len(dsets) > 1:
        raise ValueError("Not implemented yet")
    else:
        dset = dsets[0]

    return dset 
開發者ID:open-mmlab,項目名稱:mmaction,代碼行數:40,代碼來源:utils.py

示例6: get_trimmed_dataset

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def get_trimmed_dataset(data_cfg):
    if isinstance(data_cfg['ann_file'], (list, tuple)):
        ann_files = data_cfg['ann_file']
        num_dset = len(ann_files)
    else:
        ann_files = [data_cfg['ann_file']]
        num_dset = 1

    if isinstance(data_cfg['img_prefix'], (list, tuple)):
        img_prefixes = data_cfg['img_prefix']
    else:
        img_prefixes = [data_cfg['img_prefix']]
    assert len(img_prefixes) == num_dset

    dsets = []
    for i in range(num_dset):
        data_info = copy.deepcopy(data_cfg)
        data_info['ann_file'] = ann_files[i]
        data_info['img_prefix'] = img_prefixes[i]
        dset = obj_from_dict(data_info, datasets)
        dsets.append(dset)

    if len(dsets) > 1:
        raise ValueError("Not implemented yet")
    else:
        dset = dsets[0]

    return dset 
開發者ID:open-mmlab,項目名稱:mmaction,代碼行數:30,代碼來源:utils.py

示例7: build_optimizer

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def build_optimizer(model, optimizer_cfg):
    """Build optimizer from configs.
    """
    if hasattr(model, 'module'):
        model = model.module

    optimizer_cfg = optimizer_cfg.copy()
    paramwise_options = optimizer_cfg.pop('paramwise_options', None)
    assert paramwise_options is None
    return obj_from_dict(optimizer_cfg, torch.optim,
                         dict(params=model.parameters())) 
開發者ID:yl-1993,項目名稱:learn-to-cluster,代碼行數:13,代碼來源:train_lgcn.py

示例8: main

# 需要導入模塊: from mmcv import runner [as 別名]
# 或者: from mmcv.runner import obj_from_dict [as 別名]
def main():
    args = parse_args()

    if args.out is not None and not args.out.endswith(('.pkl', '.pickle')):
        raise ValueError('The output file must be a pkl file.')

    cfg = mmcv.Config.fromfile(args.config)
    # set cudnn_benchmark
    if cfg.get('cudnn_benchmark', False):
        torch.backends.cudnn.benchmark = True
    cfg.data.test.test_mode = True

    dataset = obj_from_dict(cfg.data.test, datasets, dict(test_mode=True))
    if args.gpus == 1:
        model = build_detector(
            cfg.model, train_cfg=None, test_cfg=cfg.test_cfg)
        load_checkpoint(model, args.checkpoint, strict=True)
        model = MMDataParallel(model, device_ids=[0])

        data_loader = build_dataloader(
            dataset,
            imgs_per_gpu=1,
            workers_per_gpu=cfg.data.workers_per_gpu,
            num_gpus=1,
            dist=False,
            shuffle=False)
        outputs = single_test(model, data_loader)
    else:
        model_args = cfg.model.copy()
        model_args.update(train_cfg=None, test_cfg=cfg.test_cfg)
        model_type = getattr(detectors, model_args.pop('type'))
        outputs = parallel_test(
            model_type,
            model_args,
            args.checkpoint,
            dataset,
            _data_func,
            range(args.gpus),
            workers_per_gpu=args.proc_per_gpu)

    if args.out:
        print('writing results to {}'.format(args.out))
        mmcv.dump(outputs, args.out)

    eval_type = args.eval
    if eval_type:
        print('Starting evaluate {}'.format(eval_type))

        result_file = osp.join(args.out + '.csv')
        results2csv(dataset, outputs, result_file)

        ava_eval(result_file, eval_type,
                 args.label_file, args.ann_file, args.exclude_file) 
開發者ID:open-mmlab,項目名稱:mmaction,代碼行數:55,代碼來源:test_detector.py


注:本文中的mmcv.runner.obj_from_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。