o
    ôj5}  ã                   @   sˆ  d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlZd dlZd dlm  mZ d dlmZ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	lmZmZ d d
l m!Z! d dl"m#Z#m$Z$ d dl%m&Z& g d¢Z'dee(e(f de(de(de(dee(e(f f
dd„Z)dee(e(f de(deee(e(f  fdd„Z*de(de(dejfd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j,ƒZ0G d$d%„ d%ej,ƒZ1G d&d'„ d'ej,ƒZ2G d(d)„ d)ej,ƒZ3G d*d+„ d+ej,ƒZ4G d,d-„ d-ej,ƒZ5		.dBd/e(d0ee( d1ee( d2e6d3e(d4e(d5e	e d6e7d7ede5fd8d9„Z8G d:d;„ d;eƒZ9eƒ ed<e9j:fd=�dd>d?œd5e	e9 d6e7d7ede5fd@dA„ƒƒZ;dS )Cé    N)ÚOrderedDict)Úpartial)ÚAnyÚCallableÚListÚOptionalÚSequenceÚTuple)ÚnnÚTensor)Úregister_modelÚWeightsÚWeightsEnum)Ú_IMAGENET_CATEGORIES)Ú_ovewrite_named_paramÚhandle_legacy_interface)ÚConv2dNormActivationÚSqueezeExcitation)ÚStochasticDepth)ÚImageClassificationÚInterpolationMode)Ú_log_api_usage_once)ÚMaxVitÚMaxVit_T_WeightsÚmaxvit_tÚ
input_sizeÚkernel_sizeÚstrideÚpaddingÚreturnc                 C   s8   | d | d|  | d | d | d|  | d fS )Nr   é   é   © )r   r   r   r   r"   r"   új/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/models/maxvit.pyÚ_get_conv_output_shape   s   þr$   Ún_blocksc                 C   s<   g }t | dddƒ}t|ƒD ]}t |dddƒ}| |¡ q|S )zQUtil function to check that the input size is correct for a MaxVit configuration.é   r    r!   )r$   ÚrangeÚappend)r   r%   ÚshapesZblock_input_shapeÚ_r"   r"   r#   Ú_make_block_input_shapes    s   r+   ÚheightÚwidthc                 C   sÞ   t  t  t  | ¡t  |¡g¡¡}t  |d¡}|d d …d d …d f |d d …d d d …f  }| ddd¡ ¡ }|d d …d d …df  | d 7  < |d d …d d …df  |d 7  < |d d …d d …df  d| d 9  < | d¡S )Nr!   r    r   éÿÿÿÿ)ÚtorchÚstackÚmeshgridÚarangeÚflattenÚpermuteÚ
contiguousÚsum)r,   r-   ÚcoordsZcoords_flatÚrelative_coordsr"   r"   r#   Ú_get_relative_position_index*   s    ,""&
r9   c                       sp   e Zd ZdZ	ddedededededed	ejf d
ed	ejf deddf‡ fdd„Z	de
de
fdd„Z‡  ZS )ÚMBConva=  MBConv: Mobile Inverted Residual Bottleneck.

    Args:
        in_channels (int): Number of input channels.
        out_channels (int): Number of output channels.
        expansion_ratio (float): Expansion ratio in the bottleneck.
        squeeze_ratio (float): Squeeze ratio in the SE Layer.
        stride (int): Stride of the depthwise convolution.
        activation_layer (Callable[..., nn.Module]): Activation function.
        norm_layer (Callable[..., nn.Module]): Normalization function.
        p_stochastic_dropout (float): Probability of stochastic depth.
    ç        Úin_channelsÚout_channelsÚexpansion_ratioÚsqueeze_ratior   Úactivation_layer.Ú
norm_layerÚp_stochastic_dropoutr   Nc	                    s*  t ƒ  ¡  |  |dkp||k}	|	r2tj||dddd�g}
|dkr+tjd|dd�g|
 }
tj|
Ž | _nt ¡ | _t|| ƒ}t|| ƒ}|rMt	|dd�| _
nt ¡ | _
tƒ }||ƒ|d	< t||ddd
||d d�|d< t||d|d|||d d�	|d< t||tjd�|d< tj||ddd�|d< t |¡| _d S )Nr!   T)r   r   Úbiasr    r&   ©r   r   r   Úrow©ÚmodeZpre_normr   )r   r   r   r@   rA   ÚinplaceZconv_a)r   r   r   r@   rA   ÚgroupsrH   Úconv_b)Ú
activationZsqueeze_excitation)r<   r=   r   rC   Zconv_c)ÚsuperÚ__init__r
   ÚConv2dÚ	AvgPool2dÚ
SequentialÚprojÚIdentityÚintr   Ústochastic_depthr   r   r   ÚSiLUÚlayers)Úselfr<   r=   r>   r?   r   r@   rA   rB   Úshould_projrQ   Zmid_channelsZsqz_channelsZ_layers©Ú	__class__r"   r#   rM   C   sP   



ø

÷zMBConv.__init__Úxc                 C   s"   |   |¡}|  |  |¡¡}|| S )zÍ
        Args:
            x (Tensor): Input tensor with expected layout of [B, C, H, W].
        Returns:
            Tensor: Output tensor with expected layout of [B, C, H / stride, W / stride].
        )rQ   rT   rV   ©rW   r[   Úresr"   r"   r#   Úforward€   s   
zMBConv.forward)r;   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rS   Úfloatr   r
   ÚModulerM   r   r^   Ú__classcell__r"   r"   rY   r#   r:   5   s.    ÷þýüûúùø	÷
ö=r:   c                       sT   e Zd ZdZdedededdf‡ fdd„Zdejfd	d
„Zdedefdd„Z	‡  Z
S )Ú$RelativePositionalMultiHeadAttentionzÔRelative Positional Multi-Head Attention.

    Args:
        feat_dim (int): Number of input features.
        head_dim (int): Number of features per head.
        max_seq_len (int): Maximum sequence length.
    Úfeat_dimÚhead_dimÚmax_seq_lenr   Nc                    sð   t ƒ  ¡  || dkrtd|› d|› �ƒ‚|| | _|| _tt |¡ƒ| _|| _	t
 || j| j d ¡| _|d | _t
 | j| j |¡| _t
j tjd| j d d| j d  | jftjd�¡| _|  d	t| j| jƒ¡ tj
jj| jd
d� d S )Nr   z
feat_dim: z  must be divisible by head_dim: r&   g      à¿r    r!   )ÚdtypeÚrelative_position_indexç{®Gáz”?©Ústd)rL   rM   Ú
ValueErrorÚn_headsrh   rS   ÚmathÚsqrtÚsizeri   r
   ÚLinearÚto_qkvÚscale_factorÚmergeÚ	parameterÚ	Parameterr/   ÚemptyÚfloat32Úrelative_position_bias_tableÚregister_bufferr9   ÚinitÚtrunc_normal_)rW   rg   rh   ri   rY   r"   r#   rM   •   s   


,ÿz-RelativePositionalMultiHeadAttention.__init__c                 C   s@   | j  d¡}| j|  | j| jd¡}| ddd¡ ¡ }| d¡S )Nr.   r    r   r!   )rk   Úviewr|   ri   r4   r5   Ú	unsqueeze)rW   Z
bias_indexZrelative_biasr"   r"   r#   Úget_relative_positional_bias±   s   
zARelativePositionalMultiHeadAttention.get_relative_positional_biasr[   c                 C   s  |j \}}}}| j| j}}|  |¡}tj|ddd�\}	}
}|	 |||||¡ ddddd¡}	|
 |||||¡ ddddd¡}
| |||||¡ ddddd¡}|
| j }
t 	d|	|
¡}|  
¡ }tj|| dd�}t 	d	||¡}| ddddd¡ ||||¡}|  |¡}|S )
z»
        Args:
            x (Tensor): Input tensor with expected layout of [B, G, P, D].
        Returns:
            Tensor: Output tensor with expected layout of [B, G, P, D].
        r&   r.   )Údimr   r!   r    é   z!B G H I D, B G H J D -> B G H I Jz!B G H I J, B G H J D -> B G H I D)Úshaperp   rh   ru   r/   ÚchunkÚreshaper4   rv   Úeinsumr‚   ÚFÚsoftmaxrw   )rW   r[   ÚBÚGÚPÚDÚHÚDHÚqkvÚqÚkÚvZdot_prodZpos_biasÚoutr"   r"   r#   r^   ·   s   
   

z,RelativePositionalMultiHeadAttention.forward)r_   r`   ra   rb   rS   rM   r/   r   r‚   r^   re   r"   r"   rY   r#   rf   Œ   s    þýüûrf   c                       sD   e Zd ZdZdededdf‡ fdd„Zdejdejfd	d
„Z‡  Z	S )ÚSwapAxeszPermute the axes of a tensor.ÚaÚbr   Nc                    s   t ƒ  ¡  || _|| _d S ©N)rL   rM   r—   r˜   )rW   r—   r˜   rY   r"   r#   rM   Ø   s   

zSwapAxes.__init__r[   c                 C   s   t  || j| j¡}|S r™   )r/   Úswapaxesr—   r˜   r\   r"   r"   r#   r^   Ý   s   zSwapAxes.forward)
r_   r`   ra   rb   rS   rM   r/   r   r^   re   r"   r"   rY   r#   r–   Õ   s    r–   c                       s8   e Zd ZdZd
‡ fdd„Zdededefdd	„Z‡  ZS )ÚWindowPartitionzB
    Partition the input tensor into non-overlapping windows.
    r   Nc                    ó   t ƒ  ¡  d S r™   ©rL   rM   ©rW   rY   r"   r#   rM   ç   ó   zWindowPartition.__init__r[   Úpc                 C   sf   |j \}}}}|}| |||| ||| |¡}| dddddd¡}| ||| ||  || |¡}|S )zï
        Args:
            x (Tensor): Input tensor with expected layout of [B, C, H, W].
            p (int): Number of partitions.
        Returns:
            Tensor: Output tensor with expected layout of [B, H/P, W/P, P*P, C].
        r   r    r„   r&   é   r!   ©r…   r‡   r4   )rW   r[   r    r‹   ÚCr�   ÚWr�   r"   r"   r#   r^   ê   s    zWindowPartition.forward©r   N©	r_   r`   ra   rb   rM   r   rS   r^   re   r"   r"   rY   r#   r›   â   s    r›   c                
       s@   e Zd ZdZd‡ fdd„Zdededed	edef
d
d„Z‡  ZS )ÚWindowDepartitionzo
    Departition the input tensor of non-overlapping windows into a feature volume of layout [B, C, H, W].
    r   Nc                    rœ   r™   r�   rž   rY   r"   r#   rM     rŸ   zWindowDepartition.__init__r[   r    Úh_partitionsÚw_partitionsc                 C   s`   |j \}}}}|}	||}
}| ||
||	|	|¡}| dddddd¡}| |||
|	 ||	 ¡}|S )ar  
        Args:
            x (Tensor): Input tensor with expected layout of [B, (H/P * W/P), P*P, C].
            p (int): Number of partitions.
            h_partitions (int): Number of vertical partitions.
            w_partitions (int): Number of horizontal partitions.
        Returns:
            Tensor: Output tensor with expected layout of [B, C, H, W].
        r   r¡   r!   r&   r    r„   r¢   )rW   r[   r    r¨   r©   r‹   rŒ   ZPPr£   r�   ZHPZWPr"   r"   r#   r^     s   

zWindowDepartition.forwardr¥   r¦   r"   r"   rY   r#   r§   ü   s    &r§   c                       s€   e Zd ZdZdededededeeef deded	ej	f d
ed	ej	f de
de
de
ddf‡ fdd„Zdedefdd„Z‡  ZS )ÚPartitionAttentionLayera®  
    Layer for partitioning the input tensor into non-overlapping windows and applying attention to each window.

    Args:
        in_channels (int): Number of input channels.
        head_dim (int): Dimension of each attention head.
        partition_size (int): Size of the partitions.
        partition_type (str): Type of partitioning to use. Can be either "grid" or "window".
        grid_size (Tuple[int, int]): Size of the grid to partition the input tensor into.
        mlp_ratio (int): Ratio of the  feature size expansion in the MLP layer.
        activation_layer (Callable[..., nn.Module]): Activation function to use.
        norm_layer (Callable[..., nn.Module]): Normalization function to use.
        attention_dropout (float): Dropout probability for the attention layer.
        mlp_dropout (float): Dropout probability for the MLP layer.
        p_stochastic_dropout (float): Probability of dropping out a partition.
    r<   rh   Úpartition_sizeÚpartition_typeÚ	grid_sizeÚ	mlp_ratior@   .rA   Úattention_dropoutÚmlp_dropoutrB   r   Nc              	      s(  t ƒ  ¡  || | _|| _|d | | _|| _|| _|dvr"tdƒ‚|dkr/|| j| _| _	n| j|| _| _	t
ƒ | _tƒ | _|dkrHtddƒnt ¡ | _|dkrVtddƒnt ¡ | _t ||ƒt|||d ƒt |	¡¡| _t t |¡t ||| ¡|ƒ t || |¡t |
¡¡| _t|d	d
�| _d S )Nr   )ÚgridÚwindowz0partition_type must be either 'grid' or 'window'r²   r±   éþÿÿÿéýÿÿÿr    rE   rF   )rL   rM   rp   rh   Zn_partitionsr¬   r­   ro   r    Úgr›   Úpartition_opr§   Údepartition_opr–   r
   rR   Úpartition_swapÚdepartition_swaprP   rf   ÚDropoutÚ
attn_layerÚ	LayerNormrt   Ú	mlp_layerr   Ústochastic_dropout)rW   r<   rh   r«   r¬   r­   r®   r@   rA   r¯   r°   rB   rY   r"   r#   rM   ,  s8   

û	û	z PartitionAttentionLayer.__init__r[   c                 C   s¾   | j d | j | j d | j }}t | j d | j dko&| j d | j dkd | j | j¡¡ |  || j¡}|  |¡}||  |  |¡¡ }||  |  	|¡¡ }|  
|¡}|  || j||¡}|S )z»
        Args:
            x (Tensor): Input tensor with expected layout of [B, C, H, W].
        Returns:
            Tensor: Output tensor with expected layout of [B, C, H, W].
        r   r!   z[Grid size must be divisible by partition size. Got grid size of {} and partition size of {})r­   r    r/   Ú_assertÚformatr¶   r¸   r¾   r»   r½   r¹   r·   )rW   r[   ÚghZgwr"   r"   r#   r^   f  s   "
&ÿþ

zPartitionAttentionLayer.forward)r_   r`   ra   rb   rS   Ústrr	   r   r
   rd   rc   rM   r   r^   re   r"   r"   rY   r#   rª     s8    þýûú
	÷
öõôóòñð:rª   c                       sŒ   e Zd ZdZdededededededejf d	edejf d
edededededede	eef ddf‡ fdd„Z
dedefdd„Z‡  ZS )ÚMaxVitLayera  
    MaxVit layer consisting of a MBConv layer followed by a PartitionAttentionLayer with `window` and a PartitionAttentionLayer with `grid`.

    Args:
        in_channels (int): Number of input channels.
        out_channels (int): Number of output channels.
        expansion_ratio (float): Expansion ratio in the bottleneck.
        squeeze_ratio (float): Squeeze ratio in the SE Layer.
        stride (int): Stride of the depthwise convolution.
        activation_layer (Callable[..., nn.Module]): Activation function.
        norm_layer (Callable[..., nn.Module]): Normalization function.
        head_dim (int): Dimension of the attention heads.
        mlp_ratio (int): Ratio of the MLP layer.
        mlp_dropout (float): Dropout probability for the MLP layer.
        attention_dropout (float): Dropout probability for the attention layer.
        p_stochastic_dropout (float): Probability of stochastic depth.
        partition_size (int): Size of the partitions.
        grid_size (Tuple[int, int]): Size of the input feature grid.
    r<   r=   r?   r>   r   rA   .r@   rh   r®   r°   r¯   rB   r«   r­   r   Nc                    s„   t ƒ  ¡  tƒ }t||||||||d�|d< t|||d||	|tj||
|d�|d< t|||d||	|tj||
|d�|d< t |¡| _d S )N)r<   r=   r>   r?   r   r@   rA   rB   ZMBconvr²   )r<   rh   r«   r¬   r­   r®   r@   rA   r¯   r°   rB   Zwindow_attentionr±   Zgrid_attention)	rL   rM   r   r:   rª   r
   r¼   rP   rV   )rW   r<   r=   r?   r>   r   rA   r@   rh   r®   r°   r¯   rB   r«   r­   rV   rY   r"   r#   rM   —  sN   

ø
õ
õzMaxVitLayer.__init__r[   c                 C   s   |   |¡}|S ©z�
        Args:
            x (Tensor): Input tensor of shape (B, C, H, W).
        Returns:
            Tensor: Output tensor of shape (B, C, H, W).
        ©rV   )rW   r[   r"   r"   r#   r^   Ø  s   
zMaxVitLayer.forward)r_   r`   ra   rb   rS   rc   r   r
   rd   r	   rM   r   r^   re   r"   r"   rY   r#   rÃ   ‚  sD    ýüûúù	÷
öôóòñðî
íìArÃ   c                       s�   e Zd ZdZdedededededejf dedejf d	ed
edededede	eef dede
e ddf‡ fdd„Zdedefdd„Z‡  ZS )ÚMaxVitBlocka(  
    A MaxVit block consisting of `n_layers` MaxVit layers.

     Args:
        in_channels (int): Number of input channels.
        out_channels (int): Number of output channels.
        expansion_ratio (float): Expansion ratio in the bottleneck.
        squeeze_ratio (float): Squeeze ratio in the SE Layer.
        activation_layer (Callable[..., nn.Module]): Activation function.
        norm_layer (Callable[..., nn.Module]): Normalization function.
        head_dim (int): Dimension of the attention heads.
        mlp_ratio (int): Ratio of the MLP layer.
        mlp_dropout (float): Dropout probability for the MLP layer.
        attention_dropout (float): Dropout probability for the attention layer.
        p_stochastic_dropout (float): Probability of stochastic depth.
        partition_size (int): Size of the partitions.
        input_grid_size (Tuple[int, int]): Size of the input feature grid.
        n_layers (int): Number of layers in the block.
        p_stochastic (List[float]): List of probabilities for stochastic depth for each layer.
    r<   r=   r?   r>   rA   .r@   rh   r®   r°   r¯   r«   Úinput_grid_sizeÚn_layersÚp_stochasticr   Nc                    s¬   t ƒ  ¡  t|ƒ|kstd|› d|› d�ƒ‚t ¡ | _t|dddd�| _t	|ƒD ]+\}}|dkr2dnd}|  jt
|dkr>|n||||||||||	|
|| j|d	�g7  _q(d S )
Nz'p_stochastic must have length n_layers=z, got p_stochastic=Ú.r&   r    r!   rD   r   )r<   r=   r?   r>   r   rA   r@   rh   r®   r°   r¯   r«   r­   rB   )rL   rM   Úlenro   r
   Ú
ModuleListrV   r$   r­   Ú	enumeraterÃ   )rW   r<   r=   r?   r>   rA   r@   rh   r®   r°   r¯   r«   rÇ   rÈ   rÉ   Úidxr    r   rY   r"   r#   rM   ù  s4   

ò
ÿþzMaxVitBlock.__init__r[   c                 C   s   | j D ]}||ƒ}q|S rÄ   rÅ   )rW   r[   Úlayerr"   r"   r#   r^   ,  s   

zMaxVitBlock.forward)r_   r`   ra   rb   rS   rc   r   r
   rd   r	   r   rM   r   r^   re   r"   r"   rY   r#   rÆ   ã  sD    ýüûúø	÷õôóòð
ïíìë3rÆ   c                !       s¸   e Zd ZdZdejddddddfdeeef ded	ed
ee dee dede	de
edejf  dedejf de	de	dede	de	deddf ‡ fdd„Zdedefdd„Zdd„ Z‡  ZS )r   ay  
    Implements MaxVit Transformer from the `MaxViT: Multi-Axis Vision Transformer <https://arxiv.org/abs/2204.01697>`_ paper.
    Args:
        input_size (Tuple[int, int]): Size of the input image.
        stem_channels (int): Number of channels in the stem.
        partition_size (int): Size of the partitions.
        block_channels (List[int]): Number of channels in each block.
        block_layers (List[int]): Number of layers in each block.
        stochastic_depth_prob (float): Probability of stochastic depth. Expands to a list of probabilities for each layer that scales linearly to the specified value.
        squeeze_ratio (float): Squeeze ratio in the SE Layer. Default: 0.25.
        expansion_ratio (float): Expansion ratio in the MBConv bottleneck. Default: 4.
        norm_layer (Callable[..., nn.Module]): Normalization function. Default: None (setting to None will produce a `BatchNorm2d(eps=1e-3, momentum=0.01)`).
        activation_layer (Callable[..., nn.Module]): Activation function Default: nn.GELU.
        head_dim (int): Dimension of the attention heads.
        mlp_ratio (int): Expansion ratio of the MLP layer. Default: 4.
        mlp_dropout (float): Dropout probability for the MLP layer. Default: 0.0.
        attention_dropout (float): Dropout probability for the attention layer. Default: 0.0.
        num_classes (int): Number of classes. Default: 1000.
    Ng      Ð?r„   r;   iè  r   Ústem_channelsr«   Úblock_channelsÚblock_layersrh   Ústochastic_depth_probrA   .r@   r?   r>   r®   r°   r¯   Únum_classesr   c                    sÒ  t ƒ  ¡  t| ƒ d}|d u rttjddd�}t|t|ƒƒ}t|ƒD ]%\}}|d | dks6|d | dkrGt	d|› d|› d	|› d
|› d�	ƒ‚q"t 
t||dd||	dd d�t||ddd d dd�¡| _t|dddd�}|| _t ¡ | _|g|d d…  }|}t d|t|ƒ¡ ¡ }d}t|||ƒD ]+\}}}| j t|||
|||	||||||||||| … d�¡ | jd j}||7 }q�t 
t d¡t ¡ t |d ¡t |d |d ¡t ¡ tj|d |dd�¡| _|  ¡  d S )Nr&   gü©ñÒMbP?g{®Gáz„?)ÚepsÚmomentumr   r!   zInput size z
 of block z$ is not divisible by partition size zx. Consider changing the partition size or the input size.
Current configuration yields the following block input sizes: rÊ   r    F)r   rA   r@   rC   rH   T)r   rA   r@   rC   rD   r.   )r<   r=   r?   r>   rA   r@   rh   r®   r°   r¯   r«   rÇ   rÈ   rÉ   )rC   ) rL   rM   r   r   r
   ÚBatchNorm2dr+   rË   rÍ   ro   rP   r   Ústemr$   r«   rÌ   ÚblocksÚnpÚlinspacer6   ÚtolistÚzipr(   rÆ   r­   ÚAdaptiveAvgPool2dÚFlattenr¼   rt   ÚTanhÚ
classifierÚ_init_weights)rW   r   rÐ   r«   rÑ   rÒ   rh   rÓ   rA   r@   r?   r>   r®   r°   r¯   rÔ   Úinput_channelsZblock_input_sizesrÎ   Zblock_input_sizer<   r=   rÉ   Zp_idxZ
in_channelZout_channelÚ
num_layersrY   r"   r#   rM   M  s„   
 þÿÿø
ÿõ
òÿ
ú	zMaxVit.__init__r[   c                 C   s,   |   |¡}| jD ]}||ƒ}q|  |¡}|S r™   )rØ   rÙ   rá   )rW   r[   Úblockr"   r"   r#   r^   Ã  s
   



zMaxVit.forwardc                 C   s®   |   ¡ D ]P}t|tjƒr"tjj|jdd� |jd ur!tj |j¡ qt|tj	ƒr9tj 
|jd¡ tj 
|jd¡ qt|tjƒrTtjj|jdd� |jd urTtj |j¡ qd S )Nrl   rm   r!   r   )ÚmodulesÚ
isinstancer
   rN   r~   Únormal_ÚweightrC   Úzeros_r×   Ú	constant_rt   )rW   Úmr"   r"   r#   râ   Ê  s   
€
€õzMaxVit._init_weights)r_   r`   ra   rb   r
   ÚGELUr	   rS   r   rc   r   r   rd   rM   r   r^   râ   re   r"   r"   rY   r#   r   8  sZ    %å
ýûù	÷
öôóïîìëéèçåävr   FrÐ   rÑ   rÒ   rÓ   r«   rh   ÚweightsÚprogressÚkwargsc              
   K   sš   |d ur(t |dt|jd ƒƒ |jd d |jd d ksJ ‚t |d|jd ƒ | dd¡}	td| ||||||	dœ|¤Ž}
|d urK|
 |j|d	d
�¡ |
S )NrÔ   Ú
categoriesÚmin_sizer   r!   r   ©éà   rô   )rÐ   rÑ   rÒ   rÓ   rh   r«   r   T)rï   Ú
check_hashr"   )r   rË   ÚmetaÚpopr   Úload_state_dictÚget_state_dict)rÐ   rÑ   rÒ   rÓ   r«   rh   rî   rï   rð   r   Úmodelr"   r"   r#   Ú_maxvitÙ  s&    ùørû   c                   @   sH   e Zd Zedeeddejd�edddddd	d
œiddddœd�Z	e	Z
dS )r   z9https://download.pytorch.org/models/maxvit_t-bc5ab103.pthrô   )Ú	crop_sizeÚresize_sizeÚinterpolationiÈË×ró   zLhttps://github.com/pytorch/vision/tree/main/references/classification#maxvitzImageNet-1KgÍÌÌÌÌìT@g‘í|?5.X@)zacc@1zacc@5g¬Zd;@gð§ÆK7±]@z½These weights reproduce closely the results of the paper using a similar training recipe.
            They were trained with a BatchNorm2D momentum of 0.99 instead of the more correct 0.01.)rñ   Ú
num_paramsrò   ÚrecipeÚ_metricsÚ_opsÚ
_file_sizeÚ_docs)ÚurlÚ
transformsrö   N)r_   r`   ra   r   r   r   r   ÚBICUBICr   ÚIMAGENET1K_V1ÚDEFAULTr"   r"   r"   r#   r     s*    
ÿþÿóúr   Ú
pretrained)rî   T)rî   rï   c                 K   s2   t  | ¡} td	dg d¢g d¢ddd| |dœ|¤ŽS )
aŠ  
    Constructs a maxvit_t architecture from
    `MaxViT: Multi-Axis Vision Transformer <https://arxiv.org/abs/2204.01697>`_.

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

    .. autoclass:: torchvision.models.MaxVit_T_Weights
        :members:
    é@   )r  é€   é   i   )r    r    r¡   r    é    gš™™™™™É?é   )rÐ   rÑ   rÒ   rh   rÓ   r«   rî   rï   Nr"   )r   Úverifyrû   )rî   rï   rð   r"   r"   r#   r     s   
ø	÷r   )NF)<rq   Úcollectionsr   Ú	functoolsr   Útypingr   r   r   r   r   r	   ÚnumpyrÚ   r/   Ztorch.nn.functionalr
   Ú
functionalr‰   r   Ztorchvision.models._apir   r   r   Ztorchvision.models._metar   Ztorchvision.models._utilsr   r   Ztorchvision.ops.miscr   r   Z torchvision.ops.stochastic_depthr   Ztorchvision.transforms._presetsr   r   Ztorchvision.utilsr   Ú__all__rS   r$   r+   r9   rd   r:   rf   r–   r›   r§   rª   rÃ   rÆ   r   rc   Úboolrû   r   r  r   r"   r"   r"   r#   Ú<module>   sp     .*
WIhaU .óþüûúø
öôóñ
ð*.