o
    Vh                     @   s  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 dejZG dd dejZG dd dejZG dd deZe edejfdddddee dededefd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                       s@   e Zd Zdededededededejf f fdd	Z  ZS )
TemporalSeparableConv	in_planes
out_planeskernel_sizestridepadding
norm_layer.c                    sZ   t  t||d||fd||fd||fd|dt|||ddf|ddf|ddfd|d d S )N   r   F)r   r   r   biasr   )super__init__r   )selfr   r   r   r   r   r   	__class__ P/var/www/vscode/kcb/lib/python3.10/site-packages/torchvision/models/video/s3d.pyr      s(   		zTemporalSeparableConv.__init__)	__name__
__module____qualname__intr   r   Moduler   __classcell__r#   r#   r!   r$   r      s    r   c                       sP   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
dZdd Z  Z	S )SepInceptionBlock3Dr   b0_outb1_midb1_outb2_midb2_outb3_outr   .c	           	         s   t    t||dd|d| _tt||dd|dt||ddd|d| _tt||dd|dt||ddd|d| _ttj	ddddt||d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   r,   r-   r.   r/   r0   r1   r   r!   r#   r$   r   7   s   

zSepInceptionBlock3D.__init__c                 C   s@   |  |}| |}| |}| |}t||||fd}|S )Nr   )r5   r7   r8   r:   torchcat)r    xx0x1x2x3outr#   r#   r$   forwardR   s   



zSepInceptionBlock3D.forward)
r%   r&   r'   r(   r   r   r)   r   rC   r*   r#   r#   r!   r$   r+   6   s&    	r+   c                
       sR   e Zd ZdZ			ddededeedej	j
f  d	df fd
dZdd Z  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                    s  t    t|  |d u rttjddd}ttddddd|tjddd	d
t	dddd|dtddddd|tj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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"d
t
d#ddd!ddd|t
d#d$dd$ddd|| _tjd%dd&| _ttj|d'tjd(|ddd)d*| _d S )+NgMbP?)epsmomentumr   @      r   )r   r   r   )r   r   r   )r   r   r   r4   r   r2      `                r3   )r   r   r   )r   r   r   i     0   i      p            i   i  i@  )r   r   r   i@  i  )r   rL   rL   )r   r   )pi   T)r   r   r   )r   r   r
   r   r   BatchNorm3dr6   r   r9   r   r+   features	AvgPool3davgpoolDropoutConv3d
classifier)r    rF   rG   r   r!   r#   r$   r   h   sB   


zS3D.__init__c                 C   s0   |  |}| |}| |}tj|dd}|S )N)r   r      )dim)r\   r^   ra   r;   mean)r    r=   r#   r#   r$   rC      s
   


zS3D.forward)rD   rE   N)r%   r&   r'   __doc__r(   floatr   r   r;   r   r)   r   rC   r*   r#   r#   r!   r$   r   \   s    *r   c                   @   sF   e Zd Zedeedddddedddd	d
ddiddd	dZeZdS )r   z4https://download.pytorch.org/models/s3d-d76dad2f.pth)rW   rW   )rR   rR   )	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DEFAULTr#   r#   r#   r$   r      s0    r   
pretrained)weightsT)ry   progressry   rz   kwargsrH   c                 K   sV   t | } | durt|dt| jd  tdi |}| dur)|| j|d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:
    NrF   rl   T)rz   
check_hashr#   )r   verifyr   lenru   r   load_state_dictget_state_dict)ry   rz   r{   modelr#   r#   r$   r      s   
r   )!	functoolsr   typingr   r   r   r;   r   torchvision.ops.miscr   transforms._presetsr	   utilsr
   _apir   r   r   _metar   _utilsr   r   __all__r6   r   r)   r+   r   r   rv   boolr   r#   r#   r#   r$   <module>   s$     &>.