Skip to content

Commit

Permalink
2024-12-03 nightly release (6279faa)
Browse files Browse the repository at this point in the history
  • Loading branch information
pytorchbot committed Dec 3, 2024
1 parent f620859 commit 5ab44fd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packaging/pre_build_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ else
conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly
fi

yum install -y libjpeg-turbo-devel libwebp-devel freetype gnutls
conda install libwebp -yq
conda install libjpeg-turbo -c pytorch
yum install -y freetype gnutls
pip install auditwheel
fi

Expand Down
2 changes: 2 additions & 0 deletions test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
IS_MACOS = sys.platform == "darwin"
PILLOW_VERSION = tuple(int(x) for x in PILLOW_VERSION.split("."))
WEBP_TEST_IMAGES_DIR = os.environ.get("WEBP_TEST_IMAGES_DIR", "")
# See https://github.com/pytorch/vision/pull/8724#issuecomment-2503964558
ROCM_WEBP_MESSAGE = "ROCM not built with webp support."

# Hacky way of figuring out whether we compiled with libavif/libheif (those are
# currenlty disabled by default)
Expand Down
5 changes: 4 additions & 1 deletion torchvision/csrc/io/image/cpu/decode_webp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if WEBP_FOUND
#include "webp/decode.h"
#include "webp/types.h"
#endif // WEBP_FOUND

namespace vision {
Expand Down Expand Up @@ -44,10 +45,12 @@ torch::Tensor decode_webp(

auto decoded_data =
decoding_func(encoded_data_p, encoded_data_size, &width, &height);

TORCH_CHECK(decoded_data != nullptr, "WebPDecodeRGB[A] failed.");

auto deleter = [decoded_data](void*) { WebPFree(decoded_data); };
auto out = torch::from_blob(
decoded_data, {height, width, num_channels}, torch::kUInt8);
decoded_data, {height, width, num_channels}, deleter, torch::kUInt8);

return out.permute({2, 0, 1});
}
Expand Down
22 changes: 16 additions & 6 deletions torchvision/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
install PyAV on your system.
"""
)
try:
FFmpegError = av.FFmpegError # from av 14 https://github.com/PyAV-Org/PyAV/blob/main/CHANGELOG.rst
except AttributeError:
FFmpegError = av.AVError
except ImportError:
av = ImportError(
"""\
Expand Down Expand Up @@ -155,7 +159,13 @@ def write_video(

for img in video_array:
frame = av.VideoFrame.from_ndarray(img, format="rgb24")
frame.pict_type = "NONE"
try:
frame.pict_type = "NONE"
except TypeError:
from av.video.frame import PictureType # noqa

frame.pict_type = PictureType.NONE

for packet in stream.encode(frame):
container.mux(packet)

Expand Down Expand Up @@ -215,7 +225,7 @@ def _read_from_stream(
try:
# TODO check if stream needs to always be the video stream here or not
container.seek(seek_offset, any_frame=False, backward=True, stream=stream)
except av.AVError:
except FFmpegError:
# TODO add some warnings in this case
# print("Corrupted file?", container.name)
return []
Expand All @@ -228,7 +238,7 @@ def _read_from_stream(
buffer_count += 1
continue
break
except av.AVError:
except FFmpegError:
# TODO add a warning
pass
# ensure that the results are sorted wrt the pts
Expand Down Expand Up @@ -350,7 +360,7 @@ def read_video(
)
info["audio_fps"] = container.streams.audio[0].rate

except av.AVError:
except FFmpegError:
# TODO raise a warning?
pass

Expand Down Expand Up @@ -441,10 +451,10 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in
video_time_base = video_stream.time_base
try:
pts = _decode_video_timestamps(container)
except av.AVError:
except FFmpegError:
warnings.warn(f"Failed decoding frames for file {filename}")
video_fps = float(video_stream.average_rate)
except av.AVError as e:
except FFmpegError as e:
msg = f"Failed to open container for {filename}; Caught error: {e}"
warnings.warn(msg, RuntimeWarning)

Expand Down
2 changes: 1 addition & 1 deletion torchvision/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def draw_bounding_boxes(

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

out = F.pil_to_tensor(img_to_draw)
if original_dtype.is_floating_point:
Expand Down

0 comments on commit 5ab44fd

Please sign in to comment.