Skip to content

Commit 55f4787

Browse files
authored
Merge branch 'main' into please_dont_modify_this_branch_unless_you_are_just_merging_with_main__
2 parents c5ec30a + 6279faa commit 55f4787

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

packaging/pre_build_script.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ else
3232
conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly
3333
fi
3434

35-
yum install -y libjpeg-turbo-devel libwebp-devel freetype gnutls
35+
conda install libwebp -yq
36+
conda install libjpeg-turbo -c pytorch
37+
yum install -y freetype gnutls
3638
pip install auditwheel
3739
fi
3840

test/test_image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
IS_MACOS = sys.platform == "darwin"
4646
PILLOW_VERSION = tuple(int(x) for x in PILLOW_VERSION.split("."))
4747
WEBP_TEST_IMAGES_DIR = os.environ.get("WEBP_TEST_IMAGES_DIR", "")
48+
# See https://github.com/pytorch/vision/pull/8724#issuecomment-2503964558
49+
ROCM_WEBP_MESSAGE = "ROCM not built with webp support."
4850

4951
# Hacky way of figuring out whether we compiled with libavif/libheif (those are
5052
# currenlty disabled by default)

torchvision/csrc/io/image/cpu/decode_webp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if WEBP_FOUND
55
#include "webp/decode.h"
6+
#include "webp/types.h"
67
#endif // WEBP_FOUND
78

89
namespace vision {
@@ -44,10 +45,12 @@ torch::Tensor decode_webp(
4445

4546
auto decoded_data =
4647
decoding_func(encoded_data_p, encoded_data_size, &width, &height);
48+
4749
TORCH_CHECK(decoded_data != nullptr, "WebPDecodeRGB[A] failed.");
4850

51+
auto deleter = [decoded_data](void*) { WebPFree(decoded_data); };
4952
auto out = torch::from_blob(
50-
decoded_data, {height, width, num_channels}, torch::kUInt8);
53+
decoded_data, {height, width, num_channels}, deleter, torch::kUInt8);
5154

5255
return out.permute({2, 0, 1});
5356
}

torchvision/io/video.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
install PyAV on your system.
2727
"""
2828
)
29+
try:
30+
FFmpegError = av.FFmpegError # from av 14 https://github.com/PyAV-Org/PyAV/blob/main/CHANGELOG.rst
31+
except AttributeError:
32+
FFmpegError = av.AVError
2933
except ImportError:
3034
av = ImportError(
3135
"""\
@@ -155,7 +159,13 @@ def write_video(
155159

156160
for img in video_array:
157161
frame = av.VideoFrame.from_ndarray(img, format="rgb24")
158-
frame.pict_type = "NONE"
162+
try:
163+
frame.pict_type = "NONE"
164+
except TypeError:
165+
from av.video.frame import PictureType # noqa
166+
167+
frame.pict_type = PictureType.NONE
168+
159169
for packet in stream.encode(frame):
160170
container.mux(packet)
161171

@@ -215,7 +225,7 @@ def _read_from_stream(
215225
try:
216226
# TODO check if stream needs to always be the video stream here or not
217227
container.seek(seek_offset, any_frame=False, backward=True, stream=stream)
218-
except av.AVError:
228+
except FFmpegError:
219229
# TODO add some warnings in this case
220230
# print("Corrupted file?", container.name)
221231
return []
@@ -228,7 +238,7 @@ def _read_from_stream(
228238
buffer_count += 1
229239
continue
230240
break
231-
except av.AVError:
241+
except FFmpegError:
232242
# TODO add a warning
233243
pass
234244
# ensure that the results are sorted wrt the pts
@@ -350,7 +360,7 @@ def read_video(
350360
)
351361
info["audio_fps"] = container.streams.audio[0].rate
352362

353-
except av.AVError:
363+
except FFmpegError:
354364
# TODO raise a warning?
355365
pass
356366

@@ -441,10 +451,10 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in
441451
video_time_base = video_stream.time_base
442452
try:
443453
pts = _decode_video_timestamps(container)
444-
except av.AVError:
454+
except FFmpegError:
445455
warnings.warn(f"Failed decoding frames for file {filename}")
446456
video_fps = float(video_stream.average_rate)
447-
except av.AVError as e:
457+
except FFmpegError as e:
448458
msg = f"Failed to open container for {filename}; Caught error: {e}"
449459
warnings.warn(msg, RuntimeWarning)
450460

torchvision/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def draw_bounding_boxes(
260260

261261
if label is not None:
262262
margin = width + 1
263-
draw.text((bbox[0] + margin, bbox[1] + margin), label, fill=label_color, font=txt_font)
263+
draw.text((bbox[0] + margin, bbox[1] + margin), label, fill=label_color, font=txt_font) # type: ignore[arg-type]
264264

265265
out = F.pil_to_tensor(img_to_draw)
266266
if original_dtype.is_floating_point:

0 commit comments

Comments
 (0)