U
    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 dddg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ee eeed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                       s6   e Zd Zeeeeeedejf d fddZ  ZS )TemporalSeparableConv.)	in_planes
out_planeskernel_sizestridepadding
norm_layerc                    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__ N/var/www/html/venv/lib/python3.8/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                
       sB   e Zd Zeeeeeeeedejf d fddZdd Z  Z	S )SepInceptionBlock3D.)r   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    xZx0x1Zx2Zx3outr#   r#   r$   forwardR   s    



zSepInceptionBlock3D.forward)
r%   r&   r'   r(   r   r   r)   r   r@   r*   r#   r#   r!   r$   r+   6   s   r+   c                       sF   e Zd ZdZdeeeedej	j
f  dd 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 k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?)epsZ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   rH   rH   )r   r   )pi   T)r   r   r   )r   r   r
   r   r   ZBatchNorm3dr6   r   r9   r   r+   featuresZ	AvgPool3davgpoolZDropoutZConv3d
classifier)r    rC   rD   r   r!   r#   r$   r   h   sB    

zS3D.__init__c                 C   s0   |  |}| |}| |}tj|dd}|S )N)r   r      )dim)rW   rX   rY   r;   Zmean)r    r=   r#   r#   r$   r@      s
    


zS3D.forward)rA   rB   N)r%   r&   r'   __doc__r(   floatr   r   r;   r   r)   r   r@   r*   r#   r#   r!   r$   r   \   s      *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)rS   rS   )rN   rN   )Z	crop_sizeZ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?@)	Zmin_sizeZmin_temporal_size
categoriesZrecipeZ_docsZ
num_paramsZ_metricsZ_ops
_file_size)urlZ
transformsmetaN)	r%   r&   r'   r   r   r	   r   KINETICS400_V1DEFAULTr#   r#   r#   r$   r      s.   Z
pretrained)weightsT)re   progress)re   rf   kwargsrE   c                 K   sR   t | } | dk	r(t|dt| jd  tf |}| dk	rN|| 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:
    NrC   r_   T)rf   Z
check_hash)r   verifyr   lenrb   r   Zload_state_dictZget_state_dict)re   rf   rg   modelr#   r#   r$   r      s    

)!	functoolsr   typingr   r   r   r;   r   Ztorchvision.ops.miscr   Ztransforms._presetsr	   utilsr
   Z_apir   r   r   _metar   Z_utilsr   r   __all__r6   r   r)   r+   r   r   rc   boolr   r#   r#   r#   r$   <module>   s(    &>