-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Added typing annotations to io/_video_opts #4173
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.
Thanks for the PR @frgfm. Unfortunately this breaks torch.jit
. Relevant test failure from test_probe_video_from_memory_script - test.test_video_reader.TestVideoReader
E RuntimeError:
E Unknown type name 'np.ndarray':
E File "/root/project/torchvision/io/_video_opt.py", line 432
E def _probe_video_from_memory(
E video_data: Union[torch.Tensor, np.ndarray],
E ~~~~~~~~~~ <--- HERE
E ) -> VideoMetaData:
E """
Oh, should I remove the typing for this function only then @pmeier? |
The problem here is that I think the way forward is to try to eliminate the |
Apart from the |
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.
Hey @frgfm and sorry for the delay.
Apart from the
Union
issue withtorch.jit
Until this is fixed upstream, there is nothing we can do about it.
I had to ignore assignment I couldn't get to work at the end of the file
I've answered inline with some more comments.
…to video-opt-typing
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 @frgfm!
torchvision/io/_video_opt.py
Outdated
@@ -438,15 +447,20 @@ def _probe_video_from_memory(video_data): | |||
return info | |||
|
|||
|
|||
def _convert_to_sec(start_pts, end_pts, pts_unit, time_base): | |||
def _convert_to_sec(start_pts: float, end_pts: float, pts_unit: str, time_base: Fraction) -> Tuple[float, float, str]: |
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 that start_pts
, end_pts
, *pts*
switch between ints and floats in different methods. It's worth checking that in all signatures where we declare them as ints are indeed always ints. That might be easier to do with a debugger.
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.
As mentioned in the other comment, there is no clear dtype in
torch::List<torch::Tensor> read_video_from_file( |
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.
Sorry I missed the other comment. I understand it's not straightforward to identify the types. That's why I think finding out what they are and annotating the code-base is useful. Nevertheless if we fail to annotate them correctly (say they are floats and we mark them as ints) it's going to be really confusing.
Can we confirm the types of the various pts vars by running the unit-tests and putting a debugger to observe their materialized types?
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!
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.
Two minor things left from my side. LGTM, when the other open comments are resolved and CI is happy. Thanks a lot @frgfm!
Hey @prabhat00155! You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py |
Summary: * style: Added typing annotations * style: Fixed lint * style: Fixed typing * chore: Updated mypy.ini * style: Fixed typing * chore: Updated mypy.ini * style: Fixed typing compatibility with jit * style: Fixed typing * style: Fixed typing * style: Fixed missing import * style: Fixed typing of __iter__ * style: Fixed typing * style: Fixed lint * style: Finished typing * style: ufmt the file * style: Removed unnecessary typing * style: Fixed typing of iterator Reviewed By: NicolasHug Differential Revision: D32694320 fbshipit-source-id: afdd8c0a70cfdba91a5c349a5961051b993185a1 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 io/_video_opts.py.
Any feedback is welcome!