def initialize(module, init_cfg):
    'Initialize a module.\n\n    Args:\n        module (``torch.nn.Module``): the module will be initialized.\n        init_cfg (dict | list[dict]): initialization configuration dict to\n            define initializer. OpenMMLab has implemented 6 initializers\n            including ``Constant``, ``Xavier``, ``Normal``, ``Uniform``,\n            ``Kaiming``, and ``Pretrained``.\n    Example:\n        >>> module = nn.Linear(2, 3, bias=True)\n        >>> init_cfg = dict(type=\'Constant\', layer=\'Linear\', val =1 , bias =2)\n        >>> initialize(module, init_cfg)\n\n        >>> module = nn.Sequential(nn.Conv1d(3, 1, 3), nn.Linear(1,2))\n        >>> # define key ``\'layer\'`` for initializing layer with different\n        >>> # configuration\n        >>> init_cfg = [dict(type=\'Constant\', layer=\'Conv1d\', val=1),\n                dict(type=\'Constant\', layer=\'Linear\', val=2)]\n        >>> initialize(module, init_cfg)\n\n        >>> # define key``\'override\'`` to initialize some specific part in\n        >>> # module\n        >>> class FooNet(nn.Module):\n        >>>     def __init__(self):\n        >>>         super().__init__()\n        >>>         self.feat = nn.Conv2d(3, 16, 3)\n        >>>         self.reg = nn.Conv2d(16, 10, 3)\n        >>>         self.cls = nn.Conv2d(16, 5, 3)\n        >>> model = FooNet()\n        >>> init_cfg = dict(type=\'Constant\', val=1, bias=2, layer=\'Conv2d\',\n        >>>     override=dict(type=\'Constant\', name=\'reg\', val=3, bias=4))\n        >>> initialize(model, init_cfg)\n\n        >>> model = ResNet(depth=50)\n        >>> # Initialize weights with the pretrained model.\n        >>> init_cfg = dict(type=\'Pretrained\',\n                checkpoint=\'torchvision://resnet50\')\n        >>> initialize(model, init_cfg)\n\n        >>> # Initialize weights of a sub-module with the specific part of\n        >>> # a pretrained model by using "prefix".\n        >>> url = \'http://download.openmmlab.com/mmdetection/v2.0/retinanet/\'        >>>     \'retinanet_r50_fpn_1x_coco/\'        >>>     \'retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth\'\n        >>> init_cfg = dict(type=\'Pretrained\',\n                checkpoint=url, prefix=\'backbone.\')\n    '
    if (not isinstance(init_cfg, (dict, list))):
        raise TypeError(f'init_cfg must be a dict or a list of dict,                 but got {type(init_cfg)}')
    if isinstance(init_cfg, dict):
        init_cfg = [init_cfg]
    for cfg in init_cfg:
        cp_cfg = copy.deepcopy(cfg)
        override = cp_cfg.pop('override', None)
        _initialize(module, cp_cfg)
        if (override is not None):
            cp_cfg.pop('layer', None)
            _initialize_override(module, override, cp_cfg)
        else:
            pass
Initialize a module.

Args:
    module (``torch.nn.Module``): the module will be initialized.
    init_cfg (dict | list[dict]): initialization configuration dict to
        define initializer. OpenMMLab has implemented 6 initializers
        including ``Constant``, ``Xavier``, ``Normal``, ``Uniform``,
        ``Kaiming``, and ``Pretrained``.
Example:
    >>> module = nn.Linear(2, 3, bias=True)
    >>> init_cfg = dict(type='Constant', layer='Linear', val =1 , bias =2)
    >>> initialize(module, init_cfg)

    >>> module = nn.Sequential(nn.Conv1d(3, 1, 3), nn.Linear(1,2))
    >>> # define key ``'layer'`` for initializing layer with different
    >>> # configuration
    >>> init_cfg = [dict(type='Constant', layer='Conv1d', val=1),
            dict(type='Constant', layer='Linear', val=2)]
    >>> initialize(module, init_cfg)

    >>> # define key``'override'`` to initialize some specific part in
    >>> # module
    >>> class FooNet(nn.Module):
    >>>     def __init__(self):
    >>>         super().__init__()
    >>>         self.feat = nn.Conv2d(3, 16, 3)
    >>>         self.reg = nn.Conv2d(16, 10, 3)
    >>>         self.cls = nn.Conv2d(16, 5, 3)
    >>> model = FooNet()
    >>> init_cfg = dict(type='Constant', val=1, bias=2, layer='Conv2d',
    >>>     override=dict(type='Constant', name='reg', val=3, bias=4))
    >>> initialize(model, init_cfg)

    >>> model = ResNet(depth=50)
    >>> # Initialize weights with the pretrained model.
    >>> init_cfg = dict(type='Pretrained',
            checkpoint='torchvision://resnet50')
    >>> initialize(model, init_cfg)

    >>> # Initialize weights of a sub-module with the specific part of
    >>> # a pretrained model by using "prefix".
    >>> url = 'http://download.openmmlab.com/mmdetection/v2.0/retinanet/'        >>>     'retinanet_r50_fpn_1x_coco/'        >>>     'retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth'
    >>> init_cfg = dict(type='Pretrained',
            checkpoint=url, prefix='backbone.')
def initialize(module, init_cfg):
    'Initialize a module.\n\n    Args:\n        module (``torch.nn.Module``): the module will be initialized.\n        init_cfg (dict | list[dict]): initialization configuration dict to\n            define initializer. OpenMMLab has implemented 6 initializers\n            including ``Constant``, ``Xavier``, ``Normal``, ``Uniform``,\n            ``Kaiming``, and ``Pretrained``.\n    Example:\n        >>> module = nn.Linear(2, 3, bias=True)\n        >>> init_cfg = dict(type=\'Constant\', layer=\'Linear\', val =1 , bias =2)\n        >>> initialize(module, init_cfg)\n\n        >>> module = nn.Sequential(nn.Conv1d(3, 1, 3), nn.Linear(1,2))\n        >>> # define key ``\'layer\'`` for initializing layer with different\n        >>> # configuration\n        >>> init_cfg = [dict(type=\'Constant\', layer=\'Conv1d\', val=1),\n                dict(type=\'Constant\', layer=\'Linear\', val=2)]\n        >>> initialize(module, init_cfg)\n\n        >>> # define key``\'override\'`` to initialize some specific part in\n        >>> # module\n        >>> class FooNet(nn.Module):\n        >>>     def __init__(self):\n        >>>         super().__init__()\n        >>>         self.feat = nn.Conv2d(3, 16, 3)\n        >>>         self.reg = nn.Conv2d(16, 10, 3)\n        >>>         self.cls = nn.Conv2d(16, 5, 3)\n        >>> model = FooNet()\n        >>> init_cfg = dict(type=\'Constant\', val=1, bias=2, layer=\'Conv2d\',\n        >>>     override=dict(type=\'Constant\', name=\'reg\', val=3, bias=4))\n        >>> initialize(model, init_cfg)\n\n        >>> model = ResNet(depth=50)\n        >>> # Initialize weights with the pretrained model.\n        >>> init_cfg = dict(type=\'Pretrained\',\n                checkpoint=\'torchvision://resnet50\')\n        >>> initialize(model, init_cfg)\n\n        >>> # Initialize weights of a sub-module with the specific part of\n        >>> # a pretrained model by using "prefix".\n        >>> url = \'http://download.openmmlab.com/mmdetection/v2.0/retinanet/\'        >>>     \'retinanet_r50_fpn_1x_coco/\'        >>>     \'retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth\'\n        >>> init_cfg = dict(type=\'Pretrained\',\n                checkpoint=url, prefix=\'backbone.\')\n    '
    if (not isinstance(init_cfg, (dict, list))):
        raise TypeError(f'init_cfg must be a dict or a list of dict,                 but got {type(init_cfg)}')
    if isinstance(init_cfg, dict):
        init_cfg = [init_cfg]
    for cfg in init_cfg:
        cp_cfg = copy.deepcopy(cfg)
        override = cp_cfg.pop('override', None)
        _initialize(module, cp_cfg)
        if (override is not None):
            cp_cfg.pop('layer', None)
            _initialize_override(module, override, cp_cfg)
        else:
            pass