
    ڧg                        d dl mZ d dlmZmZmZ d dlZd dlmZ d dlm	Z	 ddl
mZ ddlmZ d	d
lmZmZmZ d	dlmZ d	dlmZmZ g dZ G d dej                  Z G d dej                  Z G d dej                  Z G d de          Z e             edej        f          ddddee         dededefd                        Z dS )    )partial)AnyCallableOptionalN)nn)Conv3dNormActivation   )VideoClassification)_log_api_usage_once   )register_modelWeightsWeightsEnum)_KINETICS400_CATEGORIES)_ovewrite_named_paramhandle_legacy_interface)S3DS3D_Weightss3dc                   R     e Zd Zdededededededej        f         f fdZ xZS )	TemporalSeparableConv	in_planes
out_planeskernel_sizestridepadding
norm_layer.c                     t                                          t          ||d||fd||fd||fd|          t          |||ddf|ddf|ddfd|                     d S )N   r   F)r   r   r   biasr   )super__init__r   )selfr   r   r   r   r   r   	__class__s          X/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/models/video/s3d.pyr"   zTemporalSeparableConv.__init__   s     	 [966*GW-%   !(!Q/1~ !Q%  	
 	
 	
 	
 	
    )	__name__
__module____qualname__intr   r   Moduler"   __classcell__r$   s   @r%   r   r      s        

 
 	

 
 
 S")^,
 
 
 
 
 
 
 
 
 
r&   r   c                   `     e Zd Zdedededededededed	ej        f         f fd
Zd Z xZ	S )SepInceptionBlock3Dr   b0_outb1_midb1_outb2_midb2_outb3_outr   .c	                    t                                                       t          ||dd|          | _        t	          j        t          ||dd|          t          ||ddd|                    | _        t	          j        t          ||dd|          t          ||ddd|                    | _        t	          j        t	          j	        ddd          t          ||dd|                    | _
        d S )Nr   r   r   r   r	   )r   r   r   r   r	   r	   r	   r   r   r   )r!   r"   r   branch0r   
Sequentialr   branch1branch2	MaxPool3dbranch3)
r#   r   r0   r1   r2   r3   r4   r5   r   r$   s
            r%   r"   zSepInceptionBlock3D.__init__7   s    	+Iv1UVcmnnn} F!Xbccc!&&aSTaklll
 
 } F!Xbccc!&&aSTaklll
 
 }LYq!DDD F!Xbccc
 
r&   c                     |                      |          }|                     |          }|                     |          }|                     |          }t	          j        ||||fd          }|S )Nr   )r:   r<   r=   r?   torchcat)r#   xx0x1x2x3outs          r%   forwardzSepInceptionBlock3D.forwardR   s]    \\!__\\!__\\!__\\!__iRR(!,,
r&   )
r'   r(   r)   r*   r   r   r+   r"   rI   r,   r-   s   @r%   r/   r/   6   s        

 
 	

 
 
 
 
 S")^,
 
 
 
 
 
6      r&   r/   c            
       r     e Zd ZdZ	 	 	 ddededeedej	        j
        f                  d	df fd
Zd Z xZS )r   aW  S3D main class.

    Args:
        num_class (int): number of classes for the classification task.
        dropout (float): dropout probability.
        norm_layer (Optional[Callable]): Module specifying the normalization layer to use.

    Inputs:
        x (Tensor): batch of videos with dimensions (batch, channel, time, height, width)
      皙?Nnum_classesdropoutr   .returnc                 ,   t                                                       t          |            |t          t          j        dd          }t	          j        t          ddddd|          t	          j        ddd	
          t          dddd|          t          ddddd|          t	          j        ddd	
          t          ddddddd|          t          ddddddd|          t	          j        ddd
          t          ddddddd|          t          ddddddd|          t          ddddddd|          t          ddddddd|          t          d ddd!ddd|          t	          j        ddd"
          t          d#ddd!ddd|          t          d#d$dd$ddd|                    | _        t	          j        d%d&          | _        t	          j        t	          j        |'          t	          j        d(|ddd)*                    | _        d S )+NgMbP?)epsmomentumr	   @      r   )r   r	   r	   )r   r   r   )r   r   r   r9   r   r7      `                r8   )r   r   r   )r   r   r   i     0   i      p            i   i  i@  )r   r   r   i@  i  )r   rT   rT   )r   r   )pi   T)r   r   r    )r!   r"   r   r   r   BatchNorm3dr;   r   r>   r   r/   features	AvgPool3davgpoolDropoutConv3d
classifier)r#   rM   rN   r   r$   s       r%   r"   zS3D.__init__h   s-    	D!!! UUKKKJ!!RAq*==LYy)TTT %   ""c1aJ??LYy)TTTRS"b"jIIS#sBB
KKLYy)TTTS"c2r2zJJS#sBB
KKS#sBB
KKS#sBB
KKS#sBS*MMLYy)TTTS#sBS*MMS#sBS*MM-
 
0 |	!DDD-J!!!IdKQqtLLL
 
r&   c                     |                      |          }|                     |          }|                     |          }t          j        |d          }|S )N)r   r	      )dim)rd   rf   ri   rA   mean)r#   rC   s     r%   rI   zS3D.forward   sL    MM!LLOOOOAJqi(((r&   )rK   rL   N)r'   r(   r)   __doc__r*   floatr   r   rA   r   r+   r"   rI   r,   r-   s   @r%   r   r   \   s        	 	 ?C	(
 (
(
 (
 Xc58?&:;<	(

 
(
 (
 (
 (
 (
 (
T      r&   r   c                   d    e Zd Z ed eedd          ddedddd	d
ddiddd	          ZeZdS )r   z4https://download.pytorch.org/models/s3d-d76dad2f.pth)r_   r_   )rZ   rZ   )	crop_sizeresize_size   zOhttps://github.com/pytorch/vision/tree/main/references/video_classification#s3dzThe weights aim to approximate the accuracy of the paper. The accuracies are estimated on clip-level with parameters `frame_rate=15`, `clips_per_video=1`, and `clip_len=128`.i0~ zKinetics-400gd;OQ@g33333V@)zacc@1zacc@5gv1@gF?@)	min_sizemin_temporal_size
categoriesrecipe_docs
num_params_metrics_ops
_file_size)url
transformsmetaN)	r'   r(   r)   r   r   r
   r   KINETICS400_V1DEFAULT r&   r%   r   r      s        WB7 "
 
 
 #!#1g\ "##! !  #
 
  N6 GGGr&   r   
pretrained)weightsT)r   progressr   r   kwargsrO   c                     t                               |           } | )t          |dt          | j        d                              t          di |}| *|                    |                     |d                     |S )a  Construct Separable 3D CNN model.

    Reference: `Rethinking Spatiotemporal Feature Learning <https://arxiv.org/abs/1712.04851>`__.

    .. betastatus:: video module

    Args:
        weights (:class:`~torchvision.models.video.S3D_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.video.S3D_Weights`
            below for more details, and possible values. By default, no
            pre-trained weights are used.
        progress (bool): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to the ``torchvision.models.video.S3D`` base class.
            Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/video/s3d.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.video.S3D_Weights
        :members:
    NrM   rv   T)r   
check_hashr   )r   verifyr   lenr   r   load_state_dictget_state_dict)r   r   r   models       r%   r   r      s    0   ))GfmSl9S5T5TUUUMM&MMEg44hSW4XXYYYLr&   )!	functoolsr   typingr   r   r   rA   r   torchvision.ops.miscr   transforms._presetsr
   utilsr   _apir   r   r   _metar   _utilsr   r   __all__r;   r   r+   r/   r   r   r   boolr   r   r&   r%   <module>r      s         * * * * * * * * * *        5 5 5 5 5 5 6 6 6 6 6 6 ( ( ( ( ( ( 7 7 7 7 7 7 7 7 7 7 + + + + + + C C C C C C C C  
 
 
 
 
BM 
 
 
@# # # # #") # # #L; ; ; ; ;") ; ; ;|    +   > ,0J!KLLL,04      H[)  D  SV  [^       ML      r&   