Candle commited on
Commit
3927f54
·
1 Parent(s): 1b7edb8
Files changed (1) hide show
  1. detect_scene.py +14 -2
detect_scene.py CHANGED
@@ -8,6 +8,7 @@ import re
8
  # SCENE_CUT_THRESHOLD = 0.09
9
  K = 3 # Number of cuts to detect
10
  MIN_DURATION_FRAMES = 2
 
11
 
12
  data_dir = Path("data/animations")
13
  files = sorted(data_dir.glob("sample-*.webp"))
@@ -209,21 +210,32 @@ if __name__ == "__main__":
209
  # Sort indices by prediction score (descending)
210
  sorted_indices = valid_indices[np.argsort(valid_preds)[::-1]]
211
  scene_change_indices = []
 
212
  for idx in sorted_indices:
213
  if all(abs(idx - prev) >= MIN_DURATION_FRAMES for prev in scene_change_indices):
214
  scene_change_indices.append(int(idx))
 
215
  if len(scene_change_indices) >= (K - 1):
216
  break
217
 
218
- print(f"File: {file.name}, Frames: {len(original_frames)}, Scene Changes: {len(scene_change_indices)}")
 
 
 
219
  # Save results to JSON (include threshold and predictions)
220
  json_filename = file.parent / f"sample-{sample_num}.json"
221
  with open(json_filename, "w") as f:
222
  json.dump({
223
  "num_frames": len(original_frames),
224
  "scene_change_indices": scene_change_indices,
 
225
  # "threshold": SCENE_CUT_THRESHOLD
226
- "k": K,
 
 
 
 
 
227
  }, f, indent=2)
228
  # Save timeline JPG
229
  timeline_filename = file.parent / f"sample-{sample_num}.timeline.jpg"
 
8
  # SCENE_CUT_THRESHOLD = 0.09
9
  K = 3 # Number of cuts to detect
10
  MIN_DURATION_FRAMES = 2
11
+ MIN_CONFIDENCE = 0.02
12
 
13
  data_dir = Path("data/animations")
14
  files = sorted(data_dir.glob("sample-*.webp"))
 
210
  # Sort indices by prediction score (descending)
211
  sorted_indices = valid_indices[np.argsort(valid_preds)[::-1]]
212
  scene_change_indices = []
213
+ scene_cut_confidences = []
214
  for idx in sorted_indices:
215
  if all(abs(idx - prev) >= MIN_DURATION_FRAMES for prev in scene_change_indices):
216
  scene_change_indices.append(int(idx))
217
+ scene_cut_confidences.append(float(single_frame_pred[idx]))
218
  if len(scene_change_indices) >= (K - 1):
219
  break
220
 
221
+ # Check if any confidence is below MIN_CONFIDENCE
222
+ failed = any(conf < MIN_CONFIDENCE for conf in scene_cut_confidences)
223
+
224
+ print(f"File: {file.name}, Frames: {len(original_frames)}, Scene Changes: {len(scene_change_indices)}, Success: {not failed}")
225
  # Save results to JSON (include threshold and predictions)
226
  json_filename = file.parent / f"sample-{sample_num}.json"
227
  with open(json_filename, "w") as f:
228
  json.dump({
229
  "num_frames": len(original_frames),
230
  "scene_change_indices": scene_change_indices,
231
+ "scene_cut_confidences": scene_cut_confidences,
232
  # "threshold": SCENE_CUT_THRESHOLD
233
+ "params": {
234
+ "k": K,
235
+ "min_duration_frames": MIN_DURATION_FRAMES,
236
+ "min_confidence": MIN_CONFIDENCE,
237
+ },
238
+ "success": not failed
239
  }, f, indent=2)
240
  # Save timeline JPG
241
  timeline_filename = file.parent / f"sample-{sample_num}.timeline.jpg"