Skip to content

Commit 27c4975

Browse files
committed
Remove lots of code
1 parent adba54f commit 27c4975

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+10
-7706
lines changed

.github/scripts/setup-env.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ case $(uname) in
2323
esac
2424

2525
echo '::group::Create build environment'
26-
# See https://github.com/pytorch/vision/issues/7296 for ffmpeg
2726
conda create \
2827
--name ci \
2928
--quiet --yes \
3029
python="${PYTHON_VERSION}" pip \
3130
ninja cmake \
3231
libpng \
3332
libwebp \
34-
'ffmpeg<4.3'
3533
conda activate ci
3634
conda install --quiet --yes libjpeg-turbo -c pytorch
3735
pip install --progress-bar=off --upgrade setuptools==72.1.0

.github/scripts/unittest.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ echo '::endgroup::'
1414

1515
python test/smoke_test.py
1616

17-
# We explicitly ignore the video tests until we resolve https://github.com/pytorch/vision/issues/8162
18-
pytest --ignore-glob="*test_video*" --ignore-glob="*test_onnx*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 -k "not TestFxFeatureExtraction"
17+
pytest --ignore-glob="*test_onnx*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 -k "not TestFxFeatureExtraction"

.github/workflows/docs.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ jobs:
3434
CONDA_PATH=$(which conda)
3535
eval "$(${CONDA_PATH} shell.bash hook)"
3636
conda activate ci
37-
# FIXME: not sure why we need this. `ldd torchvision/video_reader.so` shows that it
38-
# already links against the one pulled from conda. However, at runtime it pulls from
39-
# /lib64
40-
# Should we maybe always do this in `./.github/scripts/setup-env.sh` so that we don't
41-
# have to pay attention in all other workflows?
42-
export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib:${LD_LIBRARY_PATH}"
4337
4438
cd docs
4539

docs/source/io.rst

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Decoding / Encoding images and videos
2-
=====================================
1+
Decoding / Encoding images
2+
==========================
33

44
.. currentmodule:: torchvision.io
55

66
The :mod:`torchvision.io` module provides utilities for decoding and encoding
7-
images and videos.
7+
images.
88

99
Image Decoding
1010
--------------
@@ -92,7 +92,7 @@ Video - DEPREACTED
9292
.. warning::
9393

9494
DEPRECATED: All the video decoding and encoding capabilities of torchvision
95-
are deprecated from version 0.22 and will be removed in version 0.24. We
95+
are deprecated from version 0.22 and will be removed in version 0.25. We
9696
recommend that you migrate to
9797
`TorchCodec <https://github.com/pytorch/torchcodec>`__, where we'll
9898
consolidate the future decoding/encoding capabilities of PyTorch
@@ -101,19 +101,4 @@ Video - DEPREACTED
101101
:toctree: generated/
102102
:template: function.rst
103103

104-
read_video
105-
read_video_timestamps
106104
write_video
107-
108-
109-
**Fine-grained video API**
110-
111-
In addition to the :mod:`read_video` function, we provide a high-performance
112-
lower-level API for more fine-grained control compared to the :mod:`read_video` function.
113-
It does all this whilst fully supporting torchscript.
114-
115-
.. autosummary::
116-
:toctree: generated/
117-
:template: class.rst
118-
119-
VideoReader

mypy.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ ignore_errors = True
4141

4242
ignore_errors = True
4343

44-
[mypy-torchvision.io.video_reader]
45-
46-
ignore_errors = True
47-
4844
[mypy-torchvision.models.*]
4945

5046
ignore_errors=True

packaging/pre_build_script.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
1717
# Installing webp also installs a non-turbo jpeg, so we uninstall jpeg stuff
1818
# before re-installing them
1919
conda uninstall libjpeg-turbo libjpeg -y
20-
conda install -y ffmpeg=4.2 -c pytorch
2120
conda install -y libjpeg-turbo -c pytorch
2221

2322
# Copy binaries to be included in the wheel distribution
@@ -30,7 +29,7 @@ else
3029

3130
if [[ "$ARCH" == "aarch64" ]]; then
3231
conda install libpng -y
33-
conda install -y ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly
32+
conda install -y libjpeg-turbo -c pytorch-nightly
3433
fi
3534

3635
conda install libwebp -y

packaging/wheel/relocate.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ def patch_linux():
316316
output_dir = osp.join(PACKAGE_ROOT, "dist", ".wheel-process")
317317

318318
image_binary = "image.so"
319-
video_binary = "video_reader.so"
320-
torchvision_binaries = [image_binary, video_binary]
319+
torchvision_binaries = [image_binary, ]
321320
for wheel in wheels:
322321
if osp.exists(output_dir):
323322
shutil.rmtree(output_dir)
@@ -352,8 +351,7 @@ def patch_win():
352351
output_dir = osp.join(PACKAGE_ROOT, "dist", ".wheel-process")
353352

354353
image_binary = "image.pyd"
355-
video_binary = "video_reader.pyd"
356-
torchvision_binaries = [image_binary, video_binary]
354+
torchvision_binaries = [image_binary, ]
357355
for wheel in wheels:
358356
if osp.exists(output_dir):
359357
shutil.rmtree(output_dir)

setup.py

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
USE_WEBP = os.getenv("TORCHVISION_USE_WEBP", "1") == "1"
2323
USE_NVJPEG = os.getenv("TORCHVISION_USE_NVJPEG", "1") == "1"
2424
NVCC_FLAGS = os.getenv("NVCC_FLAGS", None)
25-
# Note: the GPU video decoding stuff used to be called "video codec", which
26-
# isn't an accurate or descriptive name considering there are at least 2 other
27-
# video decoding backends in torchvision. I'm renaming this to "gpu video
28-
# decoder" where possible, keeping user facing names (like the env var below) to
29-
# the old scheme for BC.
30-
USE_GPU_VIDEO_DECODER = os.getenv("TORCHVISION_USE_VIDEO_CODEC", "1") == "1"
31-
# Same here: "use ffmpeg" was used to denote "use cpu video decoder".
32-
USE_CPU_VIDEO_DECODER = os.getenv("TORCHVISION_USE_FFMPEG", "1") == "1"
3325

3426
TORCHVISION_INCLUDE = os.environ.get("TORCHVISION_INCLUDE", "")
3527
TORCHVISION_LIBRARY = os.environ.get("TORCHVISION_LIBRARY", "")
@@ -52,8 +44,6 @@
5244
print(f"{USE_WEBP = }")
5345
print(f"{USE_NVJPEG = }")
5446
print(f"{NVCC_FLAGS = }")
55-
print(f"{USE_CPU_VIDEO_DECODER = }")
56-
print(f"{USE_GPU_VIDEO_DECODER = }")
5747
print(f"{TORCHVISION_INCLUDE = }")
5848
print(f"{TORCHVISION_LIBRARY = }")
5949
print(f"{IS_ROCM = }")
@@ -371,158 +361,6 @@ def make_image_extension():
371361
)
372362

373363

374-
def make_video_decoders_extensions():
375-
print("Building video decoder extensions")
376-
377-
build_without_extensions_msg = "Building without video decoders extensions."
378-
if sys.platform != "linux" or (sys.version_info.major == 3 and sys.version_info.minor == 9):
379-
# FIXME: Building torchvision with ffmpeg on MacOS or with Python 3.9
380-
# FIXME: causes crash. See the following GitHub issues for more details.
381-
# FIXME: https://github.com/pytorch/pytorch/issues/65000
382-
# FIXME: https://github.com/pytorch/vision/issues/3367
383-
print("Can only build video decoder extensions on linux and Python != 3.9")
384-
return []
385-
386-
ffmpeg_exe = shutil.which("ffmpeg")
387-
if ffmpeg_exe is None:
388-
print(f"{build_without_extensions_msg} Couldn't find ffmpeg binary.")
389-
return []
390-
391-
def find_ffmpeg_libraries():
392-
ffmpeg_libraries = {"libavcodec", "libavformat", "libavutil", "libswresample", "libswscale"}
393-
394-
ffmpeg_bin = os.path.dirname(ffmpeg_exe)
395-
ffmpeg_root = os.path.dirname(ffmpeg_bin)
396-
ffmpeg_include_dir = os.path.join(ffmpeg_root, "include")
397-
ffmpeg_library_dir = os.path.join(ffmpeg_root, "lib")
398-
399-
gcc = os.environ.get("CC", shutil.which("gcc"))
400-
platform_tag = subprocess.run([gcc, "-print-multiarch"], stdout=subprocess.PIPE)
401-
platform_tag = platform_tag.stdout.strip().decode("utf-8")
402-
403-
if platform_tag:
404-
# Most probably a Debian-based distribution
405-
ffmpeg_include_dir = [ffmpeg_include_dir, os.path.join(ffmpeg_include_dir, platform_tag)]
406-
ffmpeg_library_dir = [ffmpeg_library_dir, os.path.join(ffmpeg_library_dir, platform_tag)]
407-
else:
408-
ffmpeg_include_dir = [ffmpeg_include_dir]
409-
ffmpeg_library_dir = [ffmpeg_library_dir]
410-
411-
for library in ffmpeg_libraries:
412-
library_found = False
413-
for search_path in ffmpeg_include_dir + TORCHVISION_INCLUDE:
414-
full_path = os.path.join(search_path, library, "*.h")
415-
library_found |= len(glob.glob(full_path)) > 0
416-
417-
if not library_found:
418-
print(f"{build_without_extensions_msg}")
419-
print(f"{library} header files were not found.")
420-
return None, None
421-
422-
return ffmpeg_include_dir, ffmpeg_library_dir
423-
424-
ffmpeg_include_dir, ffmpeg_library_dir = find_ffmpeg_libraries()
425-
if ffmpeg_include_dir is None or ffmpeg_library_dir is None:
426-
return []
427-
428-
print("Found ffmpeg:")
429-
print(f" ffmpeg include path: {ffmpeg_include_dir}")
430-
print(f" ffmpeg library_dir: {ffmpeg_library_dir}")
431-
432-
extensions = []
433-
if USE_CPU_VIDEO_DECODER:
434-
print("Building with CPU video decoder support")
435-
436-
# TorchVision base decoder + video reader
437-
video_reader_src_dir = os.path.join(ROOT_DIR, "torchvision", "csrc", "io", "video_reader")
438-
video_reader_src = glob.glob(os.path.join(video_reader_src_dir, "*.cpp"))
439-
base_decoder_src_dir = os.path.join(ROOT_DIR, "torchvision", "csrc", "io", "decoder")
440-
base_decoder_src = glob.glob(os.path.join(base_decoder_src_dir, "*.cpp"))
441-
# Torchvision video API
442-
videoapi_src_dir = os.path.join(ROOT_DIR, "torchvision", "csrc", "io", "video")
443-
videoapi_src = glob.glob(os.path.join(videoapi_src_dir, "*.cpp"))
444-
# exclude tests
445-
base_decoder_src = [x for x in base_decoder_src if "_test.cpp" not in x]
446-
447-
combined_src = video_reader_src + base_decoder_src + videoapi_src
448-
449-
extensions.append(
450-
CppExtension(
451-
# This is an awful name. It should be "cpu_video_decoder". Keeping for BC.
452-
"torchvision.video_reader",
453-
combined_src,
454-
include_dirs=[
455-
base_decoder_src_dir,
456-
video_reader_src_dir,
457-
videoapi_src_dir,
458-
str(CSRS_DIR),
459-
*ffmpeg_include_dir,
460-
*TORCHVISION_INCLUDE,
461-
],
462-
library_dirs=ffmpeg_library_dir + TORCHVISION_LIBRARY,
463-
libraries=[
464-
"avcodec",
465-
"avformat",
466-
"avutil",
467-
"swresample",
468-
"swscale",
469-
],
470-
extra_compile_args=["-std=c++17"] if os.name != "nt" else ["/std:c++17", "/MP"],
471-
extra_link_args=["-std=c++17" if os.name != "nt" else "/std:c++17"],
472-
)
473-
)
474-
475-
if USE_GPU_VIDEO_DECODER:
476-
# Locating GPU video decoder headers and libraries
477-
# CUDA_HOME should be set to the cuda root directory.
478-
# TORCHVISION_INCLUDE and TORCHVISION_LIBRARY should include the locations
479-
# to the headers and libraries below
480-
if not (
481-
BUILD_CUDA_SOURCES
482-
and CUDA_HOME is not None
483-
and any([os.path.exists(os.path.join(folder, "cuviddec.h")) for folder in TORCHVISION_INCLUDE])
484-
and any([os.path.exists(os.path.join(folder, "nvcuvid.h")) for folder in TORCHVISION_INCLUDE])
485-
and any([os.path.exists(os.path.join(folder, "libnvcuvid.so")) for folder in TORCHVISION_LIBRARY])
486-
and any([os.path.exists(os.path.join(folder, "libavcodec", "bsf.h")) for folder in ffmpeg_include_dir])
487-
):
488-
print("Could not find necessary dependencies. Refer the setup.py to check which ones are needed.")
489-
print("Building without GPU video decoder support")
490-
return extensions
491-
print("Building torchvision with GPU video decoder support")
492-
493-
gpu_decoder_path = os.path.join(CSRS_DIR, "io", "decoder", "gpu")
494-
gpu_decoder_src = glob.glob(os.path.join(gpu_decoder_path, "*.cpp"))
495-
cuda_libs = os.path.join(CUDA_HOME, "lib64")
496-
cuda_inc = os.path.join(CUDA_HOME, "include")
497-
498-
_, extra_compile_args = get_macros_and_flags()
499-
extensions.append(
500-
CUDAExtension(
501-
"torchvision.gpu_decoder",
502-
gpu_decoder_src,
503-
include_dirs=[CSRS_DIR] + TORCHVISION_INCLUDE + [gpu_decoder_path] + [cuda_inc] + ffmpeg_include_dir,
504-
library_dirs=ffmpeg_library_dir + TORCHVISION_LIBRARY + [cuda_libs],
505-
libraries=[
506-
"avcodec",
507-
"avformat",
508-
"avutil",
509-
"swresample",
510-
"swscale",
511-
"nvcuvid",
512-
"cuda",
513-
"cudart",
514-
"z",
515-
"pthread",
516-
"dl",
517-
"nppicc",
518-
],
519-
extra_compile_args=extra_compile_args,
520-
)
521-
)
522-
523-
return extensions
524-
525-
526364
class clean(distutils.command.clean.clean):
527365
def run(self):
528366
with open(".gitignore") as f:
@@ -550,7 +388,6 @@ def run(self):
550388
extensions = [
551389
make_C_extension(),
552390
make_image_extension(),
553-
*make_video_decoders_extensions(),
554391
]
555392

556393
setup(

torchvision/__init__.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
_image_backend = "PIL"
3030

31-
_video_backend = "pyav"
32-
3331

3432
def set_image_backend(backend):
3533
"""
@@ -53,48 +51,6 @@ def get_image_backend():
5351
return _image_backend
5452

5553

56-
def set_video_backend(backend):
57-
"""
58-
Specifies the package used to decode videos.
59-
60-
Args:
61-
backend (string): Name of the video backend. one of {'pyav', 'video_reader'}.
62-
The :mod:`pyav` package uses the 3rd party PyAv library. It is a Pythonic
63-
binding for the FFmpeg libraries.
64-
The :mod:`video_reader` package includes a native C++ implementation on
65-
top of FFMPEG libraries, and a python API of TorchScript custom operator.
66-
It generally decodes faster than :mod:`pyav`, but is perhaps less robust.
67-
68-
.. note::
69-
Building with FFMPEG is disabled by default in the latest `main`. If you want to use the 'video_reader'
70-
backend, please compile torchvision from source.
71-
"""
72-
global _video_backend
73-
if backend not in ["pyav", "video_reader", "cuda"]:
74-
raise ValueError("Invalid video backend '%s'. Options are 'pyav', 'video_reader' and 'cuda'" % backend)
75-
if backend == "video_reader" and not io._HAS_CPU_VIDEO_DECODER:
76-
# TODO: better messages
77-
message = "video_reader video backend is not available. Please compile torchvision from source and try again"
78-
raise RuntimeError(message)
79-
elif backend == "cuda" and not io._HAS_GPU_VIDEO_DECODER:
80-
# TODO: better messages
81-
message = "cuda video backend is not available."
82-
raise RuntimeError(message)
83-
else:
84-
_video_backend = backend
85-
86-
87-
def get_video_backend():
88-
"""
89-
Returns the currently active video backend used to decode videos.
90-
91-
Returns:
92-
str: Name of the video backend. one of {'pyav', 'video_reader'}.
93-
"""
94-
95-
return _video_backend
96-
97-
9854
def _is_tracing():
9955
return torch._C._get_tracing_state()
10056

0 commit comments

Comments
 (0)