a
    PSicB#                  
   @   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 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 g d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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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d'lm'Z' e'ej#j(ej#j(d(Z)dS ))    )partial)AnyOptional)nn   )SemanticSegmentation   )WeightsEnumWeights)_VOC_CATEGORIES)IntermediateLayerGetterhandle_legacy_interface_ovewrite_value_param)ResNetResNet50_WeightsResNet101_Weightsresnet50	resnet101   )_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   _/var/www/html/django/DPS/env/lib/python3.9/site-packages/torchvision/models/segmentation/fcn.pyr      s   r   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)paddingbiasg?)r   Conv2dBatchNorm2dReLUDropoutsuper__init__)selfr"   r#   Zinter_channelslayers	__class__r   r    r-   %   s    zFCNHead.__init__)r   r   r   intr-   __classcell__r   r   r0   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.
    )
categoriesmin_size_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   zBhttps://download.pytorch.org/models/fcn_resnet50_coco-1167a1af.pth  resize_sizeijzPhttps://github.com/pytorch/vision/tree/main/references/segmentation#fcn_resnet50COCO-val2017-VOC-labelsg     @N@gV@miou	pixel_acc
num_paramsrecipe_metricsurl
transformsmetaN	r   r   r   r
   r   r   _COMMON_METACOCO_WITH_VOC_LABELS_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   zChttps://download.pytorch.org/models/fcn_resnet101_coco-7ecb50ca.pthr7   r8   ij<zWhttps://github.com/pytorch/vision/tree/main/references/segmentation#deeplabv3_resnet101r:   gO@gV@r;   r>   rB   NrF   r   r   r   r    r   O   s    
r   )backbonenum_classesauxr$   c                 C   sH   ddi}|rd|d< t | |d} |r.td|nd }td|}t| ||S )Nlayer4outrL   layer3)return_layersi   i   )r   r!   r   )rJ   rK   rL   rP   aux_classifier
classifierr   r   r    _fcn_resnetb   s    
rS   
pretrainedpretrained_backbone)weightsweights_backboneNT)rV   progressrK   aux_lossrW   )rV   rX   rK   rY   rW   kwargsr$   c                 K   s   t | } t|}| dur@d}t|t| jd }t|d}n|du rLd}t|g dd}t|||}| dur|| j	|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:
    Nr4   T   FTTrV   replace_stride_with_dilationrX   )
r   verifyr   r   lenrE   r   rS   load_state_dictget_state_dictrV   rX   rK   rY   rW   rZ   rJ   modelr   r   r    r   q   s    '

r   c                 K   s   t | } t|}| dur@d}t|t| jd }t|d}n|du rLd}t|g dd}t|||}| dur|| j	|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:
    Nr4   Tr[   r\   r]   r_   )
r   r`   r   r   ra   rE   r   rS   rb   rc   rd   r   r   r    r      s    '

r   )
_ModelURLs)Zfcn_resnet50_cocoZfcn_resnet101_coco)*	functoolsr   typingr   r   torchr   transforms._presetsr   _apir	   r
   _metar   _utilsr   r   r   resnetr   r   r   r   r   r   __all__r   
Sequentialr!   rG   r   r   r2   boolrS   rH   IMAGENET1K_V1r   r   rf   rC   
model_urlsr   r   r   r    <module>   s   
67