U
    ­Ê¹j#  ã                   @   s¸  d dl mZ d dlmZ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mZ dd
lmZmZmZmZmZ ddlmZ dddddgZG dd„ deƒZG dd„ dejƒZedddœZG dd„ deƒZG dd„ deƒZ ee!ee" edœdd„Z#e
ƒ edej$fdej%fd�d d!d d ej%d"œee e"ee! ee" ee eed#œd$d„ƒƒZ&e
ƒ ede j$fdej%fd�d d!d d ej%d"œee  e"ee! ee" ee eed#œd%d„ƒƒZ'd S )&é    )Úpartial)ÚAnyÚOptional)Únné   )ÚSemanticSegmentationé   )Úregister_modelÚWeightsÚWeightsEnum)Ú_VOC_CATEGORIES)Ú_ovewrite_value_paramÚhandle_legacy_interfaceÚIntermediateLayerGetter)ÚResNetÚ	resnet101ÚResNet101_WeightsÚresnet50ÚResNet50_Weightsé   )Ú_SimpleSegmentationModelÚFCNÚFCN_ResNet50_WeightsÚFCN_ResNet101_WeightsÚfcn_resnet50Úfcn_resnet101c                   @   s   e Zd ZdZdS )r   a‹  
    Implements FCN model from
    `"Fully Convolutional Networks for Semantic Segmentation"
    <https://arxiv.org/abs/1411.4038>`_.

    Args:
        backbone (nn.Module): the network used to compute the features for the model.
            The backbone should return an OrderedDict[Tensor], with the key being
            "out" for the last feature map used, and "aux" if an auxiliary classifier
            is used.
        classifier (nn.Module): module that takes the "out" element returned from
            the backbone and returns a dense prediction.
        aux_classifier (nn.Module, optional): auxiliary classifier used during training
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r    r    úb/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torchvision/models/segmentation/fcn.pyr      s   c                       s&   e Zd Zeeddœ‡ fdd„Z‡  ZS )ÚFCNHeadN)Úin_channelsÚchannelsÚreturnc              	      sP   |d }t j||dddd�t  |¡t  ¡ t  d¡t  ||d¡g}tƒ j|Ž  d S )Né   r   r   F)ÚpaddingZbiasgš™™™™™¹?)r   ZConv2dZBatchNorm2dZReLUZDropoutÚsuperÚ__init__)Úselfr#   r$   Zinter_channelsZlayers©Ú	__class__r    r!   r)   %   s    ûzFCNHead.__init__)r   r   r   Úintr)   Ú__classcell__r    r    r+   r!   r"   $   s   r"   )r   r   zŽ
        These weights were trained on a subset of COCO, using only the 20 categories that are present in the Pascal VOC
        dataset.
    )Ú
categoriesZmin_sizeZ_docsc                
   @   s@   e Zd Zedeedd�edddddd	œid
ddœ–d�ZeZdS )r   zBhttps://download.pytorch.org/models/fcn_resnet50_coco-1167a1af.pthé  ©Zresize_sizeijùzPhttps://github.com/pytorch/vision/tree/main/references/segmentation#fcn_resnet50úCOCO-val2017-VOC-labelsg     @N@gš™™™™ÙV@©ZmiouZ	pixel_accgmçû©ñc@g?5^ºIà`@©Z
num_paramsZrecipeZ_metricsZ_opsÚ
_file_size©ÚurlZ
transformsÚmetaN©	r   r   r   r
   r   r   Ú_COMMON_METAÚCOCO_WITH_VOC_LABELS_V1ÚDEFAULTr    r    r    r!   r   <   s    
þÿõýc                
   @   s@   e Zd Zedeedd�edddddd	œid
ddœ–d�ZeZdS )r   zChttps://download.pytorch.org/models/fcn_resnet101_coco-7ecb50ca.pthr0   r1   ijÅ<zWhttps://github.com/pytorch/vision/tree/main/references/segmentation#deeplabv3_resnet101r2   gš™™™™ÙO@gš™™™™ùV@r3   gV-²�m@g˜nƒÀöi@r4   r6   Nr9   r    r    r    r!   r   Q   s    
þÿõý)ÚbackboneÚnum_classesÚauxr%   c                 C   sH   ddi}|rd|d< t | |d�} |r.td|ƒnd }td|ƒ}t| ||ƒS )NZlayer4Úoutr?   Zlayer3)Úreturn_layersi   i   )r   r"   r   )r=   r>   r?   rA   Zaux_classifierÚ
classifierr    r    r!   Ú_fcn_resnetf   s    
rC   Z
pretrainedZpretrained_backbone)ÚweightsÚweights_backboneNT)rD   Úprogressr>   Úaux_lossrE   )rD   rF   r>   rG   rE   Úkwargsr%   c                 K   sŽ   t  | ¡} t |¡}| dk	rDd}td|t| jd ƒƒ}td|dƒ}n|dkrPd}t|dddgd�}t|||ƒ}| dk	rŠ| | j	|dd	�¡ |S )
a\  Fully-Convolutional Network model with a ResNet-50 backbone from the `Fully Convolutional
    Networks for Semantic Segmentation <https://arxiv.org/abs/1411.4038>`_ paper.

    .. betastatus:: segmentation module

    Args:
        weights (:class:`~torchvision.models.segmentation.FCN_ResNet50_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.segmentation.FCN_ResNet50_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.
        num_classes (int, optional): number of output classes of the model (including the background).
        aux_loss (bool, optional): If True, it uses an auxiliary loss.
        weights_backbone (:class:`~torchvision.models.ResNet50_Weights`, optional): The pretrained
            weights for the backbone.
        **kwargs: parameters passed to the ``torchvision.models.segmentation.fcn.FCN``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/segmentation/fcn.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.segmentation.FCN_ResNet50_Weights
        :members:
    Nr>   r/   rG   Té   F©rD   Zreplace_stride_with_dilation©rF   Z
check_hash)
r   Úverifyr   r   Úlenr8   r   rC   Úload_state_dictÚget_state_dict©rD   rF   r>   rG   rE   rH   r=   Úmodelr    r    r!   r   u   s    (

c                 K   sŽ   t  | ¡} t |¡}| dk	rDd}td|t| jd ƒƒ}td|dƒ}n|dkrPd}t|dddgd�}t|||ƒ}| dk	rŠ| | j	|dd	�¡ |S )
aa  Fully-Convolutional Network model with a ResNet-101 backbone from the `Fully Convolutional
    Networks for Semantic Segmentation <https://arxiv.org/abs/1411.4038>`_ paper.

    .. betastatus:: segmentation module

    Args:
        weights (:class:`~torchvision.models.segmentation.FCN_ResNet101_Weights`, optional): The
            pretrained weights to use. See
            :class:`~torchvision.models.segmentation.FCN_ResNet101_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.
        num_classes (int, optional): number of output classes of the model (including the background).
        aux_loss (bool, optional): If True, it uses an auxiliary loss.
        weights_backbone (:class:`~torchvision.models.ResNet101_Weights`, optional): The pretrained
            weights for the backbone.
        **kwargs: parameters passed to the ``torchvision.models.segmentation.fcn.FCN``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/segmentation/fcn.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.segmentation.FCN_ResNet101_Weights
        :members:
    Nr>   r/   rG   TrI   FrJ   rK   )
r   rL   r   r   rM   r8   r   rC   rN   rO   rP   r    r    r!   r   °   s    (

)(Ú	functoolsr   Útypingr   r   Ztorchr   Ztransforms._presetsr   Z_apir	   r
   r   Ú_metar   Z_utilsr   r   r   Zresnetr   r   r   r   r   r   Ú__all__r   Z
Sequentialr"   r:   r   r   r-   ÚboolrC   r;   ZIMAGENET1K_V1r   r   r    r    r    r!   Ú<module>   sx   ý
üþúø6þúø