SkalskiP commited on
Commit
1f28a9c
1 Parent(s): 4e14a56

generate caption only once

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -89,16 +89,20 @@ def process_video(
89
  )
90
  result_file_name = generate_file_name(extension="mp4")
91
  result_file_path = os.path.join(RESULTS, result_file_name)
 
92
  TRACKER.reset()
 
 
93
  with sv.VideoSink(result_file_path, video_info=video_info) as sink:
94
  for _ in tqdm(range(total // OUTPUT_LENGTH), desc="Processing video..."):
95
  frame = next(frame_generator)
96
- caption = run_captioning(
97
- model=MODEL,
98
- processor=PROCESSOR,
99
- image=frame,
100
- device=DEVICE
101
- )[CAPTIONING_TASK]
 
102
  detections = run_caption_to_phrase_grounding(
103
  model=MODEL,
104
  processor=PROCESSOR,
 
89
  )
90
  result_file_name = generate_file_name(extension="mp4")
91
  result_file_path = os.path.join(RESULTS, result_file_name)
92
+
93
  TRACKER.reset()
94
+ caption = None
95
+
96
  with sv.VideoSink(result_file_path, video_info=video_info) as sink:
97
  for _ in tqdm(range(total // OUTPUT_LENGTH), desc="Processing video..."):
98
  frame = next(frame_generator)
99
+ if caption is None:
100
+ caption = run_captioning(
101
+ model=MODEL,
102
+ processor=PROCESSOR,
103
+ image=frame,
104
+ device=DEVICE
105
+ )[CAPTIONING_TASK]
106
  detections = run_caption_to_phrase_grounding(
107
  model=MODEL,
108
  processor=PROCESSOR,