Commit ·
58e91f5
1
Parent(s): addc08f
Replace torchvision.io.read_video with a PyAV-based shim
Browse filestorchvision>=0.26 (auto-installed alongside torch 2.11.0) removed the
public read_video/write_video API entirely from torchvision.io in OSS
builds, breaking TARO onset extraction with ImportError. av (PyAV) was
already a pinned dependency, so decode frames directly with it instead.
- TARO/onset_util.py +16 -1
TARO/onset_util.py
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
-
from torchvision.io import read_video
|
| 4 |
import os
|
| 5 |
from einops import rearrange
|
| 6 |
import torchvision.transforms as transforms
|
| 7 |
from cavp_util import reencode_video_with_diff_fps
|
| 8 |
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def extract_onset(video_path, onset_model, tmp_path, device="cuda"):
|
| 11 |
"""Extract onset features from video using a pre-trained onset detection model."""
|
| 12 |
# Preprocess the video frames
|
|
|
|
| 1 |
+
import av
|
| 2 |
import torch
|
| 3 |
import torch.nn as nn
|
|
|
|
| 4 |
import os
|
| 5 |
from einops import rearrange
|
| 6 |
import torchvision.transforms as transforms
|
| 7 |
from cavp_util import reencode_video_with_diff_fps
|
| 8 |
|
| 9 |
|
| 10 |
+
def read_video(path, pts_unit="sec", output_format="TCHW"):
|
| 11 |
+
"""Minimal PyAV-based stand-in for torchvision.io.read_video (removed from
|
| 12 |
+
the public torchvision.io API in torchvision>=0.26). Returns a (T, C, H, W)
|
| 13 |
+
uint8 frame tensor to match the subset of the old API this module relies on."""
|
| 14 |
+
container = av.open(path)
|
| 15 |
+
frames = [
|
| 16 |
+
torch.from_numpy(frame.to_ndarray(format="rgb24"))
|
| 17 |
+
for frame in container.decode(video=0)
|
| 18 |
+
]
|
| 19 |
+
container.close()
|
| 20 |
+
video = torch.stack(frames, dim=0) if frames else torch.empty(0, 0, 0, 3, dtype=torch.uint8)
|
| 21 |
+
video = video.permute(0, 3, 1, 2).contiguous() # (T, H, W, C) -> (T, C, H, W)
|
| 22 |
+
return video, None, None
|
| 23 |
+
|
| 24 |
+
|
| 25 |
def extract_onset(video_path, onset_model, tmp_path, device="cuda"):
|
| 26 |
"""Extract onset features from video using a pre-trained onset detection model."""
|
| 27 |
# Preprocess the video frames
|