Candle commited on
Commit ·
8b689fc
1
Parent(s): 3830a3f
stuff
Browse files- detect_scene.py +17 -17
detect_scene.py
CHANGED
|
@@ -7,7 +7,7 @@ import re
|
|
| 7 |
|
| 8 |
SCENE_CUT_THRESHOLD = 0.09
|
| 9 |
data_dir = Path("data/animations")
|
| 10 |
-
files = sorted(data_dir.glob("sample-
|
| 11 |
|
| 12 |
def get_best_device():
|
| 13 |
if torch.cuda.is_available():
|
|
@@ -18,6 +18,19 @@ def get_best_device():
|
|
| 18 |
else:
|
| 19 |
return torch.device("cpu")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def save_prediction_plot(single_frame_pred, original_frames, filename, interval=5, title=None):
|
| 22 |
"""
|
| 23 |
Save a plot of single frame predictions with thumbnails annotated at regular intervals.
|
|
@@ -43,19 +56,6 @@ def save_prediction_plot(single_frame_pred, original_frames, filename, interval=
|
|
| 43 |
plt.savefig(filename)
|
| 44 |
plt.close()
|
| 45 |
|
| 46 |
-
def load_original_frames(filepath):
|
| 47 |
-
"""Load original frames from an animated webp file as PIL Images."""
|
| 48 |
-
from PIL import Image
|
| 49 |
-
im = Image.open(filepath)
|
| 50 |
-
frames = []
|
| 51 |
-
try:
|
| 52 |
-
while True:
|
| 53 |
-
frames.append(im.convert("RGB"))
|
| 54 |
-
im.seek(im.tell() + 1)
|
| 55 |
-
except EOFError:
|
| 56 |
-
pass
|
| 57 |
-
return frames
|
| 58 |
-
|
| 59 |
def save_timeline_jpg(frames, scene_change_indices, filename, interval=5, roi_radius=2, title=None, single_frame_pred=None):
|
| 60 |
"""
|
| 61 |
Save a timeline JPG with thumbnails every `interval` frames and every frame near scene changes.
|
|
@@ -102,9 +102,9 @@ def save_timeline_jpg(frames, scene_change_indices, filename, interval=5, roi_ra
|
|
| 102 |
imagebox = OffsetImage(np.array(thumb), zoom=0.7)
|
| 103 |
# Determine border color
|
| 104 |
if fidx in last_frames:
|
| 105 |
-
bboxprops = dict(edgecolor='red', linewidth=2
|
| 106 |
elif fidx in first_frames:
|
| 107 |
-
bboxprops = dict(edgecolor='green', linewidth=2
|
| 108 |
else:
|
| 109 |
bboxprops = None
|
| 110 |
ab = AnnotationBbox(
|
|
@@ -186,7 +186,7 @@ if __name__ == "__main__":
|
|
| 186 |
frames=original_frames,
|
| 187 |
scene_change_indices=result["scene_change_indices"],
|
| 188 |
filename=timeline_filename,
|
| 189 |
-
interval=
|
| 190 |
roi_radius=2,
|
| 191 |
title=f"Timeline: {file.name}",
|
| 192 |
single_frame_pred=result["single_frame_pred"]
|
|
|
|
| 7 |
|
| 8 |
SCENE_CUT_THRESHOLD = 0.09
|
| 9 |
data_dir = Path("data/animations")
|
| 10 |
+
files = sorted(data_dir.glob("sample-00*.webp"))
|
| 11 |
|
| 12 |
def get_best_device():
|
| 13 |
if torch.cuda.is_available():
|
|
|
|
| 18 |
else:
|
| 19 |
return torch.device("cpu")
|
| 20 |
|
| 21 |
+
def load_original_frames(filepath):
|
| 22 |
+
"""Load original frames from an animated webp file as PIL Images."""
|
| 23 |
+
from PIL import Image
|
| 24 |
+
im = Image.open(filepath)
|
| 25 |
+
frames = []
|
| 26 |
+
try:
|
| 27 |
+
while True:
|
| 28 |
+
frames.append(im.convert("RGB"))
|
| 29 |
+
im.seek(im.tell() + 1)
|
| 30 |
+
except EOFError:
|
| 31 |
+
pass
|
| 32 |
+
return frames
|
| 33 |
+
|
| 34 |
def save_prediction_plot(single_frame_pred, original_frames, filename, interval=5, title=None):
|
| 35 |
"""
|
| 36 |
Save a plot of single frame predictions with thumbnails annotated at regular intervals.
|
|
|
|
| 56 |
plt.savefig(filename)
|
| 57 |
plt.close()
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def save_timeline_jpg(frames, scene_change_indices, filename, interval=5, roi_radius=2, title=None, single_frame_pred=None):
|
| 60 |
"""
|
| 61 |
Save a timeline JPG with thumbnails every `interval` frames and every frame near scene changes.
|
|
|
|
| 102 |
imagebox = OffsetImage(np.array(thumb), zoom=0.7)
|
| 103 |
# Determine border color
|
| 104 |
if fidx in last_frames:
|
| 105 |
+
bboxprops = dict(edgecolor='red', linewidth=2)
|
| 106 |
elif fidx in first_frames:
|
| 107 |
+
bboxprops = dict(edgecolor='green', linewidth=2)
|
| 108 |
else:
|
| 109 |
bboxprops = None
|
| 110 |
ab = AnnotationBbox(
|
|
|
|
| 186 |
frames=original_frames,
|
| 187 |
scene_change_indices=result["scene_change_indices"],
|
| 188 |
filename=timeline_filename,
|
| 189 |
+
interval=10,
|
| 190 |
roi_radius=2,
|
| 191 |
title=f"Timeline: {file.name}",
|
| 192 |
single_frame_pred=result["single_frame_pred"]
|