§
    ù²ÅjÝs  ã                   óä  — d dl Z d dlmZ d dlmZmZmZmZmZ d dl	Z	d dl
mc mZ d dl	mZmZ ddl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 d	dlm Z m!Z!m"Z" ddl#mZ$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddgZ+ G d„ de¦  «        Z,dej-        fd„Z. G d„ dej-        ¦  «        Z/ G d„ dej-        ¦  «        Z0 G d„ de0¦  «        Z1 G d„ de0¦  «        Z2 G d „ d!ej-        ¦  «        Z3 G d"„ d#ej-        ¦  «        Z4d$e d%e5d&e6fd'„Z7 e¦   «          ed(e,j8        fd)e"j9        f¬*¦  «        dd+de"j9        dd,œd-ee,         d.e5d/ee6         d0ee"         d1ee6         d2ed3e3fd4„¦   «         ¦   «         Z:dS )5é    N)ÚOrderedDict)ÚAnyÚDictÚListÚOptionalÚTuple)ÚnnÚTensoré   )Úboxes)ÚObjectDetection)Ú_log_api_usage_onceé   )Úregister_modelÚWeightsÚWeightsEnum)Ú_COCO_CATEGORIES)Ú_ovewrite_value_paramÚhandle_legacy_interface)ÚVGGÚvgg16ÚVGG16_Weightsé   )Ú_utils)ÚDefaultBoxGenerator)Ú_validate_trainable_layers)ÚGeneralizedRCNNTransformÚSSD300_VGG16_WeightsÚssd300_vgg16c                   óH   — e Zd Z edededddddiidd	d
dœ¬¦  «        ZeZdS )r   zBhttps://download.pytorch.org/models/ssd300_vgg16_coco-b556d3b4.pthiâÙ)r   r   zMhttps://github.com/pytorch/vision/tree/main/references/detection#ssd300-vgg16zCOCO-val2017Úbox_mapgš™™™™9@gçû©ñÒmA@gV-²�ÿ`@zSThese weights were produced by following a similar training recipe as on the paper.)Ú
num_paramsÚ
categoriesÚmin_sizeÚrecipeÚ_metricsÚ_opsÚ
_file_sizeÚ_docs)ÚurlÚ
transformsÚmetaN)Ú__name__Ú
__module__Ú__qualname__r   r   r   ÚCOCO_V1ÚDEFAULT© ó    úQC:\Projects\Historical\venv\Lib\site-packages\torchvision/models/detection/ssd.pyr   r      sd   € € € € € ØˆgØPØ"à"Ø*ØØeàØ˜tð!ðð
 Ø!Ønð
ð 
ðñ ô €Gð$ €G€G€Gr3   Úconvc                 ó  — |                       ¦   «         D ]v}t          |t          j        ¦  «        rZt          j        j                             |j        ¦  «         |j        �*t          j        j         	                    |j        d¦  «         Œwd S )Ng        )
ÚmodulesÚ
isinstancer	   ÚConv2dÚtorchÚinitÚxavier_uniform_ÚweightÚbiasÚ	constant_)r5   Úlayers     r4   Ú_xavier_initrA   2   sv   € Ø—’‘”ð 9ð 9ˆÝ�e�RœYÑ'Ô'ð 	9ÝŒHŒM×)Ò)¨%¬,Ñ7Ô7Ð7ØŒzÐ%Ý””×'Ò'¨¬
°CÑ8Ô8Ð8øð	9ð 9r3   c                   óp   ‡ — e Zd Zdee         dee         defˆ fd„Zdee         deeef         fd„Z	ˆ xZ
S )ÚSSDHeadÚin_channelsÚnum_anchorsÚnum_classesc                 óž   •— t          ¦   «                              ¦   «          t          |||¦  «        | _        t	          ||¦  «        | _        d S ©N)ÚsuperÚ__init__ÚSSDClassificationHeadÚclassification_headÚSSDRegressionHeadÚregression_head)ÚselfrD   rE   rF   Ú	__class__s       €r4   rJ   zSSDHead.__init__;   sF   ø€ Ý‰Œ×ÒÑÔÐÝ#8¸ÀkÐS^Ñ#_Ô#_ˆÔ Ý0°¸kÑJÔJˆÔÐÐr3   ÚxÚreturnc                 óX   — |                       |¦  «        |                      |¦  «        dœS )N)Úbbox_regressionÚ
cls_logits)rN   rL   )rO   rQ   s     r4   ÚforwardzSSDHead.forward@   s3   € à#×3Ò3°AÑ6Ô6Ø×2Ò2°1Ñ5Ô5ð
ð 
ð 	
r3   )r-   r.   r/   r   ÚintrJ   r
   r   ÚstrrV   Ú__classcell__©rP   s   @r4   rC   rC   :   s“   ø€ € € € € ðK D¨¤Ið K¸DÀ¼Ið KÐTWð Kð Kð Kð Kð Kð Kð

˜˜fœð 
¨$¨s°F¨{Ô*;ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r3   rC   c                   ób   ‡ — e Zd Zdej        defˆ fd„Zdededefd„Zde	e         defd„Z
ˆ xZS )	ÚSSDScoringHeadÚmodule_listÚnum_columnsc                 ód   •— t          ¦   «                              ¦   «          || _        || _        d S rH   )rI   rJ   r]   r^   )rO   r]   r^   rP   s      €r4   rJ   zSSDScoringHead.__init__H   s/   ø€ Ý‰Œ×ÒÑÔÐØ&ˆÔØ&ˆÔÐÐr3   rQ   ÚidxrR   c                 óž   — t          | j        ¦  «        }|dk     r||z  }|}t          | j        ¦  «        D ]\  }}||k    r ||¦  «        }Œ|S )zr
        This is equivalent to self.module_list[idx](x),
        but torchscript doesn't support this yet
        r   )Úlenr]   Ú	enumerate)rO   rQ   r`   Ú
num_blocksÚoutÚiÚmodules          r4   Ú_get_result_from_module_listz+SSDScoringHead._get_result_from_module_listM   sf   € õ
 ˜Ô)Ñ*Ô*ˆ
Ø�Š7ˆ7Ø�:ÑˆCØˆÝ" 4Ô#3Ñ4Ô4ð 	 ð 	 ‰IˆAˆvØ�CŠxˆxØ�f˜Q‘i”i�øØˆ
r3   c                 óp  — g }t          |¦  «        D ]�\  }}|                      ||¦  «        }|j        \  }}}}	|                     |d| j        ||	¦  «        }|                     ddddd¦  «        }|                     |d| j        ¦  «        }|                     |¦  «         Œ�t          j	        |d¬¦  «        S )Néÿÿÿÿr   r   é   r   r   ©Údim)
rc   rh   ÚshapeÚviewr^   ÚpermuteÚreshapeÚappendr:   Úcat)
rO   rQ   Úall_resultsrf   ÚfeaturesÚresultsÚNÚ_ÚHÚWs
             r4   rV   zSSDScoringHead.forward[   s¿   € Øˆå$ Q™<œ<ð 		(ð 		(‰KˆAˆxØ×7Ò7¸À!ÑDÔDˆGð !œ‰JˆAˆq�!�QØ—l’l 1 b¨$Ô*:¸A¸qÑAÔAˆGØ—o’o a¨¨A¨q°!Ñ4Ô4ˆGØ—o’o a¨¨TÔ-=Ñ>Ô>ˆGà×Ò˜wÑ'Ô'Ð'Ð'åŒy˜¨!Ð,Ñ,Ô,Ð,r3   )r-   r.   r/   r	   Ú
ModuleListrW   rJ   r
   rh   r   rV   rY   rZ   s   @r4   r\   r\   G   sœ   ø€ € € € € ð' B¤Mð 'Àð 'ð 'ð 'ð 'ð 'ð 'ð
¨fð ¸3ð À6ð ð ð ð ð-˜˜fœð -¨&ð -ð -ð -ð -ð -ð -ð -ð -r3   r\   c                   óD   ‡ — e Zd Zdee         dee         defˆ fd„Zˆ xZS )rK   rD   rE   rF   c           	      ó  •— t          j        ¦   «         }t          ||¦  «        D ]3\  }}|                     t          j        |||z  dd¬¦  «        ¦  «         Œ4t          |¦  «         t          ¦   «                              ||¦  «         d S )Nr   r   ©Úkernel_sizeÚpadding©r	   r{   Úziprr   r9   rA   rI   rJ   )rO   rD   rE   rF   rU   ÚchannelsÚanchorsrP   s          €r4   rJ   zSSDClassificationHead.__init__m   s�   ø€ Ý”]‘_”_ˆ
Ý!$ [°+Ñ!>Ô!>ð 	dð 	dÑˆH�gØ×Ò�bœi¨°+ÀÑ2GÐUVÐ`aÐbÑbÔbÑcÔcÐcÐcÝ�ZÑ Ô Ð Ý‰Œ×Ò˜ [Ñ1Ô1Ð1Ð1Ð1r3   ©r-   r.   r/   r   rW   rJ   rY   rZ   s   @r4   rK   rK   l   s[   ø€ € € € € ð2 D¨¤Ið 2¸DÀ¼Ið 2ÐTWð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2ð 2r3   rK   c                   ó@   ‡ — e Zd Zdee         dee         fˆ fd„Zˆ xZS )rM   rD   rE   c           	      ó  •— t          j        ¦   «         }t          ||¦  «        D ]3\  }}|                     t          j        |d|z  dd¬¦  «        ¦  «         Œ4t          |¦  «         t          ¦   «                              |d¦  «         d S )Nrk   r   r   r~   r�   )rO   rD   rE   Úbbox_regrƒ   r„   rP   s         €r4   rJ   zSSDRegressionHead.__init__v   s‰   ø€ Ý”=‘?”?ˆÝ!$ [°+Ñ!>Ô!>ð 	Xð 	XÑˆH�gØ�OŠO�BœI h°°G±ÈÐTUÐVÑVÔVÑWÔWÐWÐWÝ�XÑÔÐÝ‰Œ×Ò˜ 1Ñ%Ô%Ð%Ð%Ð%r3   r…   rZ   s   @r4   rM   rM   u   sS   ø€ € € € € ð& D¨¤Ið &¸DÀ¼Ið &ð &ð &ð &ð &ð &ð &ð &ð &ð &r3   rM   c                   óò  ‡ — e Zd ZdZej        ej        dœZ	 	 	 	 	 	 	 	 	 d'd
ej	        de
deeef         dedeee                  deee                  deej	                 dededededededefˆ fd„Zej        j        deeef         deeeef                  deeeef         eeeef                  f         fd„¦   «         Zdeeeef                  deeef         dee         d ee         deeef         f
d!„Z	 d(d"ee         deeeeef                           deeeef         eeeef                  f         fd#„Zdeeef         d$ee         d%eeeef                  deeeef                  fd&„Zˆ xZS ))ÚSSDaM  
    Implements SSD architecture from `"SSD: Single Shot MultiBox Detector" <https://arxiv.org/abs/1512.02325>`_.

    The input to the model is expected to be a list of tensors, each of shape [C, H, W], one for each
    image, and should be in 0-1 range. Different images can have different sizes, but they will be resized
    to a fixed size before passing it to the backbone.

    The behavior of the model changes depending on if it is in training or evaluation mode.

    During training, the model expects both the input tensors and targets (list of dictionary),
    containing:
        - boxes (``FloatTensor[N, 4]``): the ground-truth boxes in ``[x1, y1, x2, y2]`` format, with
          ``0 <= x1 < x2 <= W`` and ``0 <= y1 < y2 <= H``.
        - labels (Int64Tensor[N]): the class label for each ground-truth box

    The model returns a Dict[Tensor] during training, containing the classification and regression
    losses.

    During inference, the model requires only the input tensors, and returns the post-processed
    predictions as a List[Dict[Tensor]], one for each input image. The fields of the Dict are as
    follows, where ``N`` is the number of detections:

        - boxes (``FloatTensor[N, 4]``): the predicted boxes in ``[x1, y1, x2, y2]`` format, with
          ``0 <= x1 < x2 <= W`` and ``0 <= y1 < y2 <= H``.
        - labels (Int64Tensor[N]): the predicted labels for each detection
        - scores (Tensor[N]): the scores for each detection

    Args:
        backbone (nn.Module): the network used to compute the features for the model.
            It should contain an out_channels attribute with the list of the output channels of
            each feature map. The backbone should return a single Tensor or an OrderedDict[Tensor].
        anchor_generator (DefaultBoxGenerator): module that generates the default boxes for a
            set of feature maps.
        size (Tuple[int, int]): the width and height to which images will be rescaled before feeding them
            to the backbone.
        num_classes (int): number of output classes of the model (including the background).
        image_mean (Tuple[float, float, float]): mean values used for input normalization.
            They are generally the mean values of the dataset on which the backbone has been trained
            on
        image_std (Tuple[float, float, float]): std values used for input normalization.
            They are generally the std values of the dataset on which the backbone has been trained on
        head (nn.Module, optional): Module run on top of the backbone features. Defaults to a module containing
            a classification and regression module.
        score_thresh (float): Score threshold used for postprocessing the detections.
        nms_thresh (float): NMS threshold used for postprocessing the detections.
        detections_per_img (int): Number of best detections to keep after NMS.
        iou_thresh (float): minimum IoU between the anchor and the GT box so that they can be
            considered as positive during training.
        topk_candidates (int): Number of best detections to keep before NMS.
        positive_fraction (float): a number between 0 and 1 which indicates the proportion of positive
            proposals used during the training of the classification head. It is used to estimate the negative to
            positive ratio.
    )Ú	box_coderÚproposal_matcherNç{®Gáz„?çÍÌÌÌÌÌÜ?éÈ   ç      à?é�  ç      Ð?ÚbackboneÚanchor_generatorÚsizerF   Ú
image_meanÚ	image_stdÚheadÚscore_threshÚ
nms_threshÚdetections_per_imgÚ
iou_threshÚtopk_candidatesÚpositive_fractionÚkwargsc                 ó8  •— t          ¦   «                              ¦   «          t          | ¦  «         || _        || _        t          j        d¬¦  «        | _        |€±t          |d¦  «        r|j	        }nt          j
        ||¦  «        }t          |¦  «        t          |j        ¦  «        k    r5t          dt          |¦  «        › dt          |j        ¦  «        › d�¦  «        ‚| j                             ¦   «         }t          |||¦  «        }|| _        t          j        |¦  «        | _        |€g d¢}|€g d¢}t'          t)          |¦  «        t+          |¦  «        ||fd	|d
œ|¤Ž| _        || _        |	| _        |
| _        || _        d|z
  |z  | _        d| _        d S )N)ç      $@r¡   ç      @r¢   )ÚweightsÚout_channelsz5The length of the output channels from the backbone (zA) do not match the length of the anchor generator aspect ratios (ú))g
×£p=
ß?gÉv¾Ÿ/Ý?g–C‹lçûÙ?)gZd;ßOÍ?gyé&1¬Ì?gÍÌÌÌÌÌÌ?r   )Úsize_divisibleÚ
fixed_sizeg      ð?F)rI   rJ   r   r“   r”   Ú	det_utilsÚBoxCoderr‹   Úhasattrr¤   Úretrieve_out_channelsrb   Úaspect_ratiosÚ
ValueErrorÚnum_anchors_per_locationrC   r˜   Ú
SSDMatcherrŒ   r   ÚminÚmaxÚ	transformr™   rš   r›   r�   Úneg_to_pos_ratioÚ_has_warned)rO   r“   r”   r•   rF   r–   r—   r˜   r™   rš   r›   rœ   r�   rž   rŸ   r¤   rE   rP   s                    €r4   rJ   zSSD.__init__º   së  ø€ õ" 	‰Œ×ÒÑÔÐÝ˜DÑ!Ô!Ð!à ˆŒà 0ˆÔå"Ô+Ð4JÐKÑKÔKˆŒàˆ<Ý�x Ñ0Ô0ð OØ'Ô4��å(Ô>¸xÈÑNÔN�å�<Ñ Ô ¥CÐ(8Ô(FÑ$GÔ$GÒGÐGÝ ð GÍCÐP\ÑL]ÔL]ð  Gð  Gõ  adð  euô  eCñ  aDô  aDð  Gð  Gð  Gñô ð ð Ô/×HÒHÑJÔJˆKÝ˜<¨°kÑBÔBˆDØˆŒ	å )Ô 4°ZÑ @Ô @ˆÔàÐØ.Ð.Ð.ˆJØÐØ-Ð-Ð-ˆIÝ1Ý�‰IŒI•s˜4‘y”y *¨ið
ØHIÐVZð
ð 
Ø^dð
ð 
ˆŒð )ˆÔØ$ˆŒØ"4ˆÔØ.ˆÔØ!$Ð'8Ñ!8Ð<MÑ MˆÔð !ˆÔÐÐr3   ÚlossesÚ
detectionsrR   c                 ó   — | j         r|S |S rH   )Útraining)rO   rµ   r¶   s      r4   Úeager_outputszSSD.eager_outputsö   s   € ð Œ=ð 	ØˆMàÐr3   ÚtargetsÚhead_outputsr„   Úmatched_idxsc                 ó²  — |d         }|d         }d}g }g }	t          |||||¦  «        D �](\  }
}}}}t          j        |dk    ¦  «        d         }||         }||                     ¦   «         z  }|
d         |         }||d d …f         }||d d …f         }| j                             ||¦  «        }|                     t          j        j         	                    ||d¬¦  «        ¦  «         t          j
        |                     d¦  «        f|
d         j        |
d         j        ¬¦  «        }|
d         |         ||<   |	                     |¦  «         �Œ*t          j        |¦  «        }t          j        |	¦  «        }	|                     d	¦  «        }t          j        |                     d	|¦  «        |	                     d	¦  «        d
¬¦  «                             |	                     ¦   «         ¦  «        }|	dk    }| j        |                     dd¬¦  «        z  }|                     ¦   «         }t+          d¦  «         ||<   |                     dd¬¦  «        \  }}|                     d¦  «        d         |k     }t/          d|¦  «        }|                     ¦   «         |z  ||                              ¦   «         ||                              ¦   «         z   |z  dœS )NrT   rU   r   r   Úsum)Ú	reductionÚlabels©ÚdtypeÚdevicerj   Únoner   T)ÚkeepdimÚinf)Ú
descending)rT   Úclassification)r‚   r:   ÚwhereÚnumelr‹   Úencode_singlerr   r	   Ú
functionalÚsmooth_l1_lossÚzerosr•   rÂ   rÃ   ÚstackÚFÚcross_entropyro   r³   r¾   ÚcloneÚfloatÚsortr±   )rO   rº   r»   r„   r¼   rT   rU   Únum_foregroundÚ	bbox_lossÚcls_targetsÚtargets_per_imageÚbbox_regression_per_imageÚcls_logits_per_imageÚanchors_per_imageÚmatched_idxs_per_imageÚforeground_idxs_per_imageÚ!foreground_matched_idxs_per_imageÚmatched_gt_boxes_per_imageÚtarget_regressionÚgt_classes_targetrF   Úcls_lossÚforeground_idxsÚnum_negativeÚnegative_lossÚvaluesr`   Úbackground_idxsrw   s                                r4   Úcompute_losszSSD.compute_lossÿ   s  € ð 'Ð'8Ô9ˆØ! ,Ô/ˆ
ð ˆØˆ	Øˆõ �˜/¨:°wÀÑMÔMð	2ñ 	2ñ 
ØØ%Ø ØØ"õ ).¬Ð4JÈaÒ4OÑ(PÔ(PÐQRÔ(SÐ%Ø0FÐG`Ô0aÐ-ØÐ?×EÒEÑGÔGÑGˆNð *;¸7Ô)CÐDeÔ)fÐ&Ø(AÐB[Ð]^Ð]^Ð]^ÐB^Ô(_Ð%Ø 1Ð2KÈQÈQÈQÐ2NÔ OÐØ $¤× <Ò <Ð=WÐYjÑ kÔ kÐØ×ÒÝ”Ô#×2Ò2Ð3LÐN_ÐkpÐ2ÑqÔqñô ð õ
 !&¤Ø%×*Ò*¨1Ñ-Ô-Ð/Ø'¨Ô1Ô7Ø(¨Ô2Ô9ð!ñ !ô !Ðð
 <MÈXÔ;VØ1ô<ÐÐ7Ñ8ð ×ÒÐ0Ñ1Ô1Ð1Ñ1å”K 	Ñ*Ô*ˆ	Ý”k +Ñ.Ô.ˆð !—o’o bÑ)Ô)ˆÝ”? :§?¢?°2°{Ñ#CÔ#CÀ[×EUÒEUÐVXÑEYÔEYÐekÐlÑlÔl×qÒqØ×ÒÑÔñ
ô 
ˆð
 &¨š/ˆØÔ,¨×/BÒ/BÀ1ÈdÐ/BÑ/SÔ/SÑSˆà ŸšÑ(Ô(ˆÝ*/°©,¬,¨ˆ�oÑ&Ø#×(Ò(¨°tÐ(Ñ<Ô<‰ˆ�àŸ(š( 1™+œ+ aœ.¨<Ò7ˆå��>Ñ"Ô"ˆà(Ÿ}š}™œ°Ñ2Ø'¨Ô8×<Ò<Ñ>Ô>ÀÈ/ÔAZ×A^ÒA^ÑA`ÔA`Ñ`ÐdeÑeð
ð 
ð 	
r3   Úimagesc           	      óH  — | j         r«|€t          j        dd¦  «         n“|D ]�}|d         }t          |t          j        ¦  «        rFt          j        t          |j        ¦  «        dk    o|j        d         dk    d|j        › d�¦  «         Œjt          j        dd	t          |¦  «        › d�¦  «         Œ‘g }|D ]j}|j        d
d …         }t          j        t          |¦  «        dk    d|j        d
d …         › �¦  «         |                     |d         |d         f¦  «         Œk|  	                    ||¦  «        \  }}|�¹t          |¦  «        D ]©\  }}|d         }|d d …dd …f         |d d …d d…f         k    }	|	                     ¦   «         rjt          j        |	                     d¬¦  «        ¦  «        d         d         }
||
                              ¦   «         }t          j        dd|› d|› d�¦  «         Œª|                      |j        ¦  «        }t          |t          j        ¦  «        rt!          d|fg¦  «        }t#          |                     ¦   «         ¦  «        }|                      |¦  «        }|                      ||¦  «        }i }g }| j         rúg }|€t          j        dd¦  «         �nt+          ||¦  «        D ]µ\  }}|d                              ¦   «         dk    rO|                     t          j        |                     d¦  «        fdt          j        |j        ¬¦  «        ¦  «         Œrt7          j        |d         |¦  «        }|                     |                      |¦  «        ¦  «         Œ¶|                      ||||¦  «        }n=|                      |||j         ¦  «        }| j	         !                    ||j         |¦  «        }t          j"         #                    ¦   «         r&| j$        stK          j&        d¦  «         d| _$        ||fS |  '                    ||¦  «        S )NFz0targets should not be none when in training moder   r   rj   rk   z:Expected target boxes to be a tensor of shape [N, 4], got ú.z0Expected target boxes to be of type Tensor, got éþÿÿÿzJexpecting the last two dimensions of the Tensor to be H and W instead got r   r   rl   zLAll bounding boxes should have positive height and width. Found invalid box z for target at index Ú0rÁ   z<SSD always returns a (Losses, Detections) tuple in scriptingT)(r¸   r:   Ú_assertr8   r
   rb   rn   Útyperr   r²   rc   ÚanyrÉ   Útolistr“   Útensorsr   Úlistræ   r˜   r”   r‚   rÊ   Úfullr•   Úint64rÃ   Úbox_opsÚbox_iourŒ   rè   Úpostprocess_detectionsÚimage_sizesÚpostprocessÚjitÚis_scriptingr´   ÚwarningsÚwarnr¹   )rO   ré   rº   Útargetr   Úoriginal_image_sizesÚimgÚvalÚ
target_idxÚdegenerate_boxesÚbb_idxÚdegen_bbru   r»   r„   rµ   r¶   r¼   rÛ   rØ   Úmatch_quality_matrixs                        r4   rV   zSSD.forwardF  s�  € ð Œ=ð 	pØˆÝ”˜eÐ%WÑXÔXÐXÐXà%ð pð p�FØ" 7œO�EÝ! %­¬Ñ6Ô6ð pÝœÝ ¤Ñ,Ô,°Ò1ÐJ°e´kÀ"´oÈÒ6JØgÐY^ÔYdÐgÐgÐgñô ð ð õ
 œ eÐ-nÕ`dÐejÑ`kÔ`kÐ-nÐ-nÐ-nÑoÔoÐoÐoð 79ÐØð 	:ð 	:ˆCØ”)˜B˜C˜C”.ˆCÝŒMÝ�C‘”˜A’ØmÐ]`Ô]fÐgiÐgjÐgjÔ]kÐmÐmñô ð ð !×'Ò'¨¨Q¬°°Q´Ð(8Ñ9Ô9Ð9Ð9ð Ÿ.š.¨°Ñ9Ô9‰ˆ�ð ÐÝ&/°Ñ&8Ô&8ð 
ð 
Ñ"�
˜FØ˜wœ�Ø#(¨¨¨¨A¨B¨B¨¤<°5¸¸¸¸B¸Q¸B¸´<Ò#?Ð Ø#×'Ò'Ñ)Ô)ð Ý"œ[Ð)9×)=Ò)=À!Ð)=Ñ)DÔ)DÑEÔEÀaÔHÈÔK�FØ,1°&¬M×,@Ò,@Ñ,BÔ,B�HÝ”MØð[Ø.6ð[ð [ØMWð[ð [ð [ñô ð øð —=’= ¤Ñ0Ô0ˆÝ�h¥¤Ñ-Ô-ð 	6Ý" S¨( OÐ#4Ñ5Ô5ˆHå˜ŸšÑ)Ô)Ñ*Ô*ˆð —y’y Ñ*Ô*ˆð ×'Ò'¨°Ñ9Ô9ˆàˆØ.0ˆ
ØŒ=ð 	jØˆLØˆÝ”˜eÐ%WÑXÔXÐXÑXå<?ÀÈÑ<QÔ<Qð 
Uð 
UÑ8Ð%Ð'8Ø(¨Ô1×7Ò7Ñ9Ô9¸QÒ>Ð>Ø$×+Ò+Ý!œJØ!2×!7Ò!7¸Ñ!:Ô!:Ð <¸bÍÌÐ\mÔ\tðñ ô ñô ð ð
 !å+2¬?Ð;LÈWÔ;UÐWhÑ+iÔ+iÐ(Ø ×'Ò'¨×(=Ò(=Ð>RÑ(SÔ(SÑTÔTÐTÐTà×*Ò*¨7°LÀ'È<ÑXÔX��à×4Ò4°\À7ÈFÔL^Ñ_Ô_ˆJØœ×3Ò3°JÀÔ@RÐThÑiÔiˆJåŒ9×!Ò!Ñ#Ô#ð 	&ØÔ#ð (Ý”Ð\Ñ]Ô]Ð]Ø#'�Ô Ø˜:Ð%Ð%Ø×!Ò! &¨*Ñ5Ô5Ð5r3   Úimage_anchorsÚimage_shapesc           
      ó  — |d         }t          j        |d         d¬¦  «        }|                     d¦  «        }|j        }g }t	          ||||¦  «        D �]ª\  }	}
}}| j                             |	|¦  «        }	t          j        |	|¦  «        }	g }g }g }t          d|¦  «        D ]Ã}|
d d …|f         }|| j
        k    }||         }|	|         }t          j        || j        d¦  «        }|                     |¦  «        \  }}||         }|                     |¦  «         |                     |¦  «         |                     t!          j        ||t           j        |¬¦  «        ¦  «         ŒÄt!          j        |d¬¦  «        }t!          j        |d¬¦  «        }t!          j        |d¬¦  «        }t          j        |||| j        ¦  «        }|d | j        …         }|                     ||         ||         ||         dœ¦  «         �Œ¬|S )	NrT   rU   rj   rl   r   r   )Ú
fill_valuerÂ   rÃ   )r   ÚscoresrÀ   )rÐ   Úsoftmaxr•   rÃ   r‚   r‹   Údecode_singlerö   Úclip_boxes_to_imageÚranger™   r¨   Ú	_topk_minr�   Útopkrr   r:   Ú	full_likerõ   rs   Úbatched_nmsrš   r›   )rO   r»   r  r	  rT   Úpred_scoresrF   rÃ   r¶   r   r  r„   Úimage_shapeÚimage_boxesÚimage_scoresÚimage_labelsÚlabelÚscoreÚ	keep_idxsÚboxÚnum_topkÚidxsÚkeeps                          r4   rø   zSSD.postprocess_detectionsž  s6  € ð 'Ð'8Ô9ˆÝ”i ¨\Ô :ÀÐCÑCÔCˆà!×&Ò& rÑ*Ô*ˆØÔ#ˆà.0ˆ
å36°ÈÐUbÐdpÑ3qÔ3qð %	ñ %	Ñ/ˆE�6˜7 KØ”N×0Ò0°¸Ñ@Ô@ˆEÝÔ/°°{ÑCÔCˆEàˆKØˆLØˆLÝ˜q +Ñ.Ô.ð pð p�Ø˜q˜q˜q %˜xÔ(�à! DÔ$5Ò5�	Ø˜iÔ(�Ø˜IÔ&�õ %Ô.¨u°dÔ6JÈAÑNÔN�Ø#Ÿjšj¨Ñ2Ô2‘��tØ˜$”i�à×"Ò" 3Ñ'Ô'Ð'Ø×#Ò# EÑ*Ô*Ð*Ø×#Ò#¥E¤O°EÀeÕSXÔS^ÐgmÐ$nÑ$nÔ$nÑoÔoÐoÐoåœ) K°QÐ7Ñ7Ô7ˆKÝ œ9 \°qÐ9Ñ9Ô9ˆLÝ œ9 \°qÐ9Ñ9Ô9ˆLõ Ô& {°LÀ,ÐPTÔP_Ñ`Ô`ˆDØÐ1˜$Ô1Ð1Ô2ˆDà×Òà(¨Ô.Ø*¨4Ô0Ø*¨4Ô0ðð ñô ð ñ ð Ðr3   )	NNNr�   rŽ   r�   r�   r‘   r’   rH   )r-   r.   r/   Ú__doc__r¨   r©   ÚMatcherÚ__annotations__r	   ÚModuler   r   rW   r   r   rÓ   r   rJ   r:   rû   Úunusedr   rX   r
   r¹   rè   rV   rø   rY   rZ   s   @r4   rŠ   rŠ   ~   sø  ø€ € € € € ð4ð 4ðn Ô'Ø%Ô-ðð €Oð -1Ø+/Ø$(Ø"Ø Ø"%ØØ"Ø#'ð:!ð :!à”)ð:!ð .ð:!ð �C˜�HŒoð	:!ð
 ð:!ð ˜T %œ[Ô)ð:!ð ˜D œKÔ(ð:!ð �r”yÔ!ð:!ð ð:!ð ð:!ð  ð:!ð ð:!ð ð:!ð !ð:!ð ð:!ð :!ð :!ð :!ð :!ð :!ðx „YÔðØ˜3 ˜;Ô'ðØ59¸$¸sÀF¸{Ô:KÔ5Lðà	ˆt�C˜�KÔ  $ t¨C°¨KÔ'8Ô"9Ð9Ô	:ðð ð ñ ÔððE
à�d˜3 ˜;Ô'Ô(ðE
ð ˜3 ˜;Ô'ðE
ð �f”ð	E
ð
 ˜6”lðE
ð 
ˆc�6ˆkÔ	ðE
ð E
ð E
ð E
ðP RVðV6ð V6Ø˜6”lðV6Ø-5°d¸4ÀÀVÀÔ;LÔ6MÔ-NðV6à	ˆt�C˜�KÔ  $ t¨C°¨KÔ'8Ô"9Ð9Ô	:ðV6ð V6ð V6ð V6ðp1Ø   f Ô-ð1Ø>BÀ6¼lð1ØZ^Ð_dÐehÐjmÐemÔ_nÔZoð1à	ˆd�3˜�;ÔÔ	 ð1ð 1ð 1ð 1ð 1ð 1ð 1ð 1r3   rŠ   c                   óR   ‡ — e Zd Zdej        defˆ fd„Zdedee	ef         fd„Z
ˆ xZS )ÚSSDFeatureExtractorVGGr“   Úhighresc                 ó2  •— t          ¦   «                              ¦   «          d„ t          |¦  «        D ¦   «         \  }}}}}d||         _        t	          j        t          j        d¦  «        dz  ¦  «        | _        t	          j	        |d |…         Ž | _
        t	          j        t	          j	        t	          j        ddd¬¦  «        t	          j        d¬	¦  «        t	          j        ddd
dd¬¦  «        t	          j        d¬	¦  «        ¦  «        t	          j	        t	          j        ddd¬¦  «        t	          j        d¬	¦  «        t	          j        ddd
dd¬¦  «        t	          j        d¬	¦  «        ¦  «        t	          j	        t	          j        ddd¬¦  «        t	          j        d¬	¦  «        t	          j        ddd
¬¦  «        t	          j        d¬	¦  «        ¦  «        t	          j	        t	          j        ddd¬¦  «        t	          j        d¬	¦  «        t	          j        ddd
¬¦  «        t	          j        d¬	¦  «        ¦  «        g¦  «        }|rz|                     t	          j	        t	          j        ddd¬¦  «        t	          j        d¬	¦  «        t	          j        ddd¬¦  «        t	          j        d¬	¦  «        ¦  «        ¦  «         t          |¦  «         t	          j	        t	          j        d
ddd¬¦  «        t	          j        ddd
dd¬¦  «        t	          j        d¬	¦  «        t	          j        ddd¬¦  «        t	          j        d¬	¦  «        ¦  «        }t          |¦  «         |                     dt	          j	        g ||d…         ¢|‘R Ž ¦  «         || _        d S )Nc              3   óT   K  — | ]#\  }}t          |t          j        ¦  «        ¯|V — Œ$d S rH   ©r8   r	   Ú	MaxPool2d)Ú.0rf   r@   s      r4   ú	<genexpr>z2SSDFeatureExtractorVGG.__init__.<locals>.<genexpr>Ö  s;   è è € Ð.xÐ.x±X°Q¸ÕXbÐchÕjlÔjvÑXwÔXwÐ.x¨qÐ.xÐ.xÐ.xÐ.xÐ.xÐ.xr3   Ti   é   i   é   r   )r   )Úinplacer   r   )r   r€   Ústrideé€   rk   F)r   r2  r€   Ú	ceil_modeé   )rD   r¤   r   r€   Údilation)rD   r¤   r   r   rj   )rI   rJ   rc   r4  r	   Ú	Parameterr:   ÚonesÚscale_weightÚ
Sequentialru   r{   r9   ÚReLUrr   rA   r,  ÚinsertÚextra)	rO   r“   r(  rx   Úmaxpool3_posÚmaxpool4_posr=  ÚfcrP   s	           €r4   rJ   zSSDFeatureExtractorVGG.__init__Ó  si  ø€ Ý‰Œ×ÒÑÔÐà.xÐ.xÅÈ8ÑATÔATÐ.xÑ.xÔ.xÑ+ˆˆ1ˆl˜L¨!ð ,0ˆ�ÔÔ(õ œL­¬°C©¬¸2Ñ)=Ñ>Ô>ˆÔõ œ x°°°Ô'>Ð?ˆŒõ ”å”Ý”I˜d C°QÐ7Ñ7Ô7Ý”G DÐ)Ñ)Ô)Ý”I˜c 3°A¸qÈÐKÑKÔKÝ”G DÐ)Ñ)Ô)ñ	ô õ ”Ý”I˜c 3°AÐ6Ñ6Ô6Ý”G DÐ)Ñ)Ô)Ý”I˜c 3°A¸qÈÐKÑKÔKÝ”G DÐ)Ñ)Ô)ñ	ô õ ”Ý”I˜c 3°AÐ6Ñ6Ô6Ý”G DÐ)Ñ)Ô)Ý”I˜c 3°AÐ6Ñ6Ô6Ý”G DÐ)Ñ)Ô)ñ	ô õ ”Ý”I˜c 3°AÐ6Ñ6Ô6Ý”G DÐ)Ñ)Ô)Ý”I˜c 3°AÐ6Ñ6Ô6Ý”G DÐ)Ñ)Ô)ñ	ô ð'ñ
ô 
ˆð8 ð 		à�LŠLÝ”Ý”I˜c 3°AÐ6Ñ6Ô6Ý”G DÐ)Ñ)Ô)Ý”I˜c 3°AÐ6Ñ6Ô6Ý”G DÐ)Ñ)Ô)ñ	ô ñô ð õ 	�UÑÔÐåŒ]ÝŒL Q¨q¸!ÀuÐMÑMÔMÝŒI #°DÀaÐQRÐ]^Ð_Ñ_Ô_ÝŒG˜DÐ!Ñ!Ô!ÝŒI $°TÀqÐIÑIÔIÝŒG˜DÐ!Ñ!Ô!ñ
ô 
ˆõ 	�RÑÔÐØ�ŠØÝŒMð Ø˜, r˜/Ô*ðàðð ð ñ	
ô 	
ð 	
ð ˆŒ
ˆ
ˆ
r3   rQ   rR   c                 ó6  — |                       |¦  «        }| j                             dddd¦  «        t          j        |¦  «        z  }|g}| j        D ]"} ||¦  «        }|                     |¦  «         Œ#t          d„ t          |¦  «        D ¦   «         ¦  «        S )Nr   rj   c                 ó6   — g | ]\  }}t          |¦  «        |f‘ŒS r2   )rX   )r-  rf   Úvs      r4   ú
<listcomp>z2SSDFeatureExtractorVGG.forward.<locals>.<listcomp>&  s&   € ÐFÐFÐF©D¨A¨q�S ™VœV Q˜KÐFÐFÐFr3   )	ru   r9  ro   rÐ   Ú	normalizer=  rr   r   rc   )rO   rQ   ÚrescaledÚoutputÚblocks        r4   rV   zSSDFeatureExtractorVGG.forward  s�   € à�MŠM˜!ÑÔˆØÔ$×)Ò)¨!¨R°°AÑ6Ô6½¼ÀQ¹¼ÑGˆØ�ˆð ”Zð 	ð 	ˆEØ��a‘”ˆAØ�MŠM˜!ÑÔÐÐåÐFÐFµI¸fÑ4EÔ4EÐFÑFÔFÑGÔGÐGr3   )r-   r.   r/   r	   r$  ÚboolrJ   r
   r   rX   rV   rY   rZ   s   @r4   r'  r'  Ò  s‹   ø€ € € € € ðF ¤ð F°Tð Fð Fð Fð Fð Fð FðPH˜ð H D¨¨f¨Ô$5ð Hð Hð Hð Hð Hð Hð Hð Hr3   r'  r“   r(  Útrainable_layersc                 óœ  — | j         } dgd„ t          | ¦  «        D ¦   «         d d…         z   }t          |¦  «        }t          j        d|cxk    o|k    nc d|› d|› �¦  «         |dk    rt          | ¦  «        n
|||z
           }| d |…         D ].}|                     ¦   «         D ]}|                     d¦  «         ŒŒ/t          | |¦  «        S )Nr   c                 óL   — g | ]!\  }}t          |t          j        ¦  «        ¯|‘Œ"S r2   r+  )r-  rf   Úbs      r4   rD  z"_vgg_extractor.<locals>.<listcomp>,  s-   € Ð\Ð\Ð\¡  AÅ
È1ÍbÌlÑ@[Ô@[Ð\˜1Ð\Ð\Ð\r3   rj   z,trainable_layers should be in the range [0, z]. Instead got F)ru   rc   rb   r:   rî   Ú
parametersÚrequires_grad_r'  )r“   r(  rJ  Ústage_indicesÚ
num_stagesÚfreeze_beforerM  Ú	parameters           r4   Ú_vgg_extractorrT  )  s  € ØÔ €Hà�CÐ\Ð\­°8Ñ)<Ô)<Ð\Ñ\Ô\Ð]`Ð^`Ð]`ÔaÑa€MÝ�]Ñ#Ô#€Jõ 
„MØ	ÐÐ+Ð+Ò+Ð+ Ò+Ð+Ð+Ð+Ød°zÐdÐdÐRbÐdÐdñô ð ð &6¸Ò%:Ð%:•C˜‘M”M�MÀÈjÐ[kÑNkÔ@l€Mà�n�}�nÔ%ð ,ð ,ˆØŸš™œð 	,ð 	,ˆIØ×$Ò$ UÑ+Ô+Ð+Ð+ð	,õ " (¨GÑ4Ô4Ð4r3   Ú
pretrainedÚpretrained_backbone)r£   Úweights_backboneT)r£   ÚprogressrF   rW  Útrainable_backbone_layersr£   rX  rF   rW  rY  rŸ   rR   c                 óJ  — t                                | ¦  «        } t          j        |¦  «        }d|v rt          j        d¦  «         | �,d}t          d|t          | j        d         ¦  «        ¦  «        }n|€d}t          | dup|du|dd¦  «        }t          ||¬	¦  «        }t          |d
|¦  «        }t          dgddgddgddgdgdggg d¢g d¢¬¦  «        }g d¢g d¢dœ}i |¥|¥}t          ||d|fi |¤Ž}	| �*|	                     |                      |d¬¦  «        ¦  «         |	S )a4  The SSD300 model is based on the `SSD: Single Shot MultiBox Detector
    <https://arxiv.org/abs/1512.02325>`_ paper.

    .. betastatus:: detection module

    The input to the model is expected to be a list of tensors, each of shape [C, H, W], one for each
    image, and should be in 0-1 range. Different images can have different sizes, but they will be resized
    to a fixed size before passing it to the backbone.

    The behavior of the model changes depending on if it is in training or evaluation mode.

    During training, the model expects both the input tensors and targets (list of dictionary),
    containing:

        - boxes (``FloatTensor[N, 4]``): the ground-truth boxes in ``[x1, y1, x2, y2]`` format, with
          ``0 <= x1 < x2 <= W`` and ``0 <= y1 < y2 <= H``.
        - labels (Int64Tensor[N]): the class label for each ground-truth box

    The model returns a Dict[Tensor] during training, containing the classification and regression
    losses.

    During inference, the model requires only the input tensors, and returns the post-processed
    predictions as a List[Dict[Tensor]], one for each input image. The fields of the Dict are as
    follows, where ``N`` is the number of detections:

        - boxes (``FloatTensor[N, 4]``): the predicted boxes in ``[x1, y1, x2, y2]`` format, with
          ``0 <= x1 < x2 <= W`` and ``0 <= y1 < y2 <= H``.
        - labels (Int64Tensor[N]): the predicted labels for each detection
        - scores (Tensor[N]): the scores for each detection

    Example:

        >>> model = torchvision.models.detection.ssd300_vgg16(weights=SSD300_VGG16_Weights.DEFAULT)
        >>> model.eval()
        >>> x = [torch.rand(3, 300, 300), torch.rand(3, 500, 400)]
        >>> predictions = model(x)

    Args:
        weights (:class:`~torchvision.models.detection.SSD300_VGG16_Weights`, optional): The pretrained
                weights to use. See
                :class:`~torchvision.models.detection.SSD300_VGG16_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)
        weights_backbone (:class:`~torchvision.models.VGG16_Weights`, optional): The pretrained weights for the
            backbone
        trainable_backbone_layers (int, optional): number of trainable (not frozen) layers starting from final block.
            Valid values are between 0 and 5, with 5 meaning all backbone layers are trainable. If ``None`` is
            passed (the default) this value is set to 4.
        **kwargs: parameters passed to the ``torchvision.models.detection.SSD``
            base class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/detection/ssd.py>`_
            for more details about this class.

    .. autoclass:: torchvision.models.detection.SSD300_VGG16_Weights
        :members:
    r•   z?The size of the model is already fixed; ignoring the parameter.NrF   r#   é[   é   rk   )r£   rX  Fr   r   )gìQ¸…ë±?g333333Ã?g…ëQ¸Õ?gR¸…ëQà?g®Gázæ?g×£p=
×ë?gÍÌÌÌÌÌð?)é   é   é    é@   éd   é,  )ÚscalesÚsteps)g;pÎˆÒÞÞ?gÌ°�N]Ý?g|
€ñÚ?)çp?re  re  )r–   r—   )rb  rb  T)rX  Ú
check_hash)r   Úverifyr   rý   rþ   r   rb   r,   r   r   rT  r   rŠ   Úload_state_dictÚget_state_dict)
r£   rX  rF   rW  rY  rŸ   r“   r”   ÚdefaultsÚmodels
             r4   r   r   =  sœ  € õR #×)Ò)¨'Ñ2Ô2€GÝ$Ô+Ð,<Ñ=Ô=Ðà�ÐÐÝŒÐWÑXÔXÐXàÐØÐÝ+¨M¸;ÍÈGÌLÐYeÔLfÑHgÔHgÑhÔhˆˆØ	Ð	Øˆå :Ø�tÐÐ;Ð/°tÐ;Ð=VÐXYÐ[\ñ!ô !Ðõ
 Ð-¸ÐAÑAÔA€HÝ˜h¨Ð/HÑIÔI€HÝ*Ø
ˆˆq�!ˆf�q˜!�f˜q !˜f q c¨A¨3Ð/Ø9Ð9Ð9Ø'Ð'Ð'ðñ ô Ðð 2Ð1Ð1Ø<Ð<Ð<ðð €Hð
 )�XÐ( Ð(€FÝ�Ð*¨J¸ÐNÐNÀvÐNÐN€EàÐØ×Ò˜g×4Ò4¸hÐSWÐ4ÑXÔXÑYÔYÐYà€Lr3   );rý   Úcollectionsr   Útypingr   r   r   r   r   r:   Útorch.nn.functionalr	   rÌ   rÐ   r
   Úopsr   rö   Útransforms._presetsr   Úutilsr   Ú_apir   r   r   Ú_metar   r   r   r   Úvggr   r   r   Ú r¨   Úanchor_utilsr   Úbackbone_utilsr   r²   r   Ú__all__r   r$  rA   rC   r\   rK   rM   rŠ   r'  rI  rW   rT  r0   ÚIMAGENET1K_FEATURESr   r2   r3   r4   ú<module>rz     sõ  ðØ €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3à €€€Ø Ð Ð Ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ð Ð à #Ð #Ð #Ð #Ð #Ð #Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø (Ð (Ð (Ð (Ð (Ð (Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø $Ð $Ð $Ð $Ð $Ð $Ø CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ø !Ð !Ð !Ð !Ð !Ð !Ø -Ð -Ð -Ð -Ð -Ð -Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø /Ð /Ð /Ð /Ð /Ð /ð Øð€ðð ð ð ð ˜;ñ ô ð ð,9�r”yð 9ð 9ð 9ð 9ð

ð 

ð 

ð 

ð 

ˆbŒiñ 

ô 

ð 

ð"-ð "-ð "-ð "-ð "-�R”Yñ "-ô "-ð "-ðJ2ð 2ð 2ð 2ð 2˜Nñ 2ô 2ð 2ð&ð &ð &ð &ð &˜ñ &ô &ð &ðQð Qð Qð Qð Qˆ"Œ)ñ Qô Qð Qðh
THð THð THð THð TH˜RœYñ THô THð THðn5˜Sð 5¨4ð 5À3ð 5ð 5ð 5ð 5ð( €ÑÔØÐØÐ/Ô7Ð8Ø+¨]Ô-NÐOðñ ô ð /3ØØ!%Ø0=Ô0QØ/3ðhð hð hàÐ*Ô+ðhð ðhð ˜#”ð	hð
 ˜}Ô-ðhð  (¨œ}ðhð ðhð 	ðhð hð hñ	ô ñ Ôð
hð hð hr3   