You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When importing torchvision, a number of libraries are imported by default for more niche functionality of the library. To improve import time, I would favor delaying those imports to when they are needed
Motivation, pitch
In my case, it is the av library in particular that contributes to the import time:
(this assumes that torch, dynamo and onnx are already imported).
The import of av can easily be avoided as it is not needed by default.
Alternatives
No response
Additional context
I checked the code and I found this code here:
try:
import av
av.logging.set_level(av.logging.ERROR)
if not hasattr(av.video.frame.VideoFrame, "pict_type"):
av = ImportError(
"""\
Your version of PyAV is too old for the necessary video operations in torchvision.
If you are on Python 3.5, you will have to build from source (the conda-forge
packages are not up-to-date). See
https://github.com/mikeboers/PyAV#installation for instructions on how to
install PyAV on your system.
"""
)
except ImportError:
av = ImportError(
"""\
PyAV is not installed, and is necessary for the video operations in torchvision.
See https://github.com/mikeboers/PyAV#installation for instructions on how to
install PyAV on your system.
"""
)
The pict_type got added somewhere in the 0.5 range (released around 2020), 6.0 followed shortly. So I would suggest to change this test to not import av but the use importlib to check the version which would make this go away. This applies both to torchvision/io/video_reader.py as well as torchvision/io/video.py. I also wonder whether the logging call is still required given so much has changed since this code was written.
The text was updated successfully, but these errors were encountered:
Hi @bschindler , thanks for the report. Happy to consider a PR to import av only when the io module is imported. Or... to only import io when io is needed. Or both...
Considering the cluncky way by which we load the extensions and make them available, I suspect this is the kind of work that sounds a lot easier than it actually is, but we'll see.
I briefly looked at it, a major issue is this line in the init file of torchvision:
from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils
This unconditionally imports io, making it part of the public interface. I could remove it from there but that would be a breaking change. Would you be in favor of that?
馃殌 The feature
When importing torchvision, a number of libraries are imported by default for more niche functionality of the library. To improve import time, I would favor delaying those imports to when they are needed
Motivation, pitch
In my case, it is the av library in particular that contributes to the import time:
(this assumes that torch, dynamo and onnx are already imported).
The import of
av
can easily be avoided as it is not needed by default.Alternatives
No response
Additional context
I checked the code and I found this code here:
The
pict_type
got added somewhere in the 0.5 range (released around 2020), 6.0 followed shortly. So I would suggest to change this test to not import av but the useimportlib
to check the version which would make this go away. This applies both totorchvision/io/video_reader.py
as well astorchvision/io/video.py
. I also wonder whether the logging call is still required given so much has changed since this code was written.The text was updated successfully, but these errors were encountered: