Unverified Commit 72686211 authored by YosuaMichael's avatar YosuaMichael Committed by GitHub
Browse files

Suppress warning when calling torch.frombuffer with non-writable buffer (#6971)


Co-authored-by: default avatarJoao Gomes <jdsgomes@fb.com>
parent bfb474b9
...@@ -336,7 +336,10 @@ def _read_video_from_memory( ...@@ -336,7 +336,10 @@ def _read_video_from_memory(
_validate_pts(audio_pts_range) _validate_pts(audio_pts_range)
if not isinstance(video_data, torch.Tensor): if not isinstance(video_data, torch.Tensor):
video_data = torch.frombuffer(video_data, dtype=torch.uint8) with warnings.catch_warnings():
# Ignore the warning because we actually dont modify the buffer in this function
warnings.filterwarnings("ignore", message="The given buffer is not writable")
video_data = torch.frombuffer(video_data, dtype=torch.uint8)
result = torch.ops.video_reader.read_video_from_memory( result = torch.ops.video_reader.read_video_from_memory(
video_data, video_data,
...@@ -378,7 +381,10 @@ def _read_video_timestamps_from_memory( ...@@ -378,7 +381,10 @@ def _read_video_timestamps_from_memory(
is much faster than read_video(...) is much faster than read_video(...)
""" """
if not isinstance(video_data, torch.Tensor): if not isinstance(video_data, torch.Tensor):
video_data = torch.frombuffer(video_data, dtype=torch.uint8) with warnings.catch_warnings():
# Ignore the warning because we actually dont modify the buffer in this function
warnings.filterwarnings("ignore", message="The given buffer is not writable")
video_data = torch.frombuffer(video_data, dtype=torch.uint8)
result = torch.ops.video_reader.read_video_from_memory( result = torch.ops.video_reader.read_video_from_memory(
video_data, video_data,
0, # seek_frame_margin 0, # seek_frame_margin
...@@ -416,7 +422,10 @@ def _probe_video_from_memory( ...@@ -416,7 +422,10 @@ def _probe_video_from_memory(
This function is torchscriptable This function is torchscriptable
""" """
if not isinstance(video_data, torch.Tensor): if not isinstance(video_data, torch.Tensor):
video_data = torch.frombuffer(video_data, dtype=torch.uint8) with warnings.catch_warnings():
# Ignore the warning because we actually dont modify the buffer in this function
warnings.filterwarnings("ignore", message="The given buffer is not writable")
video_data = torch.frombuffer(video_data, dtype=torch.uint8)
result = torch.ops.video_reader.probe_video_from_memory(video_data) result = torch.ops.video_reader.probe_video_from_memory(video_data)
vtimebase, vfps, vduration, atimebase, asample_rate, aduration = result vtimebase, vfps, vduration, atimebase, asample_rate, aduration = result
info = _fill_info(vtimebase, vfps, vduration, atimebase, asample_rate, aduration) info = _fill_info(vtimebase, vfps, vduration, atimebase, asample_rate, aduration)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment