-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add typing annotations to detection/generalized_rcnn #4631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d737e2
3ba9494
193834f
886af22
afe34a8
10cc414
5bc863a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,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().__init__() | ||
_log_api_usage_once(self) | ||
self.transform = transform | ||
|
@@ -36,19 +36,26 @@ 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[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. | ||
|
@@ -97,7 +104,7 @@ def forward(self, images, targets=None): | |
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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, what's up with that warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the error.
We pass transform as The I don't know easy way to fix this, maybe we should type |
||
|
||
losses = {} | ||
losses.update(detector_losses) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datumbox This change causes failure in internal tests, check D32216673.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI
This change was done as Union is supported by Torchscript. There isn't a CI failure on main branch. (Probably you are referring to fbcode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prabhat00155 Thanks for flagging, I see it. This is something we should keep in mind for future Annotations and PRs.
Union of a tuple with a non-tuple is likely to break code because of expressions like:
a, b = result
My proposal is to amend the diff on FBcode to either remove the annotation or remove the union (whichever passes all tests) and then sync the change that you will do on FBcode to GH on a cherrypick OR on a new PR (Which ever easier).
Let me know your thoughts on the above and if I can do something to help.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll amend the diff(removing the type annotation).