Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,7 @@ def test_encode_jpeg(img_path):
buf = io.BytesIO()
pil_img.save(buf, format="JPEG", quality=75)

# pytorch can't read from raw bytes so we go through numpy
pil_bytes = np.frombuffer(buf.getvalue(), dtype=np.uint8)
encoded_jpeg_pil = torch.as_tensor(pil_bytes)
encoded_jpeg_pil = torch.frombuffer(buf.getvalue(), dtype=torch.uint8)

for src_img in [img, img.contiguous()]:
encoded_jpeg_torch = encode_jpeg(src_img, quality=75)
Expand Down
2 changes: 1 addition & 1 deletion test/test_video_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _get_video_tensor(video_dir, video_file):
assert os.path.exists(full_path), "File not found: %s" % full_path

with open(full_path, "rb") as fp:
video_tensor = torch.from_numpy(np.frombuffer(fp.read(), dtype=np.uint8))
video_tensor = torch.frombuffer(fp.read(), dtype=torch.uint8)

return full_path, video_tensor

Expand Down
7 changes: 3 additions & 4 deletions torchvision/io/_video_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from fractions import Fraction
from typing import List, Tuple

import numpy as np
import torch

from .._internally_replaced_utils import _get_extension_path
Expand Down Expand Up @@ -338,7 +337,7 @@ def _read_video_from_memory(
_validate_pts(audio_pts_range)

if not isinstance(video_data, torch.Tensor):
video_data = torch.from_numpy(np.frombuffer(video_data, dtype=np.uint8))
video_data = torch.frombuffer(video_data, dtype=torch.uint8)

result = torch.ops.video_reader.read_video_from_memory(
video_data,
Expand Down Expand Up @@ -378,7 +377,7 @@ def _read_video_timestamps_from_memory(video_data):
is much faster than read_video(...)
"""
if not isinstance(video_data, torch.Tensor):
video_data = torch.from_numpy(np.frombuffer(video_data, dtype=np.uint8))
video_data = torch.frombuffer(video_data, dtype=torch.uint8)
result = torch.ops.video_reader.read_video_from_memory(
video_data,
0, # seek_frame_margin
Expand Down Expand Up @@ -415,7 +414,7 @@ def _probe_video_from_memory(video_data):
This function is torchscriptable
"""
if not isinstance(video_data, torch.Tensor):
video_data = torch.from_numpy(np.frombuffer(video_data, dtype=np.uint8))
video_data = torch.frombuffer(video_data, dtype=torch.uint8)
result = torch.ops.video_reader.probe_video_from_memory(video_data)
vtimebase, vfps, vduration, atimebase, asample_rate, aduration = result
info = _fill_info(vtimebase, vfps, vduration, atimebase, asample_rate, aduration)
Expand Down