a
    PSic"                     @   s~  d dl mZ d dlmZmZ d dlZd dlmZ d dlm  m	Z	 ddl
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 g dZG dd dejZG dd dejZeee eeedddZedddZG dd deZG dd deZedej fddddee eeeddd Z!edej fddddee eeedd!d"Z"dd#lm#Z# e#ej j$ej j$d$Z%dS )%    )partial)AnyOptionalN   )ImageClassification)_log_api_usage_once   )WeightsEnumWeights)_IMAGENET_CATEGORIES)handle_legacy_interface_ovewrite_named_param)
SqueezeNetSqueezeNet1_0_WeightsSqueezeNet1_1_Weightssqueezenet1_0squeezenet1_1c                       s>   e Zd Zeeeedd fddZejejdddZ  ZS )FireN)inplanessqueeze_planesexpand1x1_planesexpand3x3_planesreturnc                    sv   t    || _tj||dd| _tjdd| _tj||dd| _tjdd| _	tj||ddd| _
tjdd| _d S )Nr   kernel_sizeTinplace   )r   padding)super__init__r   nnConv2dsqueezeReLUsqueeze_activation	expand1x1expand1x1_activation	expand3x3expand3x3_activation)selfr   r   r   r   	__class__ Y/var/www/html/django/DPS/env/lib/python3.9/site-packages/torchvision/models/squeezenet.pyr       s    
zFire.__init__xr   c                 C   s8   |  | |}t| | || | |gdS Nr   )r%   r#   torchcatr'   r&   r)   r(   r*   r0   r-   r-   r.   forward   s     zFire.forward)	__name__
__module____qualname__intr    r2   Tensorr5   __classcell__r-   r-   r+   r.   r      s   
r   c                       s>   e Zd Zdeeedd fddZejejdd	d
Z	  Z
S )r   1_0        ?N)versionnum_classesdropoutr   c                    s:  t    t|  || _|dkrttjdddddtjddtjdddd	t	dd
ddt	dd
ddt	ddddtjdddd	t	ddddt	ddddt	ddddt	ddddtjdddd	t	dddd| _
n|dkrttjdddddtjddtjdddd	t	dd
ddt	dd
ddtjdddd	t	ddddt	ddddtjdddd	t	ddddt	ddddt	ddddt	dddd| _
ntd| dtjd| jdd}ttj|d|tjddtd| _|  D ]X}t|tjr||u rtj|jddd nt|j |jd urt|jd qd S )Nr<   r   `      r   )r   strideTr   )r   rD   	ceil_mode   @             0      i  i   1_1zUnsupported SqueezeNet version z: 1_0 or 1_1 expectedr   r   )p)r   r   g        g{Gz?)meanstdr   )r   r    r   r@   r!   
Sequentialr"   r$   	MaxPool2dr   features
ValueErrorDropoutAdaptiveAvgPool2d
classifiermodules
isinstanceinitnormal_weightkaiming_uniform_bias	constant_)r*   r?   r@   rA   Z
final_convmr+   r-   r.   r    %   s^    




zSqueezeNet.__init__r/   c                 C   s    |  |}| |}t|dS r1   )rS   rW   r2   flattenr4   r-   r-   r.   r5   ^   s    

zSqueezeNet.forward)r<   r=   r>   )r6   r7   r8   strr9   floatr    r2   r:   r5   r;   r-   r-   r+   r.   r   $   s   9r   )r?   weightsprogresskwargsr   c                 K   sL   |d urt |dt|jd  t| fi |}|d urH||j|d |S )Nr@   
categories)re   )r   lenmetar   load_state_dictget_state_dict)r?   rd   re   rf   modelr-   r-   r.   _squeezenetd   s    rm   z@https://github.com/pytorch/vision/pull/49#issuecomment-277560717zXThese weights reproduce closely the results of the paper using a simple training recipe.)rg   recipe_docsc                
   @   s@   e Zd Zedeeddi edddddd	id
dZeZdS )r   z>https://download.pytorch.org/models/squeezenet1_0-b66bff10.pth   	crop_size)   rs   i ImageNet-1KgM@g{GT@zacc@1zacc@5min_size
num_params_metricsurl
transformsri   N	r6   r7   r8   r
   r   r   _COMMON_METAIMAGENET1K_V1DEFAULTr-   r-   r-   r.   r   |   s    
r   c                
   @   s@   e Zd Zedeeddi edddddd	id
dZeZdS )r   z>https://download.pytorch.org/models/squeezenet1_1-b8a52dc0.pthrp   rq   )   r   i( rt   gX9M@g-'T@ru   rv   rz   Nr}   r-   r-   r-   r.   r      s    
r   
pretrained)rd   T)rd   re   )rd   re   rf   r   c                 K   s   t | } td| |fi |S )a  SqueezeNet model architecture from the `SqueezeNet: AlexNet-level
    accuracy with 50x fewer parameters and <0.5MB model size
    <https://arxiv.org/abs/1602.07360>`_ paper.

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

    .. autoclass:: torchvision.models.SqueezeNet1_0_Weights
        :members:
    r<   )r   verifyrm   rd   re   rf   r-   r-   r.   r      s    
r   c                 K   s   t | } td| |fi |S )a/  SqueezeNet 1.1 model from the `official SqueezeNet repo
    <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>`_.

    SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters
    than SqueezeNet 1.0, without sacrificing accuracy.

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

    .. autoclass:: torchvision.models.SqueezeNet1_1_Weights
        :members:
    rM   )r   r   rm   r   r-   r-   r.   r      s    
r   )
_ModelURLs)r   r   )&	functoolsr   typingr   r   r2   torch.nnr!   Ztorch.nn.initrZ   Ztransforms._presetsr   utilsr   _apir	   r
   _metar   _utilsr   r   __all__Moduler   r   rb   boolrm   r~   r   r   r   r   r   r   r{   
model_urlsr-   r-   r-   r.   <module>   sT   A

