
    QЦi                         S r SSKrSSKJr  SSKJrJrJrJrJ	r	  SSK
r
SSK
JrJr  SSKJr   " S S	\R                  5      rg)
z,
Implements the Generalized R-CNN framework
    N)OrderedDict)DictListOptionalTupleUnion)nnTensor   )_log_api_usage_oncec            
          ^  \ rS rSrSrS\R                  S\R                  S\R                  S\R                  SS4
U 4S	 jjr\R                  R                  S
 5       rSS jrSrU =r$ )GeneralizedRCNN   a@  
Main class for Generalized R-CNN.

Args:
    backbone (nn.Module):
    rpn (nn.Module):
    roi_heads (nn.Module): takes the features + the proposals from the RPN and computes
        detections / masks from it.
    transform (nn.Module): performs the data transformation from the inputs to feed into
        the model
backbonerpn	roi_heads	transformreturnNc                 v   > [         TU ]  5         [        U 5        X@l        Xl        X l        X0l        SU l        g )NF)super__init__r   r   r   r   r   _has_warned)selfr   r   r   r   	__class__s        l/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/models/detection/generalized_rcnn.pyr   GeneralizedRCNN.__init__   s2    D!" "     c                 ,    U R                   (       a  U$ U$ N)training)r   losses
detectionss      r   eager_outputsGeneralizedRCNN.eager_outputs&   s     ==Mr   c           	      :   U R                   (       a  Uc  [        R                  " SS5        OU 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  pU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#                  XU5      u  pU R%                  XUR&                  U5      u  nnU R                  R)                  XR&                  U5      n0 nUR+                  U5        UR+                  U5        [        R,                  R/                  5       (       a2  U R0                  (       d  [2        R4                  " S5        SU l        UU4$ U R7                  UU5      $ )a  
Args:
    images (list[Tensor]): images to be processed
    targets (list[Dict[str, Tensor]]): ground-truth boxes present in the image (optional)

Returns:
    result (list[BoxList] or dict[Tensor]): the output from the model.
        During training, it returns a dict[Tensor] which contains the losses.
        During testing, it returns list[BoxList] contains additional fields
        like `scores`, `labels` and `mask` (for Mask R-CNN models).

NFz0targets should not be none when in training modeboxes      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      )dimzLAll bounding boxes should have positive height and width. Found invalid box z for target at index 0z=RCNN always returns a (Losses, Detections) tuple in scriptingT)r    torch_assert
isinstancer
   lenshapetypeappendr   	enumerateanywheretolistr   tensorsr   r   r   image_sizespostprocessupdatejitis_scriptingr   warningswarnr#   )r   imagestargetstargetr&   original_image_sizesimgval
target_idxdegenerate_boxesbb_idxdegen_bbfeatures	proposalsproposal_lossesr"   detector_lossesr!   s                     r   forwardGeneralizedRCNN.forward.   s    ==e%WX%F"7OE!%66,1Jekk"o6JXY^YdYdXeefg
 e/_`dej`k_llm-no & 79C))BC.CMMCA\]`]f]fgigj]k\lm !''QQ(89  ..9 &/&8"
w#(AB<5BQB<#? #''))"[[)9)=)=!)=)DEaHKF,1M,@,@,BHMM..6Z7LZLXY[ '9 ==0h--"S(O#45H%)XXf%H"	&*nnX&J\J\^e&f#
O^^//
<N<NPde
o&o&99!!####]^#' :%%%%fj99r   )r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r	   Moduler   r/   r>   unusedr#   rP   __static_attributes____classcell__)r   s   @r   r   r      sn    
! ! !ryy !]_]f]f !ko ! YY H: H:r   r   )rV   r@   collectionsr   typingr   r   r   r   r   r/   r	   r
   utilsr   rW   r    r   r   <module>r_      s3     # 5 5   (g:bii g:r   