§
    ù²Åjý  ã                   ó„   — d Z 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ZmZ ddlmZ  G d„ d	ej        ¦  «        ZdS )
z,
Implements the Generalized R-CNN framework
é    N)ÚOrderedDict)ÚDictÚListÚOptionalÚTupleÚUnion)ÚnnÚTensoré   )Ú_log_api_usage_oncec            
       ó’   ‡ — e Zd ZdZdej        dej        dej        dej        ddf
ˆ fd„Zej        j	        d	„ ¦   «         Z
dd
„Zˆ xZS )ÚGeneralizedRCNNad  
    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                 ó¬   •— t          ¦   «                              ¦   «          t          | ¦  «         || _        || _        || _        || _        d| _        d S )NF)ÚsuperÚ__init__r   r   r   r   r   Ú_has_warned)Úselfr   r   r   r   Ú	__class__s        €ú^C:\Projects\Historical\venv\Lib\site-packages\torchvision/models/detection/generalized_rcnn.pyr   zGeneralizedRCNN.__init__   sQ   ø€ Ý‰Œ×ÒÑÔÐÝ˜DÑ!Ô!Ð!Ø"ˆŒØ ˆŒØˆŒØ"ˆŒà ˆÔÐÐó    c                 ó   — | j         r|S |S ©N)Útraining)r   ÚlossesÚ
detectionss      r   Úeager_outputszGeneralizedRCNN.eager_outputs&   s   € ð Œ=ð 	ØˆMàÐr   c           	      ó:  — | 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¦  «        }|                      |||¦  «        \  }}|                      |||j        |¦  «        \  }}| j	                             ||j        |¦  «        }i }|                     |¦  «         |                     |¦  «         t          j                             ¦   «         r&| j        st3          j        d¦  «         d| _        ||fS |                      ||¦  «        S )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   ÚforwardzGeneralizedRCNN.forward.   sv  € ð Œ=ð 	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à68ÐØð 	:ð 	:ˆ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Ø%)§X¢X¨f°hÀÑ%HÔ%HÑ"ˆ	�?Ø&*§n¢n°X¸yÈ&ÔJ\Ð^eÑ&fÔ&fÑ#ˆ
�OØ”^×/Ò/°
¸FÔ<NÐPdÑeÔeˆ
àˆØ�Š�oÑ&Ô&Ð&Ø�Š�oÑ&Ô&Ð&åŒ9×!Ò!Ñ#Ô#ð 	:ØÔ#ð (Ý”Ð]Ñ^Ô^Ð^Ø#'�Ô Ø˜:Ð%Ð%à×%Ò% f¨jÑ9Ô9Ð9r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   ÚModuler   r,   r;   Úunusedr!   rM   Ú__classcell__)r   s   @r   r   r      s²   ø€ € € € € ð
ð 
ð! ¤ð !°´ð !ÀrÄyð !Ð]_Ô]fð !Ðkoð !ð !ð !ð !ð !ð !ð „YÔðð ñ ÔððH:ð H:ð H:ð H:ð H:ð H:ð H:ð H:r   r   )rQ   r=   Úcollectionsr   Útypingr   r   r   r   r   r,   r	   r
   Úutilsr   rR   r   © r   r   ú<module>rY      sÉ   ððð ð €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5à €€€Ø Ð Ð Ð Ð Ð Ð Ð à (Ð (Ð (Ð (Ð (Ð (ðg:ð g:ð g:ð g:ð g:�b”iñ g:ô g:ð g:ð g:ð g:r   