-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add typing Annotations to detection/utils #4583
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
Conversation
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.
The PR isn't complete. A small headstart for @khushi-411 😃
Definitely @oke-aditya, I'd love to start up with this PR! The explanations you provided are really helpful. |
It worked. Your commit appeared here. |
Yep, Cheers! |
@khushi-411 you would need to use pre-commit hooks to format your code. See the contributing guide https://github.com/pytorch/vision/blob/main/CONTRIBUTING.md#pre-commit-hooks It will automatically format your code to pass python lint CI. I will have a look at PR before end of day, don't worry it's very natural to get a Red from CI, little bit of debugging can fix it. |
@@ -290,7 +285,7 @@ def __call__(self, match_quality_matrix): | |||
if self.allow_low_quality_matches: | |||
all_matches = matches.clone() | |||
else: | |||
all_matches = None | |||
all_matches = None # type: ignore[assignment] |
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.
I think we should ignore this error, as we are directly assigning None to a Tensor object.
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.
Ah, I was stuck at this point. Is there any other method of adding types here?
I read one issue (#40867). That's quite relatable.
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.
I'm not sure if we have a better way as we are assigning all_matches on the fly to be either Tensor or None.
Where could we declare all_matches to be Optional[Tensor] ?
Previously too we had to use such workaround see https://github.com/pytorch/vision/blob/main/torchvision/models/quantization/googlenet.py#L80
cc @pmeier
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.
If Optional[Tensor]
is possible, than we should definitively go for that. Otherwise probably Tensor
and ignore the error here.
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.
Let me have a quick try at that. I will get back in an hour.
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.
Didn't work well, see the below JIT error.
Apart from above comment everything looks good. |
Had a look and the first impression is that all types are correct. I can have a look again if you want tomorrow. |
Yes definitely, thanks a lot @datumbox! |
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.
LGTM after #4583 (comment) is resolved and CI is green. Thanks a lot @oke-aditya and @khushi-411!
Thanks a lot @pmeier! |
Mypy was happy locally Hopefully CI will be all green. Edit: I'm amazed that people in 3 different time zones synced so fast. Hats off to @pmeier @datumbox @khushi-411 ! |
Ok so mpy was happy and JIT wasn't.
So we have no choice but to ignore |
Well for Vasilis and me the time is at least somewhat reasonable whereas for you folks is the middle of the night 😛 |
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.
LGTM, thanks!
Summary: * Start annotating utils * checking * Add annotations at _utils.py * Remove unnecessary comments. * re-checked typings * Update typing * Ignore small error * Use optional tensor * Ignore for JIT Reviewed By: fmassa Differential Revision: D31649971 fbshipit-source-id: 687cd2f5511b0d8cad015b74b60f3af0c108c2b0 Co-authored-by: Khushi Agrawal <[email protected]> Co-authored-by: Vasilis Vryniotis <[email protected]>
* Start annotating utils * checking * Add annotations at _utils.py * Remove unnecessary comments. * re-checked typings * Update typing * Ignore small error * Use optional tensor * Ignore for JIT Co-authored-by: Khushi Agrawal <[email protected]> Co-authored-by: Vasilis Vryniotis <[email protected]>
* Start annotating utils * checking * Add annotations at _utils.py * Remove unnecessary comments. * re-checked typings * Update typing * Ignore small error * Use optional tensor * Ignore for JIT Co-authored-by: Khushi Agrawal <[email protected]> Co-authored-by: Vasilis Vryniotis <[email protected]>
Let's begin #4582
@khushi-411 do you want to take this up? I think you can push to this branch on my fork.
You can clone my forked repo and push changes. They should reflect here.
cc @datumbox