From 344ddc2cb1bc5cb246590d6a1372323d13c10c10 Mon Sep 17 00:00:00 2001 From: JamePeng Date: Tue, 27 Aug 2024 04:40:48 +0800 Subject: [PATCH] Optimize video frame sampling logic - Replaced manual index calculation with `np.linspace` for improved efficiency and readability. - Reduced computation overhead by utilizing NumPy's vectorized operations for generating evenly spaced frame indices. --- web_demo_streamlit-minicpmv2_6.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_demo_streamlit-minicpmv2_6.py b/web_demo_streamlit-minicpmv2_6.py index 1b00a86..6cdedd2 100644 --- a/web_demo_streamlit-minicpmv2_6.py +++ b/web_demo_streamlit-minicpmv2_6.py @@ -151,7 +151,7 @@ def encode_video(video_path): def uniform_sample(frame_indices, num_samples): # Calculate sampling interval and uniformly sample frame indices gap = len(frame_indices) / num_samples - sampled_idxs = [int(i * gap + gap / 2) for i in range(num_samples)] + sampled_idxs = np.linspace(gap / 2, len(frame_indices) - gap / 2, num_samples, dtype=int) return [frame_indices[i] for i in sampled_idxs] # Read the video and set the decoder's context to CPU