CoolFace
Apppublic

Mjolnir65/FasterRCNN

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
generalized_rcnn.cpython-37.pyc51 linesDownload Raw Back to __pycache__
1B

2��h�@sndZddlZddlmZddlmZmZmZmZm	Z	ddl3Z4ddl5mZmZddl
mZGdd�dej�ZdS)	z,6Implements the Generalized R-CNN framework7�N)�OrderedDict)�Dict�List�Optional�Tuple�Union)�nn�Tensor)�_log_api_usage_oncecsPeZdZdZejejejejdd��fdd�Zejj	dd��Z8d9dd	�Z�ZS)�GeneralizedRCNNad10    Main class for Generalized R-CNN.11 12    Args:13        backbone (nn.Module):14        rpn (nn.Module):15        roi_heads (nn.Module): takes the features + the proposals from the RPN and computes16            detections / masks from it.17        transform (nn.Module): performs the data transformation from the inputs to feed into18            the model19    N)�backbone�rpn�	roi_heads�	transform�returncs4t���t|�||_||_||_||_d|_dS)NF)�super�__init__r20rrr
r�_has_warned)�selfrr
rr)�	__class__��>/home/rohit/Desktop/Sem6/CV/q1.2/detection/generalized_rcnn.pyrs21zGeneralizedRCNN.__init__cCs|jr22|S|S)N)�training)r�losses�23detectionsrrr�
eager_outputs&szGeneralizedRCNN.eager_outputsc	CsB|jr�|dkrt�dd�njxh|D]`}|d}t|tj�rjt�t|j�dkoX|jddkd|j�d	��q"t�dd24t|��d	��q"Wg}xT|D]L}|jdd�}t�t|�dkd|jdd����|�|d
|df�q�W|�	||�\}}|dk	�r�x�t25|�D]�\}}|d}|dd�dd�f|dd�dd�fk}	|	���rt�|	jdd��d
d
}26||27�
�}t�dd|�d|�d	���qW|�|j�}t|tj��r�td|fg�}|�|||�\}
}|�||
|j|�\}}|j	�||j|�}i}|�|�|�|�tj���r2|j�s*t�d�d|_||fS|�||�SdS)a28        Args:29            images (list[Tensor]): images to be processed30            targets (list[Dict[str, Tensor]]): ground-truth boxes present in the image (optional)31 32        Returns:33            result (list[BoxList] or dict[Tensor]): the output from the model.34                During training, it returns a dict[Tensor] which contains the losses.35                During testing, it returns list[BoxList] contains additional fields36                like `scores`, `labels` and `mask` (for Mask R-CNN models).37 38        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�39isinstancer	�len�shape�type�appendr�	enumerate�any�where�tolistr�tensorsrr
r�image_sizes�postprocess�update�jit�is_scriptingr�warnings�warnr)r�images�targets�targetr�original_image_sizes�img�val�40target_idx�degenerate_boxes�bb_idx�degen_bb�features�	proposals�proposal_lossesr�detector_lossesrrrr�forward.sV41424344(45464748zGeneralizedRCNN.forward)N)
�__name__�49__module__�__qualname__�__doc__r�Modulerr%r4�unusedrrF�
__classcell__rr)rrrs"50r)rJr6�collectionsr�typingrrrrrr%rr	Ztorchvision.utilsr51rKrrrrr�<module>s