当前位置: 首页>>代码示例>>Python>>正文


Python mmcv.is_list_of方法代码示例

本文整理汇总了Python中mmcv.is_list_of方法的典型用法代码示例。如果您正苦于以下问题:Python mmcv.is_list_of方法的具体用法?Python mmcv.is_list_of怎么用?Python mmcv.is_list_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mmcv的用法示例。


在下文中一共展示了mmcv.is_list_of方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def __init__(self,
                 img_scale=None,
                 multiscale_mode='range',
                 ratio_range=None,
                 keep_ratio=True):
        if img_scale is None:
            self.img_scale = None
        else:
            if isinstance(img_scale, list):
                self.img_scale = img_scale
            else:
                self.img_scale = [img_scale]
            assert mmcv.is_list_of(self.img_scale, tuple)

        if ratio_range is not None:
            # mode 1: given a scale and a range of image ratio
            assert len(self.img_scale) == 1
        else:
            # mode 2: given multiple scales or a range of scales
            assert multiscale_mode in ['value', 'range']

        self.multiscale_mode = multiscale_mode
        self.ratio_range = ratio_range
        self.keep_ratio = keep_ratio 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:26,代码来源:transforms.py

示例2: random_select

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def random_select(img_scales):
        """Randomly select an img_scale from given candidates.

        Args:
            img_scales (list[tuple]): Images scales for selection.

        Returns:
            (tuple, int): Returns a tuple ``(img_scale, scale_dix)``,
                where ``img_scale`` is the selected image scale and
                ``scale_idx`` is the selected index in the given candidates.
        """

        assert mmcv.is_list_of(img_scales, tuple)
        scale_idx = np.random.randint(len(img_scales))
        img_scale = img_scales[scale_idx]
        return img_scale, scale_idx 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:18,代码来源:transforms.py

示例3: random_sample

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def random_sample(img_scales):
        """Randomly sample an img_scale when ``multiscale_mode=='range'``.

        Args:
            img_scales (list[tuple]): Images scale range for sampling.
                There must be two tuples in img_scales, which specify the lower
                and uper bound of image scales.

        Returns:
            (tuple, None): Returns a tuple ``(img_scale, None)``, where
                ``img_scale`` is sampled scale and None is just a placeholder
                to be consistent with :func:`random_select`.
        """

        assert mmcv.is_list_of(img_scales, tuple) and len(img_scales) == 2
        img_scale_long = [max(s) for s in img_scales]
        img_scale_short = [min(s) for s in img_scales]
        long_edge = np.random.randint(
            min(img_scale_long),
            max(img_scale_long) + 1)
        short_edge = np.random.randint(
            min(img_scale_short),
            max(img_scale_short) + 1)
        img_scale = (long_edge, short_edge)
        return img_scale, None 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:27,代码来源:transforms.py

示例4: __init__

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def __init__(self,
                 transforms,
                 img_scale=None,
                 scale_factor=None,
                 flip=False,
                 flip_direction='horizontal'):
        self.transforms = Compose(transforms)
        assert (img_scale is None) ^ (scale_factor is None), (
            'Must have but only one variable can be setted')
        if img_scale is not None:
            self.img_scale = img_scale if isinstance(img_scale,
                                                     list) else [img_scale]
            self.scale_key = 'scale'
            assert mmcv.is_list_of(self.img_scale, tuple)
        else:
            self.img_scale = scale_factor if isinstance(
                scale_factor, list) else [scale_factor]
            self.scale_key = 'scale_factor'

        self.flip = flip
        self.flip_direction = flip_direction if isinstance(
            flip_direction, list) else [flip_direction]
        assert mmcv.is_list_of(self.flip_direction, str)
        if not self.flip and self.flip_direction != ['horizontal']:
            warnings.warn(
                'flip_direction has no effect when flip is set to False')
        if (self.flip
                and not any([t['type'] == 'RandomFlip' for t in transforms])):
            warnings.warn(
                'flip has no effect when RandomFlip is not in transforms') 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:32,代码来源:test_time_aug.py

示例5: test_is_seq_of

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def test_is_seq_of():
    assert mmcv.is_seq_of([1.0, 2.0, 3.0], float)
    assert mmcv.is_seq_of([(1, ), (2, ), (3, )], tuple)
    assert mmcv.is_seq_of((1.0, 2.0, 3.0), float)
    assert mmcv.is_list_of([1.0, 2.0, 3.0], float)
    assert not mmcv.is_seq_of((1.0, 2.0, 3.0), float, seq_type=list)
    assert not mmcv.is_tuple_of([1.0, 2.0, 3.0], float)
    assert not mmcv.is_seq_of([1.0, 2, 3], int)
    assert not mmcv.is_seq_of((1.0, 2, 3), int) 
开发者ID:open-mmlab,项目名称:mmcv,代码行数:11,代码来源:test_misc.py

示例6: random_select

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def random_select(img_scales):
        assert mmcv.is_list_of(img_scales, tuple)
        scale_idx = np.random.randint(len(img_scales))
        img_scale = img_scales[scale_idx]
        return img_scale, scale_idx 
开发者ID:tascj,项目名称:kaggle-kuzushiji-recognition,代码行数:7,代码来源:transforms.py

示例7: random_sample

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def random_sample(img_scales):
        assert mmcv.is_list_of(img_scales, tuple) and len(img_scales) == 2
        img_scale_long = [max(s) for s in img_scales]
        img_scale_short = [min(s) for s in img_scales]
        long_edge = np.random.randint(
            min(img_scale_long),
            max(img_scale_long) + 1)
        short_edge = np.random.randint(
            min(img_scale_short),
            max(img_scale_short) + 1)
        img_scale = (long_edge, short_edge)
        return img_scale, None 
开发者ID:tascj,项目名称:kaggle-kuzushiji-recognition,代码行数:14,代码来源:transforms.py

示例8: __init__

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def __init__(self, transforms, img_scale, flip=False):
        self.transforms = Compose(transforms)
        self.img_scale = img_scale if isinstance(img_scale,
                                                 list) else [img_scale]
        assert mmcv.is_list_of(self.img_scale, tuple)
        self.flip = flip 
开发者ID:tascj,项目名称:kaggle-kuzushiji-recognition,代码行数:8,代码来源:test_aug.py

示例9: run_step_alter

# 需要导入模块: import mmcv [as 别名]
# 或者: from mmcv import is_list_of [as 别名]
def run_step_alter(self, data_loaders, workflow, max_epochs, arch_update_epoch, **kwargs):
        """Start running. Arch and weight optimization alternates by step.

        Args:
            data_loaders (list[:obj:`DataLoader`]): Dataloaders for training
                and validation.
            workflow (list[tuple]): A list of (phase, epochs) to specify the
                running order and epochs. E.g, [('train', 2), ('val', 1)] means
                running 2 epochs for training and 1 epoch for validation,
                iteratively.
            max_epochs (int): Total training epochs.
        """
        assert isinstance(data_loaders, list)
        assert mmcv.is_list_of(workflow, tuple)

        self._max_epochs = max_epochs
        work_dir = self.work_dir if self.work_dir is not None else 'NONE'
        self.logger.info('Start running, host: %s, work_dir: %s',
                         get_host_info(), work_dir)
        self.logger.info('workflow: %s, max: %d epochs', workflow, max_epochs)
        self.call_hook('before_run', 'train')

        while self.epoch < max_epochs:
            self.search_stage = 0 if self.epoch<self.cfg.arch_update_epoch else 1
            self.train_step_alter(data_loaders)

        time.sleep(1)  # wait for some hooks like loggers to finish
        self.call_hook('after_run', 'train') 
开发者ID:JaminFong,项目名称:FNA,代码行数:30,代码来源:fna_search_runner.py


注:本文中的mmcv.is_list_of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。