PEEK: Picking Essential frames via Efficient Knowledge distillation
PEEK 是一个无查询(query-free)的视频关键帧选择器:推理时仅接收视频帧,按预算 k 帧
预测每帧相关性分数,并按时间顺序返回选中的帧,可直接送入下游视频语言模型(Video-LLM)。
peek_base.safetensors(约 6.8 MB,2 层 Transformer,约 1.7M 参数,CC-BY-NC-SA-4.0)k 个桶,每桶取最高分帧(论文策略)。视频 → ffmpeg 按 fps 抽帧 → MobileCLIP2-S0 编码 (T, 512) → PeekScorer 打分 (T,)
→ stratified_argmax 选取 k 帧 → 关键帧索引 / 时间戳 / 分数requirements.txt(torch、torch_npu、open_clip_torch、transformers、imageio-ffmpeg、safetensors 等)# 1. 安装依赖(昇腾环境需先安装 torch_npu,见 requirements.txt 注释)
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple
# 2. 运行默认用例(仓库内置 sample_video.mp4,6 秒 640x360 测试视频)
python3 inference.py --k 4
# 3. 指定视频与参数
python3 inference.py --video your_video.mp4 --k 4 --fps 2.0 --output-json result.json| 参数 | 默认值 | 说明 |
|---|---|---|
--video | sample_video.mp4 | 输入视频路径 |
--k | 4 | 关键帧预算(选取帧数) |
--fps | 2.0 | 抽帧帧率 |
--selection-mode | stratified_argmax | 选取策略:stratified_argmax / topk / uniform |
--device | 自动(npu → cuda → cpu) | 推理设备 |
--output-json | 无 | 推理报告输出路径 |
说明:MobileCLIP2-S0 编码器权重首次运行会从 Hugging Face 自动下载(约 90 MB); 网络受限时可设置
HF_ENDPOINT=https://hf-mirror.com走镜像。
默认用例 sample_video.mp4(6 秒 / 2 fps → 12 帧,k=4):
| 项目 | 结果 |
|---|---|
| 设备 | npu:0 |
| 帧数 | 12 |
| 选中帧索引 | [2, 5, 7, 9] |
| 选中帧时间戳(s) | [1.0, 2.5, 3.5, 4.5] |
| 抽帧耗时 | 0.07 s |
| MobileCLIP2 编码耗时 | 0.27 s |
| PeekScorer 打分耗时 | 0.02 s |
| 总计(含模型加载) | 10.4 s |
输出示例:
{
"model": "momentslab/peek",
"device": "npu:0",
"k": 4,
"frame_count": 12,
"selected_frame_indices": [2, 5, 7, 9],
"selected_timestamps_sec": [1.0, 2.5, 3.5, 4.5],
"selected_scores": [-0.5273, -0.1409, -0.3872, -0.1724],
"timings_sec": {
"frame_extract_sec": 0.073,
"mobileclip2_encode_sec": 0.268,
"peek_score_sec": 0.017,
"total_sec": 10.429
}
}| 文件 | 说明 |
|---|---|
inference.py | NPU 推理脚本(设备自动选择 npu/cuda/cpu) |
peek_base.safetensors | PEEK 打分器权重(CC-BY-NC-SA-4.0) |
config.json | 模型架构配置 |
sample_video.mp4 | 内置演示视频 |
peek/ | PEEK 官方代码(Apache-2.0,vendored):model / encoder / frames / selection |
requirements.txt | 环境依赖清单 |
LICENSE | CC-BY-NC-SA-4.0(权重许可证) |
peek_base.safetensors)peek/ 与推理脚本)