Spaces:
Sleeping
Sleeping
Commit ·
3067ed1
1
Parent(s): 86c7cf3
fix: prevent setting torch bridge in preprocess_video for numpy compatibility
Browse files
model.py
CHANGED
|
@@ -120,13 +120,14 @@ def _pad_or_trim(frames: list, clip_length: int) -> list:
|
|
| 120 |
|
| 121 |
|
| 122 |
def preprocess_video(video_bytes: bytes, clip_length: int = CLIP_LENGTH) -> torch.Tensor:
|
| 123 |
-
|
| 124 |
vr = VideoReader(io.BytesIO(video_bytes))
|
| 125 |
total = len(vr)
|
| 126 |
idx = list(range(min(total, clip_length)))
|
| 127 |
if len(idx) < clip_length:
|
| 128 |
idx += [idx[-1]] * (clip_length - len(idx))
|
| 129 |
-
|
|
|
|
| 130 |
frames = [batch[i] for i in range(batch.shape[0])]
|
| 131 |
return _frames_to_tensor(frames)
|
| 132 |
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
def preprocess_video(video_bytes: bytes, clip_length: int = CLIP_LENGTH) -> torch.Tensor:
|
| 123 |
+
# Don't set torch bridge — keep numpy so .asnumpy() works
|
| 124 |
vr = VideoReader(io.BytesIO(video_bytes))
|
| 125 |
total = len(vr)
|
| 126 |
idx = list(range(min(total, clip_length)))
|
| 127 |
if len(idx) < clip_length:
|
| 128 |
idx += [idx[-1]] * (clip_length - len(idx))
|
| 129 |
+
|
| 130 |
+
batch = vr.get_batch(idx).asnumpy() # numpy (T, H, W, C)
|
| 131 |
frames = [batch[i] for i in range(batch.shape[0])]
|
| 132 |
return _frames_to_tensor(frames)
|
| 133 |
|