U
    h                     @   s  d dl Z d dlmZ d dlmZmZmZm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 ddlmZ ddlmZ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ddddddddddgZ!ejejdddZ"ej#$d ejejee% ejddd Z&ej#$d  G d!d" d"e
j'Z(G d#d$ d$e
j'Z)dGeeeeee% e%ee% e*e*ee ee eej e+ed'd(d)Z,ej#$d) G d*d+ d+e
j'Z-G d,d- d-e-Z.G d.d/ d/e
j'Z/G d0d1 d1e/Z0G d2d de
j'Z1ee% e%ee% ee% ee% e*ee e+ee1d3
d4d5Z2d6eiZ3G d7d deZ4G d8d deZ5G d9d deZ6G d:d deZ7G d;d deZ8G d<d deZ9e e d=e4j:fd>dd&d?ee4 e+ee1d@dAdZ;e e d=e5j:fd>dd&d?ee5 e+ee1d@dBdZ<e e d=e6j:fd>dd&d?ee6 e+ee1d@dCdZ=e e d=e7j:fd>dd&d?ee7 e+ee1d@dDdZ>e e d=e8j:fd>dd&d?ee8 e+ee1d@dEdZ?e e d=e9j:fd>dd&d?ee9 e+ee1d@dFdZ@dS )H    N)partial)AnyCallableListOptional)nnTensor   )MLPPermute)StochasticDepth)ImageClassificationInterpolationMode)_log_api_usage_once   )register_modelWeightsWeightsEnum)_IMAGENET_CATEGORIES)_ovewrite_named_paramhandle_legacy_interfaceSwinTransformerSwin_T_WeightsSwin_S_WeightsSwin_B_WeightsSwin_V2_T_WeightsSwin_V2_S_WeightsSwin_V2_B_Weightsswin_tswin_sswin_b	swin_v2_t	swin_v2_s	swin_v2_bxreturnc              
   C   s   | j dd  \}}}t| ddd|d d|d f} | ddd ddd dd d f }| ddd ddd dd d f }| ddd ddd dd d f }| ddd ddd dd d f }t||||gd} | S )Nr   r	   .r   )shapeFpadtorchcat)r%   HW_Zx0x1Zx2Zx3 r2   U/var/www/html/venv/lib/python3.8/site-packages/torchvision/models/swin_transformer.py_patch_merging_pad#   s         r4   )relative_position_bias_tablerelative_position_indexwindow_sizer&   c                 C   sB   |d |d  }| | }| ||d}|ddd d}|S )Nr   r   r(   r	   )viewpermute
contiguous	unsqueeze)r5   r6   r7   Nrelative_position_biasr2   r2   r3   _get_relative_position_bias1   s
    r>   c                       sF   e Zd ZdZejfeedejf d fddZ	e
dddZ  ZS )	PatchMergingzPatch Merging Layer.
    Args:
        dim (int): Number of input channels.
        norm_layer (nn.Module): Normalization layer. Default: nn.LayerNorm.
    .dim
norm_layerc                    sD   t    t|  || _tjd| d| dd| _|d| | _d S N   r	   Fbiassuper__init__r   rA   r   Linear	reductionnormselfrA   rB   	__class__r2   r3   rI   E   s
    
zPatchMerging.__init__r%   c                 C   s    t |}| |}| |}|S z
        Args:
            x (Tensor): input tensor with expected layout of [..., H, W, C]
        Returns:
            Tensor with layout of [..., H/2, W/2, 2*C]
        )r4   rL   rK   rN   r%   r2   r2   r3   forwardL   s    

zPatchMerging.forward__name__
__module____qualname____doc__r   	LayerNormintr   ModulerI   r   rT   __classcell__r2   r2   rO   r3   r?   >   s   $r?   c                       sF   e Zd ZdZejfeedejf d fddZ	e
dddZ  ZS )	PatchMergingV2zPatch Merging Layer for Swin Transformer V2.
    Args:
        dim (int): Number of input channels.
        norm_layer (nn.Module): Normalization layer. Default: nn.LayerNorm.
    .r@   c                    sD   t    t|  || _tjd| d| dd| _|d| | _d S rC   rG   rM   rO   r2   r3   rI   `   s
    
zPatchMergingV2.__init__rQ   c                 C   s    t |}| |}| |}|S rR   )r4   rK   rL   rS   r2   r2   r3   rT   g   s    

zPatchMergingV2.forwardrU   r2   r2   rO   r3   r^   Y   s   $r^           T)input
qkv_weightproj_weightr=   r7   	num_heads
shift_sizeattention_dropoutdropoutqkv_bias	proj_biaslogit_scaletrainingr&   c           $   	   C   s  | j \}}}}|d ||d   |d  }|d ||d   |d  }t| ddd|d|f}|j \}}}}| }|d |krd|d< |d |krd|d< t|dkrtj||d  |d  fdd}||d  ||d   }||||d  |d ||d  |d |}|dddddd	|| |d |d  |}|d	k	rv|	d	k	rv|	
 }	|	 d }|	|d|    t|||	}|	|d|dd||| ddddd}|d |d |d   }}}|d	k	r tj|d
dtj|d
ddd
 }tj|tdd }|| }n"||| d  }||dd
}|| }t|dkr|||f}d|d  f|d  |d  f|d  d	ff}d|d  f|d  |d  f|d  d	ff} d}!|D ]>}"| D ]2}#|!||"d |"d |#d |#d f< |!d7 }!qҐq|||d  |d ||d  |d }|dddd	||d |d  }|d|d }||dktd|dktd}||d| |||d|d}||dd }|d
||d|d}tj|d
d}tj|||d}||dd	|d|d|}t|||
}tj|||d}||||d  ||d  |d |d |}|dddddd	||||}t|dkrtj||d |d fdd}|d	d	d	|d	|d	d	f  }|S )a  
    Window based multi-head self attention (W-MSA) module with relative position bias.
    It supports both of shifted and non-shifted window.
    Args:
        input (Tensor[N, H, W, C]): The input tensor or 4-dimensions.
        qkv_weight (Tensor[in_dim, out_dim]): The weight tensor of query, key, value.
        proj_weight (Tensor[out_dim, out_dim]): The weight tensor of projection.
        relative_position_bias (Tensor): The learned relative position bias added to attention.
        window_size (List[int]): Window size.
        num_heads (int): Number of attention heads.
        shift_size (List[int]): Shift size for shifted window attention.
        attention_dropout (float): Dropout ratio of attention weight. Default: 0.0.
        dropout (float): Dropout ratio of output. Default: 0.0.
        qkv_bias (Tensor[out_dim], optional): The bias tensor of query, key, value. Default: None.
        proj_bias (Tensor[out_dim], optional): The bias tensor of projection. Default: None.
        logit_scale (Tensor[out_dim], optional): Logit scale of cosine attention for Swin Transformer V2. Default: None.
        training (bool, optional): Training flag used by the dropout parameters. Default: True.
    Returns:
        Tensor[N, H, W, C]: The output tensor after shifted window attention.
    r   r   )r   r	   )ZshiftsZdims   r	   rD      Nr(   )rA   g      Y@)maxg      g      Yr_   )prj   )r)   r*   r+   copysumr,   Zrollr8   r9   Zreshapeclonenumelzero_Zlinearsize	normalizeZ	transposeclampmathlogexpmatmulZ	new_zerosr;   Zmasked_fillfloatZsoftmaxrf   r:   )$r`   ra   rb   r=   r7   rc   rd   re   rf   rg   rh   ri   rj   Br.   r/   CZpad_rZpad_br%   r0   Zpad_HZpad_WZnum_windowslengthqkvqkvattnZ	attn_maskZh_slicesZw_slicescounthwr2   r2   r3   shifted_window_attentiont   sp    # ,.0
$
..$($$((, $r   c                
       sn   e Zd ZdZdeee ee eeeeed fddZdd Z	d	d
 Z
ejdddZeedddZ  ZS )ShiftedWindowAttentionz/
    See :func:`shifted_window_attention`.
    Tr_   rA   r7   rd   rc   rg   rh   re   rf   c	           	         s   t    t|dks"t|dkr*td|| _|| _|| _|| _|| _t	j
||d |d| _t	j
|||d| _|   |   d S )Nr	   z.window_size and shift_size must be of length 2rk   rE   )rH   rI   len
ValueErrorr7   rd   rc   re   rf   r   rJ   r   proj#define_relative_position_bias_tabledefine_relative_position_index)	rN   rA   r7   rd   rc   rg   rh   re   rf   rO   r2   r3   rI      s    
zShiftedWindowAttention.__init__c                 C   sL   t td| jd  d d| jd  d  | j| _t jj| jdd d S )Nr	   r   r   {Gz?Zstd)	r   	Parameterr,   Zzerosr7   rc   r5   inittrunc_normal_rN   r2   r2   r3   r   	  s    ,z:ShiftedWindowAttention.define_relative_position_bias_tablec                 C   s  t | jd }t | jd }t t j||dd}t |d}|d d d d d f |d d d d d f  }|ddd }|d d d d df  | jd d 7  < |d d d d df  | jd d 7  < |d d d d df  d| jd  d 9  < |d }| 	d| d S )Nr   r   ijZindexingr	   r(   r6   )
r,   aranger7   stackmeshgridflattenr9   r:   rq   register_buffer)rN   Zcoords_hZcoords_wZcoordsZcoords_flattenZrelative_coordsr6   r2   r2   r3   r     s    ,((,z5ShiftedWindowAttention.define_relative_position_indexr&   c                 C   s   t | j| j| jS N)r>   r5   r6   r7   r   r2   r2   r3   get_relative_position_bias  s
      z1ShiftedWindowAttention.get_relative_position_biasr$   c                 C   sD   |   }t|| jj| jj|| j| j| j| j| j	| jj
| jj
| jdS )
        Args:
            x (Tensor): Tensor with layout of [B, H, W, C]
        Returns:
            Tensor with same layout as input, i.e. [B, H, W, C]
        )rd   re   rf   rg   rh   rj   )r   r   r   weightr   r7   rc   rd   re   rf   rF   rj   rN   r%   r=   r2   r2   r3   rT   #  s    zShiftedWindowAttention.forward)TTr_   r_   )rV   rW   rX   rY   r[   r   boolr|   rI   r   r   r,   r   r   rT   r]   r2   r2   rO   r3   r      s&   
    r   c                
       sd   e Zd ZdZdeee ee eeeeed fddZdd Z	e
jd	d
dZedddZ  ZS )ShiftedWindowAttentionV2z2
    See :func:`shifted_window_attention_v2`.
    Tr_   r   c	           
   
      s   t  j||||||||d ttdt|ddf | _ttj	ddddtj
ddtj	d|d	d| _|r| jj d
 }	| jj|	d|	  j  d S )N)rg   rh   re   rf   
   r   r	   i   TrE   )inplaceFrk   )rH   rI   r   r   r,   ry   Zonesri   
SequentialrJ   ZReLUcpb_mlpr   rF   rs   datart   )
rN   rA   r7   rd   rc   rg   rh   re   rf   r   rO   r2   r3   rI   @  s&    " 
 z!ShiftedWindowAttentionV2.__init__c                 C   s  t j| jd d  | jd t jd}t j| jd d  | jd t jd}t t j||gdd}|ddd d}|d d d d d d df  | jd d   < |d d d d d d df  | jd d   < |d9 }t 	|t 
t |d  d	 }| d
| d S )Nr   r   )Zdtyper   r   r	      g      ?g      @relative_coords_table)r,   r   r7   Zfloat32r   r   r9   r:   r;   signlog2absr   )rN   Zrelative_coords_hZrelative_coords_wr   r2   r2   r3   r   _  s    $$.. z<ShiftedWindowAttentionV2.define_relative_position_bias_tabler   c                 C   s4   t | | jd| j| j| j}dt| }|S )Nr(      )	r>   r   r   r8   rc   r6   r7   r,   Zsigmoid)rN   r=   r2   r2   r3   r   o  s    z3ShiftedWindowAttentionV2.get_relative_position_biasrQ   c                 C   sH   |   }t|| jj| jj|| j| j| j| j| j	| jj
| jj
| j| jdS )r   )rd   re   rf   rg   rh   ri   rj   )r   r   r   r   r   r7   rc   rd   re   rf   rF   ri   rj   r   r2   r2   r3   rT   x  s     z ShiftedWindowAttentionV2.forward)TTr_   r_   )rV   rW   rX   rY   r[   r   r   r|   rI   r   r,   r   r   rT   r]   r2   r2   rO   r3   r   ;  s$   
    	r   c                       sr   e Zd ZdZddddejefeeee ee e	e	e	e	e
dejf e
dejf d
 fddZedd	d
Z  ZS )SwinTransformerBlocka  
    Swin Transformer Block.
    Args:
        dim (int): Number of input channels.
        num_heads (int): Number of attention heads.
        window_size (List[int]): Window size.
        shift_size (List[int]): Shift size for shifted window attention.
        mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.0.
        dropout (float): Dropout rate. Default: 0.0.
        attention_dropout (float): Attention dropout rate. Default: 0.0.
        stochastic_depth_prob: (float): Stochastic depth rate. Default: 0.0.
        norm_layer (nn.Module): Normalization layer.  Default: nn.LayerNorm.
        attn_layer (nn.Module): Attention layer. Default: ShiftedWindowAttention
          @r_   .
rA   rc   r7   rd   	mlp_ratiorf   re   stochastic_depth_probrB   
attn_layerc                    s   t    t|  |	|| _|
||||||d| _t|d| _|	|| _t|t	|| |gt
jd |d| _| j D ]:}t|t
jrtt
j|j |jd k	rtt
jj|jdd qtd S )N)re   rf   row)Zactivation_layerr   rf   gư>r   )rH   rI   r   norm1r   r   stochastic_depthnorm2r
   r[   r   ZGELUmlpmodules
isinstancerJ   r   Zxavier_uniform_r   rF   Znormal_)rN   rA   rc   r7   rd   r   rf   re   r   rB   r   mrO   r2   r3   rI     s&    


"
zSwinTransformerBlock.__init__rQ   c                 C   s8   ||  | | | }||  | | | }|S r   )r   r   r   r   r   rS   r2   r2   r3   rT     s    zSwinTransformerBlock.forward)rV   rW   rX   rY   r   rZ   r   r[   r   r|   r   r\   rI   r   rT   r]   r2   r2   rO   r3   r     s(   #r   c                       sr   e Zd ZdZddddejefeeee ee e	e	e	e	e
dejf e
dejf d
 fddZedd	d
Z  ZS )SwinTransformerBlockV2a  
    Swin Transformer V2 Block.
    Args:
        dim (int): Number of input channels.
        num_heads (int): Number of attention heads.
        window_size (List[int]): Window size.
        shift_size (List[int]): Shift size for shifted window attention.
        mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.0.
        dropout (float): Dropout rate. Default: 0.0.
        attention_dropout (float): Attention dropout rate. Default: 0.0.
        stochastic_depth_prob: (float): Stochastic depth rate. Default: 0.0.
        norm_layer (nn.Module): Normalization layer.  Default: nn.LayerNorm.
        attn_layer (nn.Module): Attention layer. Default: ShiftedWindowAttentionV2.
    r   r_   .r   c                    s$   t  j|||||||||	|
d
 d S )N)r   rf   re   r   rB   r   )rH   rI   )rN   rA   rc   r7   rd   r   rf   re   r   rB   r   rO   r2   r3   rI     s    zSwinTransformerBlockV2.__init__rQ   c                 C   s8   ||  | | | }||  | | | }|S r   )r   r   r   r   r   rS   r2   r2   r3   rT     s    zSwinTransformerBlockV2.forward)rV   rW   rX   rY   r   rZ   r   r[   r   r|   r   r\   rI   r   rT   r]   r2   r2   rO   r3   r     s(   r   c                       s   e Zd ZdZdddddddefee eee ee ee eeeeeee	de
jf  ee	de
jf  e	de
jf d fd	d
Zdd Z  ZS )r   a;  
    Implements Swin Transformer from the `"Swin Transformer: Hierarchical Vision Transformer using
    Shifted Windows" <https://arxiv.org/abs/2103.14030>`_ paper.
    Args:
        patch_size (List[int]): Patch size.
        embed_dim (int): Patch embedding dimension.
        depths (List(int)): Depth of each Swin Transformer layer.
        num_heads (List(int)): Number of attention heads in different layers.
        window_size (List[int]): Window size.
        mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.0.
        dropout (float): Dropout rate. Default: 0.0.
        attention_dropout (float): Attention dropout rate. Default: 0.0.
        stochastic_depth_prob (float): Stochastic depth rate. Default: 0.1.
        num_classes (int): Number of classes for classification head. Default: 1000.
        block (nn.Module, optional): SwinTransformer Block. Default: None.
        norm_layer (nn.Module, optional): Normalization layer. Default: None.
        downsample_layer (nn.Module): Downsample layer (patch merging). Default: PatchMerging.
    r   r_   g?i  N.)
patch_size	embed_dimdepthsrc   r7   r   rf   re   r   num_classesrB   blockdownsample_layerc                    s  t    t|  |
| _|d kr$t}|d kr:ttjdd}g }|t	tj
d||d |d f|d |d fdtddddg|| t|}d}tt|D ]}g }|d|  }t|| D ]R |	t| |d  }||||| | fdd	|D |||||d
	 |d7 }q|tj	|  |t|d k r|||| qtj	| | _|dt|d   }||| _tddddg| _td| _td| _t||
| _|  D ]@}t|tjrtjj|jdd |jd k	rtj|j qd S )Ngh㈵>)epsrk   r   r   )Zkernel_sizeZstrider	   c                    s$   g | ]} d  dkrdn|d  qS )r	   r   r2   ).0r   Zi_layerr2   r3   
<listcomp>C  s     z,SwinTransformer.__init__.<locals>.<listcomp>)r7   rd   r   rf   re   r   rB   r   r   ) rH   rI   r   r   r   r   r   rZ   appendr   ZConv2dr   rq   ranger   r|   featuresrL   r9   ZAdaptiveAvgPool2davgpoolZFlattenr   rJ   headr   r   r   r   r   rF   Zzeros_)rN   r   r   r   rc   r7   r   rf   re   r   r   rB   r   r   ZlayersZtotal_stage_blocksZstage_block_idZi_stageZstagerA   Zsd_probZnum_featuresr   rO   r   r3   rI     sp    
   


zSwinTransformer.__init__c                 C   s@   |  |}| |}| |}| |}| |}| |}|S r   )r   rL   r9   r   r   r   rS   r2   r2   r3   rT   _  s    





zSwinTransformer.forward)rV   rW   rX   rY   r?   r   r[   r|   r   r   r   r\   rI   rT   r]   r2   r2   rO   r3   r     s2   O)
r   r   r   rc   r7   r   weightsprogresskwargsr&   c           
   	   K   sZ   |d k	rt |dt|jd  tf | |||||d|}	|d k	rV|	|j|dd |	S )Nr   
categories)r   r   r   rc   r7   r   T)r   Z
check_hash)r   r   metar   Zload_state_dictZget_state_dict)
r   r   r   rc   r7   r   r   r   r   modelr2   r2   r3   _swin_transformeri  s    
r   r   c                   @   sJ   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   z7https://download.pytorch.org/models/swin_t-704ceda3.pth      Z	crop_sizeZresize_sizeinterpolationibr   r   Uhttps://github.com/pytorch/vision/tree/main/references/classification#swintransformerImageNet-1KguV^T@glW@zacc@1zacc@5gX9@g\([@YThese weights reproduce closely the results of the paper using a similar training recipe.Z
num_paramsZmin_sizeZrecipeZ_metricsZ_ops
_file_sizeZ_docsurlZ
transformsr   NrV   rW   rX   r   r   r   r   ZBICUBIC_COMMON_METAIMAGENET1K_V1DEFAULTr2   r2   r2   r3   r     s.      c                   @   sJ   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   z7https://download.pytorch.org/models/swin_s-5e29d889.pthr      r   irr   r   r   gCT@gףp=
X@r   gZd{!@gx&g@r   r   r   Nr   r2   r2   r2   r3   r     s.      c                   @   sJ   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   z7https://download.pytorch.org/models/swin_b-68c6b09e.pthr      r   i<;r   r   r   gh|?T@g)\(X@r   g&1.@gt@r   r   r   Nr   r2   r2   r2   r3   r     s.      c                   @   sJ   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   z:https://download.pytorch.org/models/swin_v2_t-b137f0e2.pth     r   iRr   r   Xhttps://github.com/pytorch/vision/tree/main/references/classification#swintransformer-v2r   gS㥛T@g rX@r   g(\@gMb([@r   r   r   Nr   r2   r2   r2   r3   r     s.      c                   @   sJ   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   z:https://download.pytorch.org/models/swin_v2_s-637d8ceb.pthr   r   r   ir   r   r   g!rhT@gNbX94X@r   gd;O'@gg@r   r   r   Nr   r2   r2   r2   r3   r     s.      c                   @   sJ   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   z:https://download.pytorch.org/models/swin_v2_b-781e5279.pthr   i  r   i=r   r   r   gI+U@gK7X@r   g33333S4@gˡEu@r   r   r   Nr   r2   r2   r2   r3   r   	  s.      Z
pretrained)r   )r   r   )r   r   r   r&   c                 K   sB   t | } tf ddgdddddgddddgddgd	| |d
|S )a  
    Constructs a swin_tiny architecture from
    `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows <https://arxiv.org/abs/2103.14030>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_T_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_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.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_T_Weights
        :members:
    rD   `   r	      rk            皙?r   r   r   rc   r7   r   r   r   )r   verifyr   r   r   r   r2   r2   r3   r   "  s    


	c                 K   sB   t | } tf ddgdddddgddddgd	d	gd
| |d|S )a  
    Constructs a swin_small architecture from
    `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows <https://arxiv.org/abs/2103.14030>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_S_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_S_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.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_S_Weights
        :members:
    rD   r   r	      rk   r   r   r   r   333333?r   )r   r   r   r   r2   r2   r3   r   H  s    


	c                 K   sB   t | } tf ddgdddddgddddgddgd	| |d
|S )a  
    Constructs a swin_base architecture from
    `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows <https://arxiv.org/abs/2103.14030>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_B_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_B_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.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_B_Weights
        :members:
    rD      r	   r   r   r       r         ?r   )r   r   r   r   r2   r2   r3   r    n  s    


	c                 K   sF   t | } tf ddgdddddgddddgddgd	| |ttd

|S )a  
    Constructs a swin_v2_tiny architecture from
    `Swin Transformer V2: Scaling Up Capacity and Resolution <https://arxiv.org/abs/2111.09883>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_V2_T_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_V2_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.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_V2_T_Weights
        :members:
    rD   r   r	   r   rk   r   r   r   r   
r   r   r   rc   r7   r   r   r   r   r   )r   r   r   r   r^   r   r2   r2   r3   r!     s    


c                 K   sF   t | } tf ddgdddddgddddgd	d	gd
| |ttd
|S )a  
    Constructs a swin_v2_small architecture from
    `Swin Transformer V2: Scaling Up Capacity and Resolution <https://arxiv.org/abs/2111.09883>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_V2_S_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_V2_S_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.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_V2_S_Weights
        :members:
    rD   r   r	   r   rk   r   r   r   r   r   r   )r   r   r   r   r^   r   r2   r2   r3   r"     s    


c                 K   sF   t | } tf ddgdddddgddddgddgd| |ttd	
|S )
a  
    Constructs a swin_v2_base architecture from
    `Swin Transformer V2: Scaling Up Capacity and Resolution <https://arxiv.org/abs/2111.09883>`_.

    Args:
        weights (:class:`~torchvision.models.Swin_V2_B_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.Swin_V2_B_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.swin_transformer.SwinTransformer``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.Swin_V2_B_Weights
        :members:
    rD   r   r	   r   r   r   r   r   r   )r   r   r   r   r^   r   r2   r2   r3   r#     s    


)r_   r_   NNNT)Arx   	functoolsr   typingr   r   r   r   r,   Ztorch.nn.functionalr   Z
functionalr*   r   Zops.miscr
   r   Zops.stochastic_depthr   Ztransforms._presetsr   r   utilsr   Z_apir   r   r   _metar   Z_utilsr   r   __all__r4   Zfxwrapr[   r>   r\   r?   r^   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r2   r2   r2   r3   <module>   s     
#      sQV92n $$$$$$$&$&