3
Á3W^I  ã               @   s‚   d dl Z d dljZd dljjZddlmZ dddgZddd	œZG d
d„ dej	ƒZ
G dd„ dej	ƒZdd„ Zddd„Zddd„ZdS )é    Né   )Úload_state_dict_from_urlÚ
SqueezeNetÚsqueezenet1_0Úsqueezenet1_1z>https://download.pytorch.org/models/squeezenet1_0-a815701f.pthz>https://download.pytorch.org/models/squeezenet1_1-f364aa15.pth)r   r   c                   s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚFirec                sz   t t| ƒjƒ  || _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)Úsuperr   Ú__init__ÚinplanesÚnnÚConv2dÚsqueezeÚReLUÚsqueeze_activationÚ	expand1x1Úexpand1x1_activationÚ	expand3x3Úexpand3x3_activation)Úselfr   Zsqueeze_planesZexpand1x1_planesZexpand3x3_planes)Ú	__class__© úD/tmp/pip-build-7wfi2gtz/torchvision/torchvision/models/squeezenet.pyr      s    
zFire.__init__c             C   s8   | j | j|ƒƒ}tj| j| j|ƒƒ| j| j|ƒƒgdƒS )Nr   )r   r   ÚtorchÚcatr   r   r   r   )r   Úxr   r   r   Úforward   s
    zFire.forward)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r   r   )r   r   r      s   r   c                   s&   e Zd Zd‡ fdd„	Zdd„ Z‡  ZS )r   Ú1_0éè  c                s:  t t| ƒjƒ  || _|dkrÌtj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�r†tj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j|d�ƒ‚tjd| jdd�}tjtjdd�|tjdd�tjdƒƒ| _xd| jƒ D ]X}t|tjƒ�rÚ||k�r
tj|jddd� ntj|jƒ |jd k	�rÚtj|jdƒ �qÚW d S )Nr$   r
   é`   é   é   )r   ÚstrideT)r	   )r   r)   Z	ceil_modeé   é@   é€   é    é   é0   éÀ   i€  i   Ú1_1z<Unsupported SqueezeNet version {version}:1_0 or 1_1 expected)Úversionr   )r   g      à?)Úpg        g{®Gáz„?)ZmeanZstdr   )r   r   )r   r   r   Únum_classesr   Z
Sequentialr   r   Z	MaxPool2dr   ÚfeaturesÚ
ValueErrorÚformatZDropoutZAdaptiveAvgPool2dÚ
classifierÚmodulesÚ
isinstanceÚinitZnormal_ZweightZkaiming_uniform_ZbiasZ	constant_)r   r2   r4   Z
final_convÚm)r   r   r   r   '   s^    






zSqueezeNet.__init__c             C   s    | j |ƒ}| j|ƒ}tj|dƒS )Nr   )r5   r8   r   Úflatten)r   r   r   r   r   r   c   s    

zSqueezeNet.forward)r$   r%   )r    r!   r"   r   r   r#   r   r   )r   r   r   %   s   <c             K   s6   t | f|Ž}|r2d|  }tt| |d�}|j|ƒ |S )NZ
squeezenet)Úprogress)r   r   Ú
model_urlsZload_state_dict)r2   Ú
pretrainedr>   ÚkwargsÚmodelÚarchZ
state_dictr   r   r   Ú_squeezeneti   s    
rD   FTc             K   s   t d| |f|Ž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:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
        progress (bool): If True, displays a progress bar of the download to stderr
    r$   )rD   )r@   r>   rA   r   r   r   r   s   s    	c             K   s   t d| |f|Ž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:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
        progress (bool): If True, displays a progress bar of the download to stderr
    r1   )rD   )r@   r>   rA   r   r   r   r      s    
)FT)FT)r   Ztorch.nnr   Ztorch.nn.initr;   Úutilsr   Ú__all__r?   ÚModuler   r   rD   r   r   r   r   r   r   Ú<module>   s   

D

