Skip to content

Commit

Permalink
Optimize video frame sampling logic
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
JamePeng authored Aug 26, 2024
1 parent 3745c33 commit 344ddc2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion web_demo_streamlit-minicpmv2_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 344ddc2

Please sign in to comment.