-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Added missing typing annotations in datasets/video_utils #4172
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.
@frgfm the mypy
failures are related:
torchvision/datasets/kinetics.py:137: error: Argument 4 to "VideoClips" has
incompatible type "Optional[float]"; expected "Optional[int]" [arg-type]
frame_rate,
^
Found 1 error in 1 file (checked 110 source files)
Hi @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.
Thanks @frgfm for the update! I have some comments 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.
Three minor things left.
@@ -320,22 +326,22 @@ def get_clip(self, idx): | |||
end_pts = clip_pts[-1].item() | |||
video, audio, info = read_video(video_path, start_pts, end_pts) | |||
else: | |||
info = _probe_video_from_file(video_path) | |||
video_fps = info.video_fps | |||
_info = _probe_video_from_file(video_path) |
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.
Since we now have
Line 6 in 59baae9
allow_redefinition = True |
this renaming is probably not needed anymore. Could you check?
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 did and unfortunately it's still an issue
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.
It seems even with allow_redefinition
, mypy
is stricter than I thought:
Allows variables to be redefined with an arbitrary type, as long as the redefinition is in the same block and nesting level as the original definition. [emphasis mine]
Since that is not the case here, we need to keep your fix.
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 when CI is happy. Thanks a lot @frgfm!
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 @frgfm. I have a few comments.
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 All the question can be answered with "Because we are using a static analyzer on dynamic code". Usually when we encounter weirdness, it is either because mypy
is unnecessarily strict or we actually have spaghetti / unsafe code that should be refactored. Given that the latter is usually not obvious, we opted to simply silence mypy
where it complains, since the code works as is.
If you want to see all the errors, you can checkout this PR locally, revert the changes you had questions about and run mypy
.
) Summary: * style: Fixed last missing typing annotation * style: Fixed typing * style: Fixed remaining typing annotations * style: Fixed typing * style: Fixed typing * refactor: Removed unused import * Update torchvision/datasets/video_utils.py Reviewed By: NicolasHug Differential Revision: D32694309 fbshipit-source-id: c9aadbdc09d15de9a2a6a2b9b6a99edd829d89f2 Co-authored-by: Philip Meier <[email protected]> Co-authored-by: Prabhat Roy <[email protected]>
Following up on #2025, this PR adds missing typing annotations in datasets/video_utils.py.
Any feedback is welcome!
cc @pmeier