From 6d737e25ad45cb6fac441bc19c172a666c0e0999 Mon Sep 17 00:00:00 2001 From: Aditya Oke Date: Sat, 16 Oct 2021 00:54:30 +0530 Subject: [PATCH 1/4] Update typing --- torchvision/models/detection/generalized_rcnn.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/torchvision/models/detection/generalized_rcnn.py b/torchvision/models/detection/generalized_rcnn.py index c77c892e63e..f6b5b39f9d0 100644 --- a/torchvision/models/detection/generalized_rcnn.py +++ b/torchvision/models/detection/generalized_rcnn.py @@ -23,7 +23,7 @@ class GeneralizedRCNN(nn.Module): the model """ - def __init__(self, backbone, rpn, roi_heads, transform): + def __init__(self, backbone: nn.Module, rpn: nn.Module, roi_heads: nn.Module, transform: nn.Module) -> None: super(GeneralizedRCNN, self).__init__() self.transform = transform self.backbone = backbone @@ -33,15 +33,20 @@ def __init__(self, backbone, rpn, roi_heads, transform): self._has_warned = False @torch.jit.unused - def eager_outputs(self, losses, detections): - # type: (Dict[str, Tensor], List[Dict[str, Tensor]]) -> Union[Dict[str, Tensor], List[Dict[str, Tensor]]] + def eager_outputs( + self, losses: Dict[str, Tensor], detections: List[Dict[str, Tensor]] + ) -> Union[Dict[str, Tensor], List[Dict[str, Tensor]]]: + if self.training: return losses return detections - def forward(self, images, targets=None): - # type: (List[Tensor], Optional[List[Dict[str, Tensor]]]) -> Tuple[Dict[str, Tensor], List[Dict[str, Tensor]]] + def forward( + self, + images: List[Tensor], + targets: Optional[List[str, Tensor]] = None, + ) -> Union[Tuple[Dict[str, Tensor], List[Dict[str, Tensor]]], Dict[str, Tensor], List[Dict[str, Tensor]]]: """ Args: images (list[Tensor]): images to be processed From 3ba94941e33caa651307059b194e917f063b97a8 Mon Sep 17 00:00:00 2001 From: Aditya Oke Date: Sat, 16 Oct 2021 01:02:20 +0530 Subject: [PATCH 2/4] Fix bug --- torchvision/models/detection/generalized_rcnn.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/torchvision/models/detection/generalized_rcnn.py b/torchvision/models/detection/generalized_rcnn.py index f6b5b39f9d0..d523920de6c 100644 --- a/torchvision/models/detection/generalized_rcnn.py +++ b/torchvision/models/detection/generalized_rcnn.py @@ -34,7 +34,9 @@ def __init__(self, backbone: nn.Module, rpn: nn.Module, roi_heads: nn.Module, tr @torch.jit.unused def eager_outputs( - self, losses: Dict[str, Tensor], detections: List[Dict[str, Tensor]] + self, + losses: Dict[str, Tensor], + detections: List[Dict[str, Tensor]], ) -> Union[Dict[str, Tensor], List[Dict[str, Tensor]]]: if self.training: @@ -45,12 +47,12 @@ def eager_outputs( def forward( self, images: List[Tensor], - targets: Optional[List[str, Tensor]] = None, + targets: Optional[List[Dict[str, Tensor]]] = None, ) -> Union[Tuple[Dict[str, Tensor], List[Dict[str, Tensor]]], Dict[str, Tensor], List[Dict[str, Tensor]]]: """ Args: images (list[Tensor]): images to be processed - targets (list[Dict[Tensor]]): ground-truth boxes present in the image (optional) + 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. From 886af2255ace0634a08cb476dbfc6b385cd5504c Mon Sep 17 00:00:00 2001 From: Aditya Oke Date: Mon, 18 Oct 2021 12:11:56 +0530 Subject: [PATCH 3/4] Unblock mypy --- mypy.ini | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mypy.ini b/mypy.ini index a2733d3ae3b..5d076b2d007 100644 --- a/mypy.ini +++ b/mypy.ini @@ -33,10 +33,6 @@ ignore_errors = True ignore_errors = True -[mypy-torchvision.models.detection.generalized_rcnn] - -ignore_errors = True - [mypy-torchvision.models.detection.faster_rcnn] ignore_errors = True From 10cc41442947626552bf3f908edfcd6ca5378e42 Mon Sep 17 00:00:00 2001 From: Aditya Oke Date: Fri, 29 Oct 2021 00:31:07 +0530 Subject: [PATCH 4/4] Ignore small error --- torchvision/models/detection/generalized_rcnn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/models/detection/generalized_rcnn.py b/torchvision/models/detection/generalized_rcnn.py index bd755167ceb..f02f2b33928 100644 --- a/torchvision/models/detection/generalized_rcnn.py +++ b/torchvision/models/detection/generalized_rcnn.py @@ -104,7 +104,7 @@ def forward( features = OrderedDict([("0", features)]) proposals, proposal_losses = self.rpn(images, features, targets) detections, detector_losses = self.roi_heads(features, proposals, images.image_sizes, targets) - detections = self.transform.postprocess(detections, images.image_sizes, original_image_sizes) + detections = self.transform.postprocess(detections, images.image_sizes, original_image_sizes) # type: ignore[operator] losses = {} losses.update(detector_losses)