ó
    Eñi q  ã                   óÎ  • S SK r S SKJr  S SKJrJr  S SKrS SKJs  J	r
  S SKJrJr  SSKJr  SSKJr  SSKJr  S	S
KJrJrJr  S	SKJr  S	SKJrJr  S	SKJrJrJr  SSK Jr!  SSK"J#r#  SSK$J%r%  SSK&J'r'  SS/r( " S S\5      r)S\RT                  4S jr+ " S S\RT                  5      r, " S S\RT                  5      r- " S S\-5      r. " S S\-5      r/ " S  S!\RT                  5      r0 " S" S#\RT                  5      r1S$\S%\2S&\34S' jr4\" 5       \" S(\)Rj                  4S)\Rl                  4S*9SS+S\Rl                  SS,.S-\\)   S.\2S/\\3   S0\\   S1\\3   S2\S3\04S4 jj5       5       r7g)5é    N)ÚOrderedDict)ÚAnyÚOptional)Ú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                   óB   • \ rS rSr\" S\S\SSSSS00S	S
SS.S9r\rSr	g)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Úmeta© N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r
   r   ÚCOCO_V1ÚDEFAULTÚ__static_attributes__r+   ó    Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/models/detection/ssd.pyr   r      sG   † ÙØPØ"à"Ø*ØØeàØ˜tð!ðð
 Ø!Ønñ
ñ€Gð$ ƒGr3   Úconvc                 ó`  • U R                  5        Hš  n[        U[        R                  5      (       d  M$  [        R                  R
                  R                  UR                  5        UR                  c  Mf  [        R                  R
                  R                  UR                  S5        Mœ     g )Ng        )
ÚmodulesÚ
isinstancer   ÚConv2dÚtorchÚinitÚxavier_uniform_ÚweightÚbiasÚ	constant_)r5   Úlayers     r4   Ú_xavier_initrA   2   sc   € Ø—‘–ˆÜ�eœRŸY™Y×'Ó'Ü�H‰H�M‰M×)Ñ)¨%¯,©,Ô7Ø�z‰zÓ%Ü—‘—‘×'Ñ'¨¯
©
°CÖ8ò	  r3   c                   óf   ^ • \ rS rSrS\\   S\\   S\4U 4S jjrS\\   S\\	\4   4S jr
S	rU =r$ )
ÚSSDHeadé:   Úin_channelsÚnum_anchorsÚnum_classesc                 ód   >• [         TU ]  5         [        XU5      U l        [	        X5      U l        g ©N)ÚsuperÚ__init__ÚSSDClassificationHeadÚclassification_headÚSSDRegressionHeadÚregression_head)ÚselfrE   rF   rG   Ú	__class__s       €r4   rK   ÚSSDHead.__init__;   s+   ø€ Ü‰ÑÔÜ#8¸ÐS^Ó#_ˆÔ Ü0°ÓJˆÕr3   ÚxÚreturnc                 óH   • U R                  U5      U R                  U5      S.$ )N)Úbbox_regressionÚ
cls_logits)rO   rM   )rP   rS   s     r4   ÚforwardÚSSDHead.forward@   s(   € à#×3Ñ3°AÓ6Ø×2Ñ2°1Ó5ñ
ð 	
r3   )rM   rO   )r,   r-   r.   r/   ÚlistÚintrK   r   ÚdictÚstrrX   r2   Ú__classcell__©rQ   s   @r4   rC   rC   :   sO   ø† ðK D¨¡Ið K¸DÀ¹Ið KÐTW÷ Kð

˜˜f™ð 
¨$¨s°F¨{Ñ*;÷ 
ò 
r3   rC   c                   óv   ^ • \ rS rSrS\R
                  S\4U 4S jjrS\S\S\4S jr	S\
\   S\4S	 jrS
rU =r$ )ÚSSDScoringHeadéG   Úmodule_listÚnum_columnsc                 ó:   >• [         TU ]  5         Xl        X l        g rI   )rJ   rK   rc   rd   )rP   rc   rd   rQ   s      €r4   rK   ÚSSDScoringHead.__init__H   s   ø€ Ü‰ÑÔØ&ÔØ&Õr3   rS   ÚidxrT   c                 ó¢   • [        U R                  5      nUS:  a  X#-  nUn[        U R                  5       H  u  pVXR:X  d  M  U" U5      nM     U$ )zZ
This is equivalent to self.module_list[idx](x),
but torchscript doesn't support this yet
r   )Úlenrc   Ú	enumerate)rP   rS   rg   Ú
num_blocksÚoutÚiÚmodules          r4   Ú_get_result_from_module_listÚ+SSDScoringHead._get_result_from_module_listM   sT   € ô
 ˜×)Ñ)Ó*ˆ
Ø�‹7ØÑˆCØˆÜ" 4×#3Ñ#3Ö4‰IˆAØ�xÙ˜Q“i’ñ 5ð ˆ
r3   c                 óZ  • / n[        U5       H†  u  p4U R                  XC5      nUR                  u  pgp‰UR                  USU R                  X‰5      nUR                  SSSSS5      nUR                  USU R                  5      nUR                  U5        Mˆ     [        R                  " USS9$ )Néÿÿÿÿr   r   é   r   r   ©Údim)
rj   ro   ÚshapeÚviewrd   ÚpermuteÚreshapeÚappendr:   Úcat)
rP   rS   Úall_resultsrm   ÚfeaturesÚresultsÚNÚ_ÚHÚWs
             r4   rX   ÚSSDScoringHead.forward[   sŸ   € Øˆä$ Qž<‰KˆAØ×7Ñ7¸ÓDˆGð !Ÿ™‰JˆA�!Ø—l‘l 1 b¨$×*:Ñ*:¸AÓAˆGØ—o‘o a¨¨A¨q°!Ó4ˆGØ—o‘o a¨¨T×-=Ñ-=Ó>ˆGà×Ñ˜wÖ'ñ (ô �yŠy˜¨!Ñ,Ð,r3   )rc   rd   )r,   r-   r.   r/   r   Ú
ModuleListr[   rK   r   ro   rZ   rX   r2   r^   r_   s   @r4   ra   ra   G   sP   ø† ð' B§M¡Mð 'À÷ 'ð
¨fð ¸3ð À6ô ð-˜˜f™ð -¨&÷ -ò -r3   ra   c                   óD   ^ • \ rS rSrS\\   S\\   S\4U 4S jjrSrU =r$ )rL   él   rE   rF   rG   c           
      óÜ   >• [         R                  " 5       n[        X5       H-  u  pVUR                  [         R                  " XSU-  SSS95        M/     [        U5        [        TU ]  XC5        g )Nr   r   ©Úkernel_sizeÚpadding©r   r„   Úziprz   r9   rA   rJ   rK   )rP   rE   rF   rG   rW   ÚchannelsÚanchorsrQ   s          €r4   rK   ÚSSDClassificationHead.__init__m   sW   ø€ Ü—]’]“_ˆ
Ü!$ [Ö!>ÑˆHØ×ÑœbŸiši¨ÀÑ2GÐUVÐ`aÑbÖcñ "?ä�ZÔ Ü‰Ñ˜Õ1r3   r+   ©	r,   r-   r.   r/   rZ   r[   rK   r2   r^   r_   s   @r4   rL   rL   l   s+   ø† ð2 D¨¡Ið 2¸DÀ¹Ið 2ÐTW÷ 2õ 2r3   rL   c                   ó@   ^ • \ rS rSrS\\   S\\   4U 4S jjrSrU =r$ )rN   éu   rE   rF   c           
      óà   >• [         R                  " 5       n[        X5       H.  u  pEUR                  [         R                  " USU-  SSS95        M0     [        U5        [        TU ]  US5        g )Nrs   r   r   rˆ   r‹   )rP   rE   rF   Úbbox_regr�   rŽ   rQ   s         €r4   rK   ÚSSDRegressionHead.__init__v   sW   ø€ Ü—=’=“?ˆÜ!$ [Ö!>ÑˆHØ�O‰OœBŸIšI h°°G±ÈÐTUÑVÖWñ "?ä�XÔÜ‰Ñ˜ 1Õ%r3   r+   r�   r_   s   @r4   rN   rN   u   s#   ø† ð& D¨¡Ið &¸DÀ¹I÷ &õ &r3   rN   c                   óz  ^ • \ rS rSrSr\R                  \R                  S.r         S"S\	R                  S\S\\\4   S\S\\\      S	\\\      S
\\	R                     S\S\S\S\S\S\S\4U 4S jjjr\R(                  R*                  S\\\4   S\\\\4      S\\\\4   \\\\4      4   4S j5       rS\\\\4      S\\\4   S\\   S\\   S\\\4   4
S jr S#S\\   S\\\\\4         S\\\\4   \\\\4      4   4S jjrS\\\4   S\\   S\\\\4      S\\\\4      4S  jrS!rU =r$ )$ÚSSDé~   a™  
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_matcherÚbackboneÚanchor_generatorÚsizerG   Ú
image_meanÚ	image_stdÚheadÚscore_threshÚ
nms_threshÚdetections_per_imgÚ
iou_threshÚtopk_candidatesÚpositive_fractionÚkwargsc                 óä  >• [         TU ]  5         [        U 5        Xl        X l        [
        R                  " SS9U l        Uc«  [        US5      (       a  UR                  nO[
        R                  " X5      n[        U5      [        UR                  5      :w  a.  [        S[        U5       S[        UR                  5       S35      eU R                  R                  5       n[        UUU5      nXpl        [
        R"                  " U5      U l        Uc  / SQnUc  / SQn['        [)        U5      [+        U5      XV4S	US
.UD6U l        X€l        X�l        X l        XÀl        SU-
  U-  U l        SU l        g )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)rJ   rK   r   r›   rœ   Ú	det_utilsÚBoxCoderr™   Úhasattrr¬   Úretrieve_out_channelsri   Úaspect_ratiosÚ
ValueErrorÚnum_anchors_per_locationrC   r    Ú
SSDMatcherrš   r   ÚminÚmaxÚ	transformr¡   r¢   r£   r¥   Úneg_to_pos_ratioÚ_has_warned)rP   r›   rœ   r�   rG   rž   rŸ   r    r¡   r¢   r£   r¤   r¥   r¦   r§   r¬   rF   rQ   s                    €r4   rK   ÚSSD.__init__º   sŒ  ø€ ô" 	‰ÑÔÜ˜DÔ!à Œà 0Ôä"×+Ò+Ð4JÑKˆŒà‰<Ü�x ×0Ñ0Ø'×4Ñ4‘ä(×>Ò>¸xÓN�ä�<Ó ¤CÐ(8×(FÑ(FÓ$GÓGÜ ØKÌCÐP\ÓL]ÐK^ð  _`ô  adð  eu÷  eCñ  eCó  aDð  `Eð  EFð  Góð ð ×/Ñ/×HÑHÓJˆKÜ˜<¨°kÓBˆDØŒ	ä )× 4Ò 4°ZÓ @ˆÔàÑÚ.ˆJØÑÚ-ˆIÜ1Ü�‹I”s˜4“y *ð
ØHIÐVZñ
Ø^dñ
ˆŒð )ÔØ$ŒØ"4ÔØ.ÔØ!$Ð'8Ñ!8Ð<MÑ MˆÔð !ˆÕr3   ÚlossesÚ
detectionsrT   c                 ó,   • U R                   (       a  U$ U$ rI   )Útraining)rP   r¾   r¿   s      r4   Úeager_outputsÚSSD.eager_outputsö   s   € ð �=�=ØˆMàÐr3   ÚtargetsÚhead_outputsrŽ   Úmatched_idxsc           	      óØ  • US   nUS   nSn/ n/ n	[        XXcU5       GH  u  n
nnnn[        R                  " US:¬  5      S   nXï   nUUR                  5       -  nU
S   U   nX¿S S 24   nXßS S 24   nU R                  R                  UU5      nUR                  [        R                  R                  R                  UUSS95        [        R                  " UR                  S5      4U
S   R                  U
S   R                  S9nU
S   U   UU'   U	R                  U5        GM     [        R                  " U5      n[        R                  " U	5      n	UR                  S	5      n[        R                   " UR#                  S	U5      U	R#                  S	5      S
S9R#                  U	R                  5       5      nU	S:„  nU R$                  UR'                  SSS9-  nUR)                  5       n[+        S5      * UU'   UR-                  SSS9u  nnUR-                  S5      S   U:  n[/        SU5      nUR'                  5       U-  UU   R'                  5       UU   R'                  5       -   U-  S.$ )NrV   rW   r   r	   Úsum)Ú	reductionÚlabels©ÚdtypeÚdevicerr   Únoner   T)ÚkeepdimÚinf)Ú
descending)rV   Úclassification)rŒ   r:   ÚwhereÚnumelr™   Úencode_singlerz   r   Ú
functionalÚsmooth_l1_lossÚzerosr�   rÌ   rÍ   ÚstackÚFÚcross_entropyrw   r»   rÈ   ÚcloneÚfloatÚsortr¹   )rP   rÄ   rÅ   rŽ   rÆ   rV   rW   Ú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_targetrG   Úcls_lossÚforeground_idxsÚnum_negativeÚnegative_lossÚvaluesrg   Úbackground_idxsr   s                                r4   Úcompute_lossÚSSD.compute_lossÿ   s£  € ð 'Ð'8Ñ9ˆØ! ,Ñ/ˆ
ð ˆØˆ	Øˆô �¨:À×Mñ
ØØ%Ø ØØ"ô ).¯ªÐ4JÈaÑ4OÓ(PÐQRÑ(SÐ%Ø0FÑ0aÐ-ØÐ?×EÑEÓGÑGˆNð *;¸7Ñ)CÐDeÑ)fÐ&Ø(AÒ]^ÐB^Ñ(_Ð%Ø 1ÊQÐ2NÑ OÐØ $§¡× <Ñ <Ð=WÐYjÓ kÐØ×ÑÜ—‘×#Ñ#×2Ñ2Ð3LÐN_ÐkpÐ2Ðqôô
 !&§¢Ø%×*Ñ*¨1Ó-Ð/Ø'¨Ñ1×7Ñ7Ø(¨Ñ2×9Ñ9ñ!Ðð
 <MÈXÑ;VØ1ñ<ÐÐ7Ñ8ð ×ÑÐ0×1ñ1 Nô4 —K’K 	Ó*ˆ	Ü—k’k +Ó.ˆð !—o‘o bÓ)ˆÜ—?’? :§?¡?°2°{Ó#CÀ[×EUÑEUÐVXÓEYÐekÑl×qÑqØ×ÑÓó
ˆð
 &¨™/ˆØ×,Ñ,¨×/BÑ/BÀ1ÈdÐ/BÐ/SÑSˆà Ÿ™Ó(ˆÜ*/°«,¨ˆ�oÑ&Ø#×(Ñ(¨°tÐ(Ð<‰ˆ�àŸ(™( 1›+ a™.¨<Ñ7ˆä��>Ó"ˆà(Ÿ}™}›°Ñ2Ø'¨Ñ8×<Ñ<Ó>ÀÈ/ÑAZ×A^ÑA^ÓA`Ñ`ÐdeÑeñ
ð 	
r3   Úimagesc           
      ó4  • U R                   (       aÂ  Uc  [        R                  " SS5        O§U H¡  nUS   n[        U[        R                  5      (       aV  [        R                  " [        UR                  5      S:H  =(       a    UR                  S   S:H  SUR                   S35        M}  [        R                  " SS	[        U5       S35        M£     / nU H^  nUR                  S
S  n[        R                  " [        U5      S:H  SUR                  S
S   35        UR                  US   US   45        M`     U R                  X5      u  pUb   [        U5       H‘  u  pƒUS   nUS S 2SS 24   US S 2S S24   :*  n	U	R                  5       (       d  M8  [        R                  " U	R                  SS95      S   S   n
XJ   R                  5       n[        R                  " SSU SU S35        M“     U R                  UR                  5      n[        U[        R                  5      (       a  [!        SU4/5      n[#        UR%                  5       5      nU R'                  U5      nU R)                  X5      n0 n/ nU R                   (       aè  / nUc  [        R                  " SS5        GO[+        Xâ5       H§  u  nnUS   R-                  5       S:X  aP  UR                  [        R.                  " UR1                  S5      4S[        R2                  UR4                  S95        Mm  [6        R8                  " US   U5      nUR                  U R;                  U5      5        M©     U R=                  X-UU5      nOCU R?                  XÞUR@                  5      nU R                  RC                  UUR@                  U5      n[        RD                  RG                  5       (       a2  U RH                  (       d  [J        RL                  " S5        SU l$        UU4$ U RO                  UU5      $ )NFz0targets should not be none when in training moder	   r   rr   rs   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   rt   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   ri   rv   Útyperz   rº   rj   ÚanyrÓ   Útolistr›   Útensorsr   rZ   rð   r    rœ   rŒ   rÔ   Úfullr�   Úint64rÍ   Úbox_opsÚbox_iourš   rò   Úpostprocess_detectionsÚimage_sizesÚpostprocessÚjitÚis_scriptingr¼   ÚwarningsÚwarnrÂ   )rP   rô   rÄ   Útargetr	   Úoriginal_image_sizesÚimgÚvalÚ
target_idxÚdegenerate_boxesÚbb_idxÚdegen_bbr}   rÅ   rŽ   r¾   r¿   rÆ   rå   râ   Úmatch_quality_matrixs                        r4   rX   ÚSSD.forwardF  s®  € ð �=�=Ø‰Ü—’˜eÐ%WÕXã%�FØ" 7™O�EÜ! %¬¯©×6Ñ6ÜŸšÜ §¡Ó,°Ñ1×J°e·k±kÀ"±oÈÑ6JØXÐY^×YdÑYdÐXeÐefÐgöô
 Ÿš eÐ/_Ô`dÐejÓ`kÐ_lÐlmÐ-nÖoñ &ð 79ÐÛˆCØ—)‘)˜B˜C�.ˆCÜ�MŠMÜ�C“˜A‘Ø\Ð]`×]fÑ]fÐgiÐgjÐ]kÐ\lÐmôð !×'Ñ'¨¨Q©°°Q±Ð(8Ö9ñ ð Ÿ.™.¨Ó9‰ˆð ÑÜ&/°Ö&8Ñ"�
Ø˜w™�Ø#(ª¨A©B¨¡<°5º¸B¸Q¸B¸±<Ñ#?Ð Ø#×'Ñ'×)Ó)Ü"Ÿ[š[Ð)9×)=Ñ)=À!Ð)=Ð)DÓEÀaÑHÈÑK�FØ,1©M×,@Ñ,@Ó,B�HÜ—M’MØð.Ø.6¨ZÐ7LÈZÈLÐXYð[öñ '9ð —=‘= §¡Ó0ˆÜ�h¤§¡×-Ñ-Ü" S¨( OÐ#4Ó5ˆHä˜Ÿ™Ó)Ó*ˆð —y‘y Ó*ˆð ×'Ñ'¨Ó9ˆàˆØ.0ˆ
Ø�=�=ØˆLØ‰Ü—’˜eÐ%WÖXä<?ÀÖ<QÑ8Ð%Ð'8Ø(¨Ñ1×7Ñ7Ó9¸QÓ>Ø$×+Ñ+Ü!ŸJšJØ!2×!7Ñ!7¸Ó!:Ð <¸bÌÏÉÐ\m×\tÑ\tñôñ
 !ä+2¯?ª?Ð;LÈWÑ;UÐWhÓ+iÐ(Ø ×'Ñ'¨×(=Ñ(=Ð>RÓ(SÖTñ =Rð ×*Ñ*¨7À'È<ÓX‘à×4Ñ4°\ÈF×L^ÑL^Ó_ˆJØŸ™×3Ñ3°JÀ×@RÑ@RÐThÓiˆJä�9‰9×!Ñ!×#Ñ#Ø×#×#Ü—’Ð\Ô]Ø#'�Ô Ø˜:Ð%Ð%Ø×!Ñ! &¨*Ó5Ð5r3   Úimage_anchorsÚimage_shapesc                 óÂ  • US   n[         R                  " US   SS9nUR                  S5      nUR                  n/ n[	        XEX#5       GH‘  u  pšp¼U R
                  R                  X›5      n	[        R                  " Xœ5      n	/ n/ n/ n[        SU5       H¶  nU
S S 2U4   nUU R                  :„  nUU   nU	U   n[        R                  " UU R                  S5      nUR                  U5      u  nnUU   nUR                  U5        UR                  U5        UR                  [         R"                  " UU[         R$                  US95        M¸     [         R&                  " USS9n[         R&                  " USS9n[         R&                  " USS9n[        R(                  " XÞXðR*                  5      nUS U R,                   nUR                  UU   UU   UU   S.5        GM”     U$ )	NrV   rW   rr   rt   r   r   )Ú
fill_valuerÌ   rÍ   )r	   ÚscoresrÊ   )rÚ   Úsoftmaxr�   rÍ   rŒ   r™   Údecode_singler   Úclip_boxes_to_imageÚranger¡   r°   Ú	_topk_minr¥   Útopkrz   r:   Ú	full_likerÿ   r{   Úbatched_nmsr¢   r£   )rP   rÅ   r  r  rV   Úpred_scoresrG   rÍ   r¿   r	   r  rŽ   Úimage_shapeÚimage_boxesÚimage_scoresÚimage_labelsÚlabelÚscoreÚ	keep_idxsÚboxÚnum_topkÚidxsÚkeeps                          r4   r  ÚSSD.postprocess_detectionsž  sÝ  € ð 'Ð'8Ñ9ˆÜ—i’i ¨\Ñ :ÀÑCˆà!×&Ñ& rÓ*ˆØ×#Ñ#ˆà.0ˆ
ä36°ÐUb×3qÑ/ˆE˜7Ø—N‘N×0Ñ0°Ó@ˆEÜ×/Ò/°ÓCˆEàˆKØˆLØˆLÜ˜q +Ö.�Øšq %˜xÑ(�à! D×$5Ñ$5Ñ5�	Ø˜iÑ(�Ø˜IÑ&�ô %×.Ò.¨u°d×6JÑ6JÈAÓN�Ø#Ÿj™j¨Ó2‘��tØ˜$‘i�à×"Ñ" 3Ô'Ø×#Ñ# EÔ*Ø×#Ñ#¤E§O¢O°EÀeÔSX×S^ÑS^ÐgmÑ$nÖoñ /ô   Ÿ)š) K°QÑ7ˆKÜ Ÿ9š9 \°qÑ9ˆLÜ Ÿ9š9 \°qÑ9ˆLô ×&Ò& {À,×P_ÑP_Ó`ˆDØÐ1˜$×1Ñ1Ð2ˆDà×Ñà(¨Ñ.Ø*¨4Ñ0Ø*¨4Ñ0ñ÷ñ? 4rðL Ðr3   )r¼   rœ   r›   r™   r£   r    r»   r¢   rš   r¡   r¥   rº   )	NNNg{®Gáz„?gÍÌÌÌÌÌÜ?éÈ   g      à?i�  g      Ð?rI   )r,   r-   r.   r/   Ú__doc__r°   r±   ÚMatcherÚ__annotations__r   ÚModuler   Útupler[   r   rZ   rÝ   r   rK   r:   r  Úunusedr\   r]   r   rÂ   rò   rX   r  r2   r^   r_   s   @r4   r—   r—   ~   s‡  ø† ñ4ðn ×'Ñ'Ø%×-Ñ-ñ€Oð -1Ø+/Ø$(Ø"Ø Ø"%ØØ"Ø#'ñ:!à—)‘)ð:!ð .ð:!ð �C˜�H‰oð	:!ð
 ð:!ð ˜T %™[Ñ)ð:!ð ˜D ™KÑ(ð:!ð �r—y‘yÑ!ð:!ð ð:!ð ð:!ð  ð:!ð ð:!ð ð:!ð !ð:!ð ÷:!ð :!ðx ‡Y�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
ðP RVñ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ðp1Ø   f Ñ-ð1Ø>BÀ6¹lð1ØZ^Ð_dÐehÐjmÐemÑ_nÑZoð1à	ˆd�3˜�;ÑÑ	 ÷1ò 1r3   r—   c                   ód   ^ • \ rS rSrS\R
                  S\4U 4S jjrS\S\	\
\4   4S jrSrU =r$ )	ÚSSDFeatureExtractorVGGiÒ  r›   Úhighresc                 óÊ  >• [         TU ]  5         S [        U5       5       u    p4pSSX   l        [        R
                  " [        R                  " S5      S-  5      U l        [        R                  " US U 6 U l
        [        R                  " [        R                  " [        R                  " SSSS9[        R                  " SS	9[        R                  " SSS
SSS9[        R                  " SS	95      [        R                  " [        R                  " SSSS9[        R                  " SS	9[        R                  " SSS
SSS9[        R                  " SS	95      [        R                  " [        R                  " SSSS9[        R                  " SS	9[        R                  " SSS
S9[        R                  " SS	95      [        R                  " [        R                  " SSSS9[        R                  " SS	9[        R                  " SSS
S9[        R                  " SS	95      /5      nU(       at  UR                  [        R                  " [        R                  " SSSS9[        R                  " SS	9[        R                  " SSSS9[        R                  " SS	95      5        [        U5        [        R                  " [        R                   " S
SSSS9[        R                  " SSS
SSS9[        R                  " SS	9[        R                  " SSSS9[        R                  " SS	95      n[        U5        UR#                  S[        R                  " / XS QUP76 5        X`l        g )Nc              3   ól   #   • U  H*  u  p[        U[        R                  5      (       d  M&  Uv •  M,     g 7frI   )r8   r   Ú	MaxPool2d)Ú.0rm   r@   s      r4   Ú	<genexpr>Ú2SSDFeatureExtractorVGG.__init__.<locals>.<genexpr>Ö  s(   é € Ð.xÒAT±X°QÔXbÐchÔjl×jvÑjv×Xw¯q©qÒATùs   ‚%4«	4Ti   é   i   é   r   )r‰   )Úinplacer   r   )r‰   rŠ   Ústrideé€   rs   F)r‰   r@  rŠ   Ú	ceil_modeé   )rE   r¬   r‰   rŠ   Údilation)rE   r¬   r‰   r   rr   )rJ   rK   rj   rB  r   Ú	Parameterr:   ÚonesÚscale_weightÚ
Sequentialr}   r„   r9   ÚReLUrz   rA   r9  ÚinsertÚextra)	rP   r›   r6  r€   Úmaxpool3_posÚmaxpool4_posrK  ÚfcrQ   s	           €r4   rK   ÚSSDFeatureExtractorVGG.__init__Ó  s›  ø€ Ü‰ÑÔá.xÄÈ8ÔATÓ.xÑ+ˆˆ1˜Lð ,0ˆÑÔ(ô ŸLšL¬¯ª°C«¸2Ñ)=Ó>ˆÔô Ÿš x°°Ð'>Ð?ˆŒô —’ä—’Ü—I’I˜d C°QÑ7Ü—G’G DÑ)Ü—I’I˜c 3°A¸qÈÑKÜ—G’G DÑ)ó	ô —’Ü—I’I˜c 3°AÑ6Ü—G’G DÑ)Ü—I’I˜c 3°A¸qÈÑKÜ—G’G DÑ)ó	ô —’Ü—I’I˜c 3°AÑ6Ü—G’G DÑ)Ü—I’I˜c 3°AÑ6Ü—G’G DÑ)ó	ô —’Ü—I’I˜c 3°AÑ6Ü—G’G DÑ)Ü—I’I˜c 3°AÑ6Ü—G’G DÑ)ó	ð'ó
ˆö8 à�L‰LÜ—’Ü—I’I˜c 3°AÑ6Ü—G’G DÑ)Ü—I’I˜c 3°AÑ6Ü—G’G DÑ)ó	ôô 	�UÔä�]Š]Ü�LŠL Q¨q¸!ÀuÑMÜ�IŠI #°DÀaÐQRÐ]^Ñ_Ü�GŠG˜DÑ!Ü�IŠI $°TÀqÑIÜ�GŠG˜DÑ!ó
ˆô 	�RÔØ�‰ØÜ�MŠMð Ø rÐ*ðàòô	
ð �
r3   rS   rT   c           	      ó`  • U R                  U5      nU R                  R                  SSSS5      [        R                  " U5      -  nU/nU R
                   H  nU" U5      nUR                  U5        M     [        [        U5       VVs/ s H  u  pV[        U5      U4PM     snn5      $ s  snnf )Nr   rr   )
r}   rG  rw   rÚ   Ú	normalizerK  rz   r   rj   r]   )rP   rS   ÚrescaledÚoutputÚblockrm   Úvs          r4   rX   ÚSSDFeatureExtractorVGG.forward  s•   € à�M‰M˜!ÓˆØ×$Ñ$×)Ñ)¨!¨R°°AÓ6¼¿ºÀQ»ÑGˆØ�ˆð —Z”ZˆEÙ�a“ˆAØ�M‰M˜!Öñ  ô ´I¸fÔ4EÔFÒ4E©D¨AœS ›V Q›KÑ4EÒFÓGÐGùÓFs   Â	B*
)rK  r}   rG  )r,   r-   r.   r/   r   r1  ÚboolrK   r   r\   r]   rX   r2   r^   r_   s   @r4   r5  r5  Ò  sC   ø† ðF §¡ð F°T÷ FðPH˜ð H D¨¨f¨Ñ$5÷ Hò Hr3   r5  r›   r6  Útrainable_layersc           	      óÚ  • U R                   n S/[        U 5       VVs/ s H(  u  p4[        U[        R                  5      (       d  M&  UPM*     snnS S -   n[        U5      n[        R                  " SUs=:*  =(       a    U:*  Os  SU SU 35        US:X  a  [        U 5      OXVU-
     nU S U  H+  nUR                  5        H  nUR                  S5        M     M-     [        X5      $ s  snnf )Nr   rr   z,trainable_layers should be in the range [0, z]. Instead got F)r}   rj   r8   r   r9  ri   r:   rù   Ú
parametersÚrequires_grad_r5  )	r›   r6  rX  rm   ÚbÚstage_indicesÚ
num_stagesÚfreeze_beforeÚ	parameters	            r4   Ú_vgg_extractorra  )  sá   € Ø× Ñ €Hà�C¬°8Ô)<Ô\Ò)<¡ Ä
È1ÌbÏlÉl×@[Ÿ1Ñ)<Ò\Ð]`Ð^`ÐaÑa€MÜ�]Ó#€Jô 
‡M‚MØ	Ð×+Ó+ Ô+Ø
6°z°lÀ/ÐRbÐQcÐdôð &6¸Ó%:”C˜”MÀÐ[kÑNkÑ@l€Mà�n�}Ó%ˆØŸ™žˆIØ×$Ñ$ UÖ+ó (ñ &ô " (Ó4Ð4ùó ]s   �%C'ÁC'Ú
pretrainedÚpretrained_backbone)r«   Úweights_backboneT)r«   ÚprogressrG   rd  Útrainable_backbone_layersr«   re  rG   rd  rf  r§   rT   c                 ó  • [         R                  U 5      n [        R                  " U5      nSU;   a  [        R                  " S5        U b&  Sn[        SU[        U R                  S   5      5      nOUc  Sn[        U SL=(       d    USLUSS5      n[        X1S	9n[        US
U5      n[        S/SS/SS/SS/S/S/// SQ/ SQS9n/ SQ/ SQS.n0 UEUEn[        XgSU40 UD6n	U b  U	R                  U R                  USS95        U	$ )a|  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.NrG   r!   é[   é   rs   )r«   re  Fr   r   )gìQ¸…ë±?g333333Ã?g…ëQ¸Õ?gR¸…ëQà?g®Gázæ?g×£p=
×ë?gÍÌÌÌÌÌð?)é   é   é    é@   éd   é,  )ÚscalesÚsteps)g;pÎˆÒÞÞ?gÌ°�N]Ý?g|
€ñÚ?)çp?rr  rr  )rž   rŸ   )ro  ro  T)re  Ú
check_hash)r   Úverifyr   r  r  r   ri   r*   r   r   ra  r   r—   Úload_state_dictÚget_state_dict)
r«   re  rG   rd  rf  r§   r›   rœ   ÚdefaultsÚmodels
             r4   r   r   =  sC  € ôR #×)Ñ)¨'Ó2€GÜ$×+Ò+Ð,<Ó=Ðà�ÓÜ�ŠÐWÔXàÑØÐÜ+¨M¸;ÌÈGÏLÉLÐYeÑLfÓHgÓh‰Ø	Ñ	Øˆä :Ø�tÐ×;Ð/°tÐ;Ð=VÐXYÐ[\ó!Ðô
 Ð-ÑA€HÜ˜h¨Ð/HÓI€HÜ*Ø
ˆˆq�!ˆf�q˜!�f˜q !˜f q c¨A¨3Ð/Ú9Ú'ñÐò 2Ú<ñ€Hð
 )�XÐ( Ð(€FÜ�¨J¸ÑNÀvÑN€EàÑØ×Ñ˜g×4Ñ4¸hÐSWÐ4ÐXÔYà€Lr3   )8r  Úcollectionsr   Útypingr   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   r1  rA   rC   ra   rL   rN   r—   r5  rW  r[   ra  r0   ÚIMAGENET1K_FEATURESr   r+   r3   r4   Ú<module>r‡     sŸ  ðÛ Ý #ß  ã ß Ð ß å #Ý 2Ý (ß 7Ñ 7Ý $ß Cß +Ñ +Ý !Ý -Ý 6Ý /ð Øð€ô˜;ô ð,9�r—y‘yô 9ô

ˆb�i‰iô 

ô"-�R—Y‘Yô "-ôJ2˜Nô 2ô&˜ô &ôQˆ"�)‰)ô Qôh
TH˜RŸY™Yô THðn5˜Sð 5¨4ð 5À3ô 5ñ( ÓÙØÐ/×7Ñ7Ð8Ø+¨]×-NÑ-NÐOñð /3ØØ!%Ø0=×0QÑ0QØ/3òhàÐ*Ñ+ðhð ðhð ˜#‘ð	hð
 ˜}Ñ-ðhð  (¨™}ðhð ðhð 	ôhó	ó ñ
hr3   