
    9i                         S SK Jr  SSKJr  SSKJr   " S S\R                  5      r " S S\R                  5      r " S	 S
\R                  5      r	g)    N   )Inception3D)TadaConvNeXtc                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )BaseVideoModel
   a  
Standard video model.
The model is divided into the backbone and the head, where the backbone
extracts features and the head performs classification.

The backbones can be defined in model/base/backbone.py or anywhere else
as long as the backbone is registered by the BACKBONE_REGISTRY.
The heads can be defined in model/module_zoo/heads/ or anywhere else
as long as the head is registered by the HEAD_REGISTRY.

The registries automatically finds the registered modules and construct
the base video model.
c                 |  > [         [        U ]  5         UR                  R                  S:X  a  [        U5      U l        O[UR                  R                  S:X  a  [        U5      U l        O0SR                  UR                  R                  5      n[        U5      eUR                  R                  R                  S:X  a  [        U5      U l        gUR                  R                  R                  S:X  a  [        U5      U l        gSR                  UR                  R                  R                  5      n[        U5      e)/
Args:
    cfg (Config): global config object.
ConvNeXt_tinyS3DGz@backbone {} is not supported, ConvNeXt_tiny or S3DG is supportedBaseHeadAvgHeadz:head {} is not supported, BaseHead or AvgHead is supportedN)superr   __init__MODELNAMEr   backboner   formatNotImplementedErrorVIDEOHEADr   headr   )selfcfg	error_str	__class__s      n/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/models/cv/action_recognition/models.pyr   BaseVideoModel.__init__   s    
 	nd,. 99>>_,(-DMYY^^v%',DMZaa		 I%i00 99>>*, DIYY^^  I-DIT[[		##%I%i00    c                 J    U R                  U5      nU R                  U5      nU$ )Nr   r   )r   xs     r   forwardBaseVideoModel.forward5   s"    MM!IIaLr   r!   	__name__
__module____qualname____firstlineno____doc__r   r#   __static_attributes____classcell__r   s   @r   r   r   
   s    18 r   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )r   ;   
Constructs base head.
c                 Z  > [         [        U ]  5         Xl        UR                  R
                  R                  nUR                  R                  R                  nUR                  R                  R                  nUR                  R                  R                  nU R                  X#XE5        g)r
   N)r   r   r   r   r   BACKBONENUM_OUT_FEATURESr   NUM_CLASSESDROPOUT_RATE
ACTIVATION_construct_head)r   r   dimnum_classesdropout_rateactivation_funcr   s         r   r   BaseHead.__init__@   su     	h&(ii  11iinn00yy~~22))..33S|Mr   c                 d   [         R                  " S5      U l        US:  a  [         R                  " U5      U l        [         R
                  " XSS9U l        US:X  a  [         R                  " SS9U l        g US:X  a  [         R                  " 5       U l        g [        S	R                  U5      5      e)
Nr   g        T)biassoftmax)r8   sigmoidz-{} is not supported as an activationfunction.)nnAdaptiveAvgPool3dglobal_avg_poolDropoutdropoutLinearoutSoftmax
activationSigmoidr   r   )r   r8   r9   r:   r;   s        r   r7   BaseHead._construct_headP   s    !33A6#::l3DL99SD9i' jjR0DO	) jjlDO% '228&2IK Kr   c                    [        UR                  5      S:X  a"  U R                  U5      nUR                  S5      n[	        U S5      (       a  U R                  U5      nOUnU R                  U5      nU R                  U5      nUR                  UR                  S   S5      nX!R                  UR                  S   S5      4$ )N   r            r   rF   r   r@   )	lenshaperD   permutehasattrrF   rH   rJ   viewr   r"   rH   s      r   r#   BaseHead.forward`   s    qww<1$$Q'A		/*A4##,,q/CChhsmooc"hhsyy|R(FF1771:r***r   )rJ   r   rF   rD   rH   )
r&   r'   r(   r)   r*   r   r7   r#   r+   r,   r-   s   @r   r   r   ;   s    N K + +r   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r   o   r0   c                 l   > [         [        U ]  5         Xl        [        R
                  " S5      U l        g)r
   r   N)r   r   r   r   rB   rC   rD   )r   r   r   s     r   r   AvgHead.__init__t   s*     	gt%'!33A6r   c                     [        UR                  5      S:X  a"  U R                  U5      nUR                  S5      nUR	                  UR                  S   S5      nX!R	                  UR                  S   S5      4$ )NrN   rO   r   r@   )rS   rT   rD   rU   rW   rX   s      r   r#   AvgHead.forward   sd    qww<1$$Q'A		/*AffQWWQZ$FF1771:r***r   )r   rD   r%   r-   s   @r   r   r   o   s    
7+ +r   r   )
torch.nnrB   s3dgr   tada_convnextr   Moduler   r   r    r   r   <module>re      sB      '.RYY .b1+ryy 1+h+bii +r   