eardoi/peek-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PEEK(昇腾 NPU 适配)

PEEK(Picking Essential frames via Efficient Knowledge distillation)是 低预算视频字幕的查询无关关键帧选择器(PeekScorer 1.71M 参数), 输入视频帧即可预测逐帧相关性分数并选出关键帧。

本项目完成其在**华为昇腾 NPU(Ascend 910B)**上的推理适配与验证。

模型规格

项目说明
编码器MobileCLIP2Encoder(open_clip 骨干)
选择器PeekScorer(1.71M)
输入视频帧(RGB 图片序列)
输出逐帧相关性分数 + 关键帧索引(stratified argmax)
权重格式peek_base.safetensors

环境准备

# 需先从 GitHub clone 官方代码库(含模型定义)
git -c http.version=HTTP/1.1 clone --depth 1 \
  https://gh-proxy.com/https://github.com/momentslab/peek.git /tmp/peek
/workspace/tf4venv/bin/pip install open_clip_torch

推理

cd /workspace/peek
/workspace/tf4venv/bin/python inference.py \
    --model_path /workspace/peek_src --n_frames 10 --k 3 --device npu:0

参数

参数说明默认值
--model_pathpeek 权重目录/workspace/peek_src
--repo_codeGitHub 官方代码目录/tmp/peek
--frames视频帧图片列表(逗号分隔)自动生成
--n_frames自动生成帧数10
--k选择的关键帧数3
--device推理设备(npu:0 / cpu)npu:0
--output结果保存文件(可选)stdout

验证结果(Ascend 910B, npu:0)

输入:10 张真实风格视频帧(不同亮度模拟时间变化)

[info] pipeline OK: scorer 1.71M, device: npu:0
[info] frames: 10 张
============================================================
[info] 帧相关性分数: [-0.988, -0.863, -0.841, -0.831, -0.756, ...]
[info] 选中的 3 个关键帧索引: [5, 6, 7]
============================================================

PEEK 在 NPU 上完成逐帧相关性评分与关键帧选择(分数随时间帧递增, 选中后半段帧),NPU 推理链路完整跑通(transformer 编码器算子回退 CPU, 不影响结果)。

适配说明

  • GitHub 代码依赖:模型定义在官方仓库(src/peek/inference.py), 需先 clone 代码库(GitHub 直连超时,用 gh-proxy 镜像)。
  • load_peek_pipeline(checkpoint_path=..., device=...) 返回 (encoder, scorer, device);score_frame_paths 用关键字参数传 encoder=/scorer=/device=;select_indices 用 stratified argmax 选帧。
  • 设备解析 resolve_device():NPU 可用性检测,失败自动回退 CPU。
  • 模型权重不推送到仓库:*.safetensors 已加入 .gitignore。

目录结构

.
├── README.md          # 模型卡片(本文件)
├── inference.py       # NPU 推理脚本
└── assets/            # 适配过程截图素材

引用

  • 模型:https://huggingface.co/momentslab/peek
  • 代码:https://github.com/momentslab/peek