nam_nguyenhoai_AI commited on
Commit
7c07d74
·
1 Parent(s): 40666aa

update src

Browse files
Files changed (2) hide show
  1. app.py +6 -2
  2. utils.py +1 -1
app.py CHANGED
@@ -52,7 +52,8 @@ def make_video(video_path, outdir='./summarized_video', algorithm='Kmeans', mode
52
  clip_sample_rate = 1
53
  # F
54
  num_frames = 8
55
-
 
56
  frames = []
57
  features = []
58
 
@@ -64,7 +65,10 @@ def make_video(video_path, outdir='./summarized_video', algorithm='Kmeans', mode
64
  if not ret:
65
  break
66
 
 
 
67
  raw_frame = cv2.resize(raw_frame, resize_to)
 
68
  frames.append(raw_frame)
69
 
70
  # Find key frames by selecting frames with clip_sample_rate
@@ -109,7 +113,7 @@ def make_video(video_path, outdir='./summarized_video', algorithm='Kmeans', mode
109
 
110
  video_writer = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), frame_rate, (frames[0].shape[1], frames[0].shape[0]))
111
  for idx in selected_frames:
112
- video_writer.write(frames[idx])
113
 
114
  raw_video.release()
115
  video_writer.release()
 
52
  clip_sample_rate = 1
53
  # F
54
  num_frames = 8
55
+
56
+ original_frames = []
57
  frames = []
58
  features = []
59
 
 
65
  if not ret:
66
  break
67
 
68
+ # use the original frames to write the output video
69
+ original_frames.append(raw_frame)
70
  raw_frame = cv2.resize(raw_frame, resize_to)
71
+ # use the resized frames to extract features
72
  frames.append(raw_frame)
73
 
74
  # Find key frames by selecting frames with clip_sample_rate
 
113
 
114
  video_writer = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), frame_rate, (frames[0].shape[1], frames[0].shape[0]))
115
  for idx in selected_frames:
116
+ video_writer.write(original_frames[idx])
117
 
118
  raw_video.release()
119
  video_writer.release()
utils.py CHANGED
@@ -55,7 +55,7 @@ def to_video(selected_frames, frames, output_path, video_fps):
55
  def load_model(model_version):
56
  try:
57
  DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
58
- model = TimesformerModel.from_pretrained(f"facebook/timesformer-base-finetuned-{model_version}").to(DEVICE).eval()
59
  processor=VideoMAEImageProcessor.from_pretrained("MCG-NJU/videomae-base")
60
  return model, processor, DEVICE
61
 
 
55
  def load_model(model_version):
56
  try:
57
  DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
58
+ model = TimesformerModel.from_pretrained(f"facebook/timesformer-base-finetuned-{model_version}")
59
  processor=VideoMAEImageProcessor.from_pretrained("MCG-NJU/videomae-base")
60
  return model, processor, DEVICE
61