コード例 #1
0
ファイル: test_forward.py プロジェクト: tjpulfn/SEPC
def _get_config_module(fname):
    """Load a configuration as a python module."""
    from xdoctest.utils import import_module_from_path
    config_dpath = _get_config_directory()
    config_fpath = join(config_dpath, fname)
    config_mod = import_module_from_path(config_fpath)
    return config_mod
コード例 #2
0
ファイル: doctest_example.py プロジェクト: jayvdb/xdoctest
 def _import_module(self):
     """
     After this point we are in dynamic analysis mode, in most cases
     xdoctest should have been in static-analysis-only mode.
     """
     if self.module is None:
         if not self.modname.startswith('<'):
             # self.module = utils.import_module_from_path(self.modpath, index=0)
             self.module = utils.import_module_from_path(self.modpath, index=-1)
コード例 #3
0
ファイル: dynamic_analysis.py プロジェクト: jayvdb/xdoctest
def parse_dynamic_calldefs(modpath=None):
    """
    Dynamic parsing of module doctestable items.

    While this does execute module code it is needed for testing extension
    libraries.

    CommandLine:
        python -m xdoctest.dynamic_analysis parse_dynamic_calldefs

    Example:
        >>> from xdoctest import dynamic_analysis
        >>> module = dynamic_analysis
        >>> calldefs = parse_dynamic_calldefs(module.__file__)
        >>> for key, calldef in sorted(calldefs.items()):
        ...     print('key = {!r}'.format(key))
        ...     print(' * calldef.callname = {}'.format(calldef.callname))
        ...     if calldef.docstr is None:
        ...         print(' * len(calldef.docstr) = {}'.format(calldef.docstr))
        ...     else:
        ...         print(' * len(calldef.docstr) = {}'.format(len(calldef.docstr)))
    """
    from xdoctest import static_analysis as static
    from xdoctest import utils  # NOQA
    # Possible option for dynamic parsing
    module = utils.import_module_from_path(modpath)
    calldefs = {}

    if getattr(module, '__doc__'):
        calldefs['__doc__'] = static.CallDefNode(
            callname='__doc__',
            docstr=module.__doc__,
            lineno=0,
            doclineno=1,
            doclineno_end=1,
            args=None
        )

    for key, val in iter_module_doctestables(module):
        # if hasattr(val, '__doc__'):
        if hasattr(val, '__doc__') and hasattr(val, '__name__'):
            calldefs[key] = static.CallDefNode(
                callname=val.__name__,
                docstr=val.__doc__,
                lineno=0,
                doclineno=1,
                doclineno_end=1,
                args=None
            )
    return calldefs
コード例 #4
0
ファイル: doctest_example.py プロジェクト: Erotemic/xdoctest
 def _import_module(self):
     """
     After this point we are in dynamic analysis mode, in most cases
     xdoctest should have been in static-analysis-only mode.
     """
     if self.module is None:
         if not self.modname.startswith('<'):
             # self.module = utils.import_module_from_path(self.modpath, index=0)
             try:
                 self.module = utils.import_module_from_path(self.modpath,
                                                             index=-1)
             except RuntimeError as ex:
                 msg_parts = [('XDoctest failed to pre-import the module '
                               'containing the doctest.')]
                 msg_parts.append(str(ex))
                 new_exc = RuntimeError('\n'.join(msg_parts))
                 # new_exc = ex
                 # Remove traceback before this line
                 new_exc.__traceback__ = None
                 # Backwards syntax compatible raise exc from None
                 # https://www.python.org/dev/peps/pep-3134/#explicit-exception-chaining
                 new_exc.__cause__ = None
                 raise new_exc
コード例 #5
0
ファイル: test_config.py プロジェクト: gjt9274/ML
def test_config_build_detector():
    """
    Test that all detection models defined in the configs can be initialized.
    """
    from xdoctest.utils import import_module_from_path
    from mmdet.models import build_detector

    config_dpath = _get_config_directory()
    print('Found config_dpath = {!r}'.format(config_dpath))

    # import glob
    # config_fpaths = list(glob.glob(join(config_dpath, '**', '*.py')))
    # config_names = [relpath(p, config_dpath) for p in config_fpaths]

    # Only tests a representative subset of configurations

    config_names = [
        # 'dcn/faster_rcnn_dconv_c3-c5_r50_fpn_1x.py',
        # 'dcn/cascade_mask_rcnn_dconv_c3-c5_r50_fpn_1x.py',
        # 'dcn/faster_rcnn_dpool_r50_fpn_1x.py',
        'dcn/mask_rcnn_dconv_c3-c5_r50_fpn_1x.py',
        # 'dcn/faster_rcnn_dconv_c3-c5_x101_32x4d_fpn_1x.py',
        # 'dcn/cascade_rcnn_dconv_c3-c5_r50_fpn_1x.py',
        # 'dcn/faster_rcnn_mdpool_r50_fpn_1x.py',
        # 'dcn/faster_rcnn_mdconv_c3-c5_group4_r50_fpn_1x.py',
        # 'dcn/faster_rcnn_mdconv_c3-c5_r50_fpn_1x.py',
        # ---
        # 'htc/htc_x101_32x4d_fpn_20e_16gpu.py',
        'htc/htc_without_semantic_r50_fpn_1x.py',
        # 'htc/htc_dconv_c3-c5_mstrain_400_1400_x101_64x4d_fpn_20e.py',
        # 'htc/htc_x101_64x4d_fpn_20e_16gpu.py',
        # 'htc/htc_r50_fpn_1x.py',
        # 'htc/htc_r101_fpn_20e.py',
        # 'htc/htc_r50_fpn_20e.py',
        # ---
        'cityscapes/mask_rcnn_r50_fpn_1x_cityscapes.py',
        # 'cityscapes/faster_rcnn_r50_fpn_1x_cityscapes.py',
        # ---
        # 'scratch/scratch_faster_rcnn_r50_fpn_gn_6x.py',
        # 'scratch/scratch_mask_rcnn_r50_fpn_gn_6x.py',
        # ---
        # 'grid_rcnn/grid_rcnn_gn_head_x101_32x4d_fpn_2x.py',
        'grid_rcnn/grid_rcnn_gn_head_r50_fpn_2x.py',
        # ---
        'double_heads/dh_faster_rcnn_r50_fpn_1x.py',
        # ---
        'empirical_attention/faster_rcnn_r50_fpn_attention_0010_dcn_1x.py',
        # 'empirical_attention/faster_rcnn_r50_fpn_attention_1111_1x.py',
        # 'empirical_attention/faster_rcnn_r50_fpn_attention_0010_1x.py',
        # 'empirical_attention/faster_rcnn_r50_fpn_attention_1111_dcn_1x.py',
        # ---
        # 'ms_rcnn/ms_rcnn_r101_caffe_fpn_1x.py',
        # 'ms_rcnn/ms_rcnn_x101_64x4d_fpn_1x.py',
        # 'ms_rcnn/ms_rcnn_r50_caffe_fpn_1x.py',
        # ---
        # 'guided_anchoring/ga_faster_x101_32x4d_fpn_1x.py',
        # 'guided_anchoring/ga_rpn_x101_32x4d_fpn_1x.py',
        # 'guided_anchoring/ga_retinanet_r50_caffe_fpn_1x.py',
        # 'guided_anchoring/ga_fast_r50_caffe_fpn_1x.py',
        # 'guided_anchoring/ga_retinanet_x101_32x4d_fpn_1x.py',
        # 'guided_anchoring/ga_rpn_r101_caffe_rpn_1x.py',
        # 'guided_anchoring/ga_faster_r50_caffe_fpn_1x.py',
        'guided_anchoring/ga_rpn_r50_caffe_fpn_1x.py',
        # ---
        'foveabox/fovea_r50_fpn_4gpu_1x.py',
        # 'foveabox/fovea_align_gn_ms_r101_fpn_4gpu_2x.py',
        # 'foveabox/fovea_align_gn_r50_fpn_4gpu_2x.py',
        # 'foveabox/fovea_align_gn_r101_fpn_4gpu_2x.py',
        'foveabox/fovea_align_gn_ms_r50_fpn_4gpu_2x.py',
        # ---
        # 'hrnet/cascade_rcnn_hrnetv2p_w32_20e.py',
        # 'hrnet/mask_rcnn_hrnetv2p_w32_1x.py',
        # 'hrnet/cascade_mask_rcnn_hrnetv2p_w32_20e.py',
        # 'hrnet/htc_hrnetv2p_w32_20e.py',
        # 'hrnet/faster_rcnn_hrnetv2p_w18_1x.py',
        # 'hrnet/mask_rcnn_hrnetv2p_w18_1x.py',
        # 'hrnet/faster_rcnn_hrnetv2p_w32_1x.py',
        # 'hrnet/faster_rcnn_hrnetv2p_w40_1x.py',
        'hrnet/fcos_hrnetv2p_w32_gn_1x_4gpu.py',
        # ---
        # 'gn+ws/faster_rcnn_r50_fpn_gn_ws_1x.py',
        # 'gn+ws/mask_rcnn_x101_32x4d_fpn_gn_ws_2x.py',
        'gn+ws/mask_rcnn_r50_fpn_gn_ws_2x.py',
        # 'gn+ws/mask_rcnn_r50_fpn_gn_ws_20_23_24e.py',
        # ---
        # 'wider_face/ssd300_wider_face.py',
        # ---
        'pascal_voc/ssd300_voc.py',
        'pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py',
        'pascal_voc/ssd512_voc.py',
        # ---
        # 'gcnet/mask_rcnn_r4_gcb_c3-c5_r50_fpn_syncbn_1x.py',
        # 'gcnet/mask_rcnn_r16_gcb_c3-c5_r50_fpn_syncbn_1x.py',
        # 'gcnet/mask_rcnn_r4_gcb_c3-c5_r50_fpn_1x.py',
        # 'gcnet/mask_rcnn_r16_gcb_c3-c5_r50_fpn_1x.py',
        'gcnet/mask_rcnn_r50_fpn_sbn_1x.py',
        # ---
        'gn/mask_rcnn_r50_fpn_gn_contrib_2x.py',
        # 'gn/mask_rcnn_r50_fpn_gn_2x.py',
        # 'gn/mask_rcnn_r101_fpn_gn_2x.py',
        # ---
        # 'reppoints/reppoints_moment_x101_dcn_fpn_2x.py',
        'reppoints/reppoints_moment_r50_fpn_2x.py',
        # 'reppoints/reppoints_moment_x101_dcn_fpn_2x_mt.py',
        'reppoints/reppoints_partial_minmax_r50_fpn_1x.py',
        'reppoints/bbox_r50_grid_center_fpn_1x.py',
        # 'reppoints/reppoints_moment_r101_dcn_fpn_2x.py',
        # 'reppoints/reppoints_moment_r101_fpn_2x_mt.py',
        # 'reppoints/reppoints_moment_r50_fpn_2x_mt.py',
        'reppoints/reppoints_minmax_r50_fpn_1x.py',
        # 'reppoints/reppoints_moment_r50_fpn_1x.py',
        # 'reppoints/reppoints_moment_r101_fpn_2x.py',
        # 'reppoints/reppoints_moment_r101_dcn_fpn_2x_mt.py',
        'reppoints/bbox_r50_grid_fpn_1x.py',
        # ---
        # 'fcos/fcos_mstrain_640_800_x101_64x4d_fpn_gn_2x.py',
        # 'fcos/fcos_mstrain_640_800_r101_caffe_fpn_gn_2x_4gpu.py',
        'fcos/fcos_r50_caffe_fpn_gn_1x_4gpu.py',
        # ---
        'albu_example/mask_rcnn_r50_fpn_1x.py',
        # ---
        'libra_rcnn/libra_faster_rcnn_r50_fpn_1x.py',
        # 'libra_rcnn/libra_retinanet_r50_fpn_1x.py',
        # 'libra_rcnn/libra_faster_rcnn_r101_fpn_1x.py',
        # 'libra_rcnn/libra_faster_rcnn_x101_64x4d_fpn_1x.py',
        # 'libra_rcnn/libra_fast_rcnn_r50_fpn_1x.py',
        # ---
        # 'ghm/retinanet_ghm_r50_fpn_1x.py',
        # ---
        # 'fp16/retinanet_r50_fpn_fp16_1x.py',
        'fp16/mask_rcnn_r50_fpn_fp16_1x.py',
        'fp16/faster_rcnn_r50_fpn_fp16_1x.py'
    ]

    print('Using {} config files'.format(len(config_names)))

    for config_fname in config_names:
        config_fpath = join(config_dpath, config_fname)
        config_mod = import_module_from_path(config_fpath)

        config_mod.model
        config_mod.train_cfg
        config_mod.test_cfg
        print('Building detector, config_fpath = {!r}'.format(config_fpath))

        # Remove pretrained keys to allow for testing in an offline environment
        if 'pretrained' in config_mod.model:
            config_mod.model['pretrained'] = None

        detector = build_detector(config_mod.model,
                                  train_cfg=config_mod.train_cfg,
                                  test_cfg=config_mod.test_cfg)
        assert detector is not None
コード例 #6
0
def test_config_data_pipeline():
    """
    Test whether the data pipeline is valid and can process corner cases.
    CommandLine:
        xdoctest -m tests/test_config.py test_config_build_data_pipeline
    """
    from xdoctest.utils import import_module_from_path
    from mmdet.datasets.pipelines import Compose
    import numpy as np

    config_dpath = _get_config_directory()
    print('Found config_dpath = {!r}'.format(config_dpath))

    # Only tests a representative subset of configurations
    # TODO: test pipelines using Albu, current Albu throw None given empty GT
    config_names = [
        'wider_face/ssd300_wider_face.py',
        'pascal_voc/ssd300_voc.py',
        'pascal_voc/ssd512_voc.py',
        # 'albu_example/mask_rcnn_r50_fpn_1x.py',
        'fp16/mask_rcnn_r50_fpn_fp16_1x.py',
    ]

    print('Using {} config files'.format(len(config_names)))

    for config_fname in config_names:
        config_fpath = join(config_dpath, config_fname)
        config_mod = import_module_from_path(config_fpath)

        # remove loading pipeline
        loading_pipeline = config_mod.train_pipeline.pop(0)
        config_mod.train_pipeline.pop(0)
        config_mod.test_pipeline.pop(0)

        train_pipeline = Compose(config_mod.train_pipeline)
        test_pipeline = Compose(config_mod.test_pipeline)

        print(
            'Building data pipeline, config_fpath = {!r}'.format(config_fpath))

        print('Test training data pipeline: \n{!r}'.format(train_pipeline))
        img = np.random.randint(0, 255, size=(888, 666, 3), dtype=np.uint8)
        if loading_pipeline.get('to_float32', False):
            img = img.astype(np.float32)
        results = dict(
            filename='test_img.png',
            img=img,
            img_shape=img.shape,
            ori_shape=img.shape,
            gt_bboxes=np.array([[35.2, 11.7, 39.7, 15.7]], dtype=np.float32),
            gt_labels=np.array([1], dtype=np.int64),
            gt_masks=[(img[..., 0] == 233).astype(np.uint8)],
        )
        results['bbox_fields'] = ['gt_bboxes']
        results['mask_fields'] = ['gt_masks']
        output_results = train_pipeline(results)
        assert output_results is not None

        print('Test testing data pipeline: \n{!r}'.format(test_pipeline))
        results = dict(
            filename='test_img.png',
            img=img,
            img_shape=img.shape,
            ori_shape=img.shape,
            gt_bboxes=np.array([[35.2, 11.7, 39.7, 15.7]], dtype=np.float32),
            gt_labels=np.array([1], dtype=np.int64),
            gt_masks=[(img[..., 0] == 233).astype(np.uint8)],
        )
        results['bbox_fields'] = ['gt_bboxes']
        results['mask_fields'] = ['gt_masks']
        output_results = test_pipeline(results)
        assert output_results is not None

        # test empty GT
        print('Test empty GT with training data pipeline: \n{!r}'.format(
            train_pipeline))
        results = dict(
            filename='test_img.png',
            img=img,
            img_shape=img.shape,
            ori_shape=img.shape,
            gt_bboxes=np.zeros((0, 4), dtype=np.float32),
            gt_labels=np.array([], dtype=np.int64),
            gt_masks=[],
        )
        results['bbox_fields'] = ['gt_bboxes']
        results['mask_fields'] = ['gt_masks']
        output_results = train_pipeline(results)
        assert output_results is not None

        print('Test empty GT with testing data pipeline: \n{!r}'.format(
            test_pipeline))
        results = dict(
            filename='test_img.png',
            img=img,
            img_shape=img.shape,
            ori_shape=img.shape,
            gt_bboxes=np.zeros((0, 4), dtype=np.float32),
            gt_labels=np.array([], dtype=np.int64),
            gt_masks=[],
        )
        results['bbox_fields'] = ['gt_bboxes']
        results['mask_fields'] = ['gt_masks']
        output_results = test_pipeline(results)
        assert output_results is not None