-
Notifications
You must be signed in to change notification settings - Fork 7k
Type annotations for torchvision.ops #2331
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
Thanks for the PR! Unfortunately, torchscript currently doesn't support Also, if a function argument is not annotated, torchscript assumes that the argument is a Tensor, so for the functions that are missing type annotations you can safely annotate them with Tensor. Can you look into fixing this? |
torchvision/ops/boxes.py
Outdated
@@ -5,7 +5,7 @@ | |||
|
|||
|
|||
@torch.jit.script | |||
def nms(boxes, scores, iou_threshold): | |||
def nms(boxes: Tensor, scores: Tensor, iou_threshold: float) -> Tensor: | |||
# type: (Tensor, Tensor, float) -> Tensor |
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.
Can you remove the comment-style type annotations if you add the type annotations inline?
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.
Sure, I have it in the local repo, will push it soon.
Thanks for the fast review! I have locally updated the code, but still have minor issues before pushing it.
What to do with
Is this for functions nested in |
No, this is for all functions in torchvision which support torchscript.
As I mentioned in my previous comment, if there is no type annotation for an argument, torchscript assumes the argument is a tensor, so for |
Hi, Test failures look weird, and might be due to the fact that CircleCI is running on your account. Let me have a look to understand what is going on. cc @seemethere for thoughts |
@iamvukasin I think the reason this is happening is because you have enabled builds for your fork on CircleCI. Could you go and disable builds on your fork
|
@seemethere Definitely the problem was that the builds had been running with my CirceCI plan. I have stopped any further builds by following your guide. |
@iamvukasin Can you try rebasing this PR on top of master to try running new CI jobs? |
Codecov Report
@@ Coverage Diff @@
## master #2331 +/- ##
=======================================
Coverage 70.69% 70.70%
=======================================
Files 94 94
Lines 7839 7841 +2
Branches 1221 1221
=======================================
+ Hits 5542 5544 +2
Misses 1925 1925
Partials 372 372
Continue to review full report at Codecov.
|
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 a lot!
I have one minor comment that I think could be fixed in a follow-up PR, but let's merge this as is as it's already a nice improvement.
def __init__(self, num_features, eps=0., n=None): | ||
def __init__( | ||
self, | ||
num_features: Tuple[int, ...], |
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.
nit: I would have expected num_features
to be an int
, not a tuple with a varying number of elements.
* Add type annotations for torchvision.ops * Fix type annotations for torchvision.ops * Fix typo in import * Fix undefined name in FeaturePyramidNetwork
Addresses #2025