From 158b40071bffcd20b46528b181a10452cdff1f02 Mon Sep 17 00:00:00 2001 From: pedro-bento Date: Mon, 5 Oct 2026 21:17:09 +0100 Subject: [PATCH] fix(media): copy TransNetV2 frames to silence the read-only tensor warning np.frombuffer() returns a read-only array; torch.from_numpy warned on every scene detection. np.array(copy=True) makes it writable without changing dtype or values. --- clipwright/media/scene_detection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clipwright/media/scene_detection.py b/clipwright/media/scene_detection.py index 037504b..40edf4f 100644 --- a/clipwright/media/scene_detection.py +++ b/clipwright/media/scene_detection.py @@ -106,7 +106,9 @@ def _detect_transnetv2(video_path): threshold = float(os.environ.get("TRANSNETV2_THRESHOLD", "0.5")) with _TN2_LOCK, torch.no_grad(): - tensor = torch.from_numpy(np.ascontiguousarray(frames)).to(model.device) + # frombuffer() yields a read-only array; copy so torch stops warning and + # writing to the tensor is well-defined. + tensor = torch.from_numpy(np.array(frames, copy=True)).to(model.device) single_frame_pred, _ = model.predict_frames(tensor, quiet=True) single_frame_pred = single_frame_pred.cpu() del tensor