o

    +h                     @   s   d dl mZ d dlZd dlZG dd dejZG dd deejZG dd dejZG dd	 d	eejZG d
d deej	Z	dS )    Nc                       s6   e Zd ZdZd	 fdd	Zedd Zdd Z  ZS )

BaseModulea  Base module for all modules in openmmlab.

    ``BaseModule`` is a wrapper of ``torch.nn.Module`` with additional
    functionality of parameter initialization. Compared with
    ``torch.nn.Module``, ``BaseModule`` mainly adds three attributes.

    - ``init_cfg``: the config to control the initialization.
    - ``init_weights``: The function of parameter initialization and recording
      initialization information.
    - ``_params_init_info``: Used to track the parameter initialization
      information. This attribute only exists during executing the
      ``init_weights``.

    Args:
        init_cfg (dict, optional): Initialization config dict.
    Nc                    s$   t t|   d| _t|| _dS )z7Initialize BaseModule, inherited from `torch.nn.Module`FN)superr   __init___is_initcopydeepcopyinit_cfg)selfr   	__class__ 5/root/Awesome-Backbones/configs/common/base_module.pyr      s   zBaseModule.__init__c                 C   s   | j S N)r   )r	   r   r   r
   is_init*   s   zBaseModule.is_initc                 C   s   ddl m} | js6| jr!|| | j t| jtr!| jd dkr!dS |  D ]}t|dr0|  q%d| _dS t	
d| jj d	 dS )
zInitialize the weights.r   )
initializetypeZ
PretrainedNinit_weightsTzinit_weights of z  has been called more than once.)
core.initializer   r   r   
isinstancedictchildrenhasattrr   warningswarnr   __name__)r	   r   mr   r   r
   r   .   s   

zBaseModule.init_weightsr   )	r   
__module____qualname____doc__r   propertyr   r   
__classcell__r   r   r
   r
   r      s    
r   c                   @   s   e Zd ZdZddddZdS )
SequentialznSequential module in openmmlab.

    Args:
        init_cfg (dict, optional): Initialization config dict.
    N)r   c                G   s$   t | | tjj| g|R   d S r   )r   r   nnr!   )r	   r   argsr   r   r
   r   O   s   zSequential.__init__r   r   r   r   r   r   r   r   r
   r!   H   s    r!   c                       s$   e Zd Z fddZdd Z  ZS )TwoInputSequentialc                    s   t t|   t|| _d S r   )r   r%   r   r"   
ModuleListmodule_list)r	   modulesr
   r   r
   r   T   s   zTwoInputSequential.__init__c                 C   s$   | j D ]
}||}||}q||fS r   )r'   )r	   x1x2moduler   r   r
   forwardX   s   

zTwoInputSequential.forward)r   r   r   r   r,   r    r   r   r
   r
   r%   S   s    r%   c                   @      e Zd ZdZdddZdS )r&   zModuleList in openmmlab.

    Args:
        modules (iterable, optional): an iterable of modules to add.
        init_cfg (dict, optional): Initialization config dict.
    Nc                 C      t | | tj| | d S r   )r   r   r"   r&   r	   r(   r   r   r   r
   r   f      zModuleList.__init__NNr$   r   r   r   r
   r&   ^   s    r&   c                   @   r-   )
ModuleDictzModuleDict in openmmlab.

    Args:
        modules (dict, optional): a mapping (dictionary) of (string: module)
            or an iterable of key-value pairs of type (string, module).
        init_cfg (dict, optional): Initialization config dict.
    Nc                 C   r.   r   )r   r   r"   r2   r/   r   r   r
   r   s   r0   zModuleDict.__init__r1   r$   r   r   r   r
   r2   j   s    r2   )
torch.nnr"   r   r   Moduler   r!   r%   r&   r2   r   r   r   r
   <module>   s    C