mirror of
https://github.com/OpenBMB/MiniCPM-V.git
synced 2026-02-04 17:59:18 +08:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user