Ambiq compressionkit PPG 神经信号压缩 Codec (2x) — 昇腾 NPU 适配版
本工程将 Ambiq compressionkit 的 PPG 光电容积脉搏波 RVQ 神经压缩 codec(2x 压缩率)从 Keras/TFLite 迁移到 昇腾 NPU(torch-npu) 纯 PyTorch 实现。
| 项目 | 值 |
|---|---|
| 模态 | PPG(光电容积脉搏波) |
| 采样率 | 64 Hz |
| 帧长 | 320 样本(5 秒) |
| 压缩率 | 2x(码率压缩比 2.0) |
| Codec 族 | Residual Vector Quantization (RVQ) |
| RVQ 级数 | 4 级,每级 256 个 16 维码本向量 |
| 编码器输出 | [1, 160, 16](时域降采样 2x) |
| 解码器输出 | [1, 320, 1] |
keras.weights
已导出为 encoder_weights.npz / decoder_weights.npz,缓存于
model_weights/Ambiq/compressionkit-ppg-2x-v1.0/)。npu:0(设备忙/OOM 自动回退 npu:1)。z 与各级码本做最近邻(欧氏距离),逐级 argmin 得到码索引,解码时按索引查码本求和。| 文件 | 说明 |
|---|---|
inference.py | 双模式推理:CLI + FastAPI(见下) |
codec.py | 纯 PyTorch codec 实现(encoder / decoder / RVQ / 归一化) |
model_weights/ | 权重本地缓存(gitignore,不入库) |
torch torch_npu numpy fastapi uvicorn python-multipartpython inference.py --img model_weights/Ambiq/compressionkit-ppg-2x-v1.0/sample_stimulus.npz输出 JSON:model、compression_ratio、mse、snr_db、codebook_indices、
reconstructed_signal 等。
uvicorn inference:app --host 0.0.0.0 --port 8000
curl -s -F "file=@sample_stimulus.npz" http://127.0.0.1:8000/predictPOST multipart/form-data,字段名 file,返回 JSON 推理结果。
权重遵循原仓库 LICENSE-MODEL-WEIGHTS.md(Ambiq Model Weights License);
样例/演示数据使用合成 physiokit 波形与 BIDMC PPG 数据集(ODC-By-1.0)。