From f1e2328679aa743b15c12bde2adc4804479da212 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 19 Aug 2024 12:23:33 +0100 Subject: [PATCH] better name --- test/test_io.py | 6 +++--- test/test_video_reader.py | 4 ++-- test/test_videoapi.py | 4 ++-- torchvision/__init__.py | 2 +- torchvision/io/__init__.py | 2 ++ torchvision/io/_video_opt.py | 5 +++-- torchvision/io/video_reader.py | 4 ++-- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/test_io.py b/test/test_io.py index 1b7b7eb15a1..d2950ac9595 100644 --- a/test/test_io.py +++ b/test/test_io.py @@ -63,7 +63,7 @@ def temp_video(num_frames, height, width, fps, lossless=False, video_codec=None, @pytest.mark.skipif( - get_video_backend() != "pyav" and not io._HAS_VIDEO_OPT, reason="video_reader backend not available" + get_video_backend() != "pyav" and not io._HAS_CPU_VIDEO_DECODER, reason="video_reader backend not available" ) @pytest.mark.skipif(av is None, reason="PyAV unavailable") class TestVideo: @@ -77,14 +77,14 @@ def test_write_read_video(self): assert_equal(data, lv) assert info["video_fps"] == 5 - @pytest.mark.skipif(not io._HAS_VIDEO_OPT, reason="video_reader backend is not chosen") + @pytest.mark.skipif(not io._HAS_CPU_VIDEO_DECODER, reason="video_reader backend is not chosen") def test_probe_video_from_file(self): with temp_video(10, 300, 300, 5) as (f_name, data): video_info = io._probe_video_from_file(f_name) assert pytest.approx(2, rel=0.0, abs=0.1) == video_info.video_duration assert pytest.approx(5, rel=0.0, abs=0.1) == video_info.video_fps - @pytest.mark.skipif(not io._HAS_VIDEO_OPT, reason="video_reader backend is not chosen") + @pytest.mark.skipif(not io._HAS_CPU_VIDEO_DECODER, reason="video_reader backend is not chosen") def test_probe_video_from_memory(self): with temp_video(10, 300, 300, 5) as (f_name, data): with open(f_name, "rb") as fp: diff --git a/test/test_video_reader.py b/test/test_video_reader.py index 243aa12fc12..10995424982 100644 --- a/test/test_video_reader.py +++ b/test/test_video_reader.py @@ -11,7 +11,7 @@ from numpy.random import randint from pytest import approx from torchvision import set_video_backend -from torchvision.io import _HAS_VIDEO_OPT +from torchvision.io import _HAS_CPU_VIDEO_DECODER try: @@ -263,7 +263,7 @@ def _get_video_tensor(video_dir, video_file): @pytest.mark.skipif(av is None, reason="PyAV unavailable") -@pytest.mark.skipif(_HAS_VIDEO_OPT is False, reason="Didn't compile with ffmpeg") +@pytest.mark.skipif(_HAS_CPU_VIDEO_DECODER is False, reason="Didn't compile with ffmpeg") class TestVideoReader: def check_separate_decoding_result(self, tv_result, config): """check the decoding results from TorchVision decoder""" diff --git a/test/test_videoapi.py b/test/test_videoapi.py index dc878ca9f8c..aabcf6407f7 100644 --- a/test/test_videoapi.py +++ b/test/test_videoapi.py @@ -7,7 +7,7 @@ import torchvision from pytest import approx from torchvision.datasets.utils import download_url -from torchvision.io import _HAS_VIDEO_OPT, VideoReader +from torchvision.io import _HAS_CPU_VIDEO_DECODER, VideoReader # WARNING: these tests have been skipped forever on the CI because the video ops @@ -62,7 +62,7 @@ def fate(name, path="."): } -@pytest.mark.skipif(_HAS_VIDEO_OPT is False, reason="Didn't compile with ffmpeg") +@pytest.mark.skipif(_HAS_CPU_VIDEO_DECODER is False, reason="Didn't compile with ffmpeg") class TestVideoApi: @pytest.mark.skipif(av is None, reason="PyAV unavailable") @pytest.mark.parametrize("test_video", test_videos.keys()) diff --git a/torchvision/__init__.py b/torchvision/__init__.py index 857625a783c..5d06156c25f 100644 --- a/torchvision/__init__.py +++ b/torchvision/__init__.py @@ -72,7 +72,7 @@ def set_video_backend(backend): global _video_backend if backend not in ["pyav", "video_reader", "cuda"]: raise ValueError("Invalid video backend '%s'. Options are 'pyav', 'video_reader' and 'cuda'" % backend) - if backend == "video_reader" and not io._HAS_VIDEO_OPT: + if backend == "video_reader" and not io._HAS_CPU_VIDEO_DECODER: # TODO: better messages message = "video_reader video backend is not available. Please compile torchvision from source and try again" raise RuntimeError(message) diff --git a/torchvision/io/__init__.py b/torchvision/io/__init__.py index 780b6ab333e..afb88829f56 100644 --- a/torchvision/io/__init__.py +++ b/torchvision/io/__init__.py @@ -10,6 +10,7 @@ _HAS_GPU_VIDEO_DECODER = False from ._video_opt import ( + _HAS_CPU_VIDEO_DECODER, _HAS_VIDEO_OPT, _probe_video_from_file, _probe_video_from_memory, @@ -49,6 +50,7 @@ "_read_video_from_memory", "_read_video_timestamps_from_memory", "_probe_video_from_memory", + "_HAS_CPU_VIDEO_DECODER", "_HAS_VIDEO_OPT", "_HAS_GPU_VIDEO_DECODER", "_read_video_clip_from_memory", diff --git a/torchvision/io/_video_opt.py b/torchvision/io/_video_opt.py index 2bd7d11929e..69af045e773 100644 --- a/torchvision/io/_video_opt.py +++ b/torchvision/io/_video_opt.py @@ -10,10 +10,11 @@ try: _load_library("video_reader") - _HAS_VIDEO_OPT = True + _HAS_CPU_VIDEO_DECODER = True except (ImportError, OSError): - _HAS_VIDEO_OPT = False + _HAS_CPU_VIDEO_DECODER = False +_HAS_VIDEO_OPT = _HAS_CPU_VIDEO_DECODER # For BC default_timebase = Fraction(0, 1) diff --git a/torchvision/io/video_reader.py b/torchvision/io/video_reader.py index c00723a4534..505909fd984 100644 --- a/torchvision/io/video_reader.py +++ b/torchvision/io/video_reader.py @@ -7,9 +7,9 @@ from ..utils import _log_api_usage_once -from ._video_opt import _HAS_VIDEO_OPT +from ._video_opt import _HAS_CPU_VIDEO_DECODER -if _HAS_VIDEO_OPT: +if _HAS_CPU_VIDEO_DECODER: def _has_video_opt() -> bool: return True