o
    _{já  ã                	   @   sÞ   d dl Z d dlmZ d dlmZmZ d dlmZ ddlm	Z	m
Z
mZmZmZmZ z
d dlmZmZ W n eefyI   edƒZedƒd	d
„ ƒZY nw ddd„Zdd„ Zdd„ Zddd„Zdd„ Zdd„ Zddd„Zdd„ ZdS )é    N)ÚRegistryÚbuild_from_cfg)Úimport_module_error_funcé   )Ú	BACKBONESÚHEADSÚ
LOCALIZERSÚLOSSESÚNECKSÚRECOGNIZERS)Ú	DETECTORSÚbuild_detectorZdetectorÚmmdetc                 C   s   d S ©N© ©ÚcfgÚ	train_cfgÚtest_cfgr   r   ú-/root/disk_3tb/HAC/mmaction/models/builder.pyr      s   r   c                    s4   t | tƒr‡ ‡fdd„| D ƒ}tj|Ž S t| ˆˆ ƒS )ar  Build a module.

    Args:
        cfg (dict, list[dict]): The config of modules, it is either a dict
            or a list of configs.
        registry (:obj:`Registry`): A registry the module belongs to.
        default_args (dict, optional): Default arguments to build the module.
            Defaults to None.

    Returns:
        nn.Module: A built nn module.
    c                    s   g | ]}t |ˆˆ ƒ‘qS r   )r   )Ú.0Úcfg_©Údefault_argsÚregistryr   r   Ú
<listcomp>#   s    ÿzbuild.<locals>.<listcomp>)Ú
isinstanceÚlistÚnnÚ
Sequentialr   )r   r   r   Úmodulesr   r   r   Úbuild   s   
ÿ
r!   c                 C   ó
   t | tƒS )zBuild backbone.)r!   r   ©r   r   r   r   Úbuild_backbone+   ó   
r$   c                 C   r"   )zBuild head.)r!   r   r#   r   r   r   Ú
build_head0   r%   r&   c                 C   sl   |dus|durt  dt¡ |  d¡du s|du sJ dƒ‚|  d¡du s,|du s,J dƒ‚t| tt||d�ƒS )zBuild recognizer.Nú‰train_cfg and test_cfg is deprecated, please specify them in model. Details see this PR: https://github.com/open-mmlab/mmaction2/pull/629r   z8train_cfg specified in both outer field and model field r   z7test_cfg specified in both outer field and model field )r   r   )ÚwarningsÚwarnÚUserWarningÚgetr!   r   Údictr   r   r   r   Úbuild_recognizer5   s   üÿÿ
ÿr-   c                 C   r"   )zBuild loss.)r!   r	   r#   r   r   r   Ú
build_lossE   r%   r.   c                 C   r"   )zBuild localizer.)r!   r   r#   r   r   r   Úbuild_localizerJ   r%   r/   c                 C   sŠ   |   ¡ }| d¡}|tv rt| ƒS |tv rt| ||ƒS |tv r3|dus'|dur-t dt	¡ t
| ||ƒS dg}||v r>tdƒ‚t|› d�ƒ‚)zBuild model.ÚtypeNr'   ZFastRCNNz:Please install mmdet for spatial temporal detection tasks.z: is not registered in LOCALIZERS, RECOGNIZERS or DETECTORS)ÚcopyÚpopr   r/   r   r-   r   r(   r)   r*   r   ÚImportErrorÚ
ValueError)r   r   r   ÚargsÚobj_typeZmodel_in_mmdetr   r   r   Úbuild_modelO   s&   
üÿr7   c                 C   r"   )zBuild neck.)r!   r
   r#   r   r   r   Ú
build_neckg   r%   r8   r   )NN)r(   Útorch.nnr   Z
mmcv.utilsr   r   Úmmaction.utilsr   r   r   r   r   r	   r
   r   Zmmdet.models.builderr   r   r3   ÚModuleNotFoundErrorr!   r$   r&   r-   r.   r/   r7   r8   r   r   r   r   Ú<module>   s(     û
	

