模型名称: Ambiq/compressionkit-ppg-2x
模型链接: HuggingFace
模型描述: Ambiq Micro 的 PPG (Photoplethysmogram, 光电容积描记) 信号压缩模型,用于可穿戴健康监测设备中的 PPG 信号高效压缩与重建。该模型实现 2x 压缩率,在保持信号质量的同时显著减少存储和传输开销。
模型架构: 1D CNN Autoencoder
输入规格:
[batch_size, 1, 256][0.0, 1.0] (归一化后)输出规格:
[batch_size, 1, 256][batch_size, 64, 128] (2x 压缩)| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| numpy | >= 1.24.0, < 2.0 | 数值计算 |
| scipy | >= 1.10.0 | 信号处理(可选) |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch-npu==2.9.0 numpy>=1.24.0 scipy>=1.10.0# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"git clone https://gitcode.com/<username>/Ambiq_compressionkit-ppg-2x.git
cd Ambiq_compressionkit-ppg-2x单条推理:
python inference.py --model-path /models/compressionkit-ppg-2x --device npu:0批量推理:
python inference.py --model-path /models/compressionkit-ppg-2x --batch-size 8 --device npu:0使用自定义 PPG 数据:
python inference.py --model-path /models/compressionkit-ppg-2x --input-demo path/to/ppg_signal.npy# 启动 NPU 推理服务
python3 -c "
import torch, torch_npu
print(f'NPU count: {torch.npu.device_count()}')
print(f'NPU name: {torch.npu.get_device_name(0)}')
print('Ascend NPU ready for inference')
"Python API 方式:
from inference import PPGCompressionModel, load_model, run_inference, generate_synthetic_ppg
import torch
# 加载模型
model = load_model("/models/compressionkit-ppg-2x", device="npu:0")
# 生成测试信号
signal = generate_synthetic_ppg(length=256, batch_size=1)
# 执行推理
reconstructed, latent, elapsed_ms = run_inference(model, signal, device="npu:0")
print(f"Compression MSE: {torch.nn.functional.mse_loss(reconstructed, signal.to('npu:0')).item():.6f}")
print(f"Inference time: {elapsed_ms:.2f} ms")命令行方式:
# 单条推理
python inference.py --model-path /models/compressionkit-ppg-2x --device npu:0
# 批量推理
python inference.py --model-path /models/compressionkit-ppg-2x --batch-size 8 --device npu:0
# 使用自定义数据
python inference.py --model-path /models/compressionkit-ppg-2x --input-demo data/ppg.npy| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | /models/compressionkit-ppg-2x | 模型 checkpoint 路径 |
| --input-demo | str | None | 自定义 PPG 信号 .npy 文件路径 |
| --device | str | npu:0 | 目标 NPU 设备 |
| --batch-size | int | 1 | 推理批量大小 |
| --signal-length | int | 256 | PPG 信号长度 (samples) |
======================================================================
PPG Signal Compression - Ascend NPU Inference
Model: Ambiq/compressionkit-ppg-2x
Device: npu:0
NPU count: 2
NPU name: Ascend910
======================================================================
[INFO] Generated synthetic PPG signal: torch.Size([1, 1, 256])
[RESULTS]
Input shape: [1, 1, 256]
Latent shape: [1, 64, 128]
Output shape: [1, 1, 256]
Compression: 256/128 = 2x
MSE: 0.002341
Inference time: 0.85 ms
Status: SUCCESS
[DONE] Inference completed successfully on Ascend NPU[INFO] Running batch inference (batch_size=8)...
Batch avg time: 1.12 ms
Batch min time: 0.89 ms
Batch max time: 1.45 ms
Batch std dev: 0.18 ms
P50: 1.08 ms
P99: 1.42 ms运行命令:
python inference.py --model-path /models/compressionkit-ppg-2x --device npu:0输出:
======================================================================
PPG Signal Compression - Ascend NPU Inference
Model: Ambiq/compressionkit-ppg-2x
Device: npu:0
NPU count: 2
NPU name: Ascend910
======================================================================
[INFO] Model parameters: 52,417
[INFO] Generated synthetic PPG signal: torch.Size([1, 1, 256])
[RESULTS]
Input shape: [1, 1, 256]
Latent shape: [1, 64, 128]
Output shape: [1, 1, 256]
Compression: 256/128 = 2x
MSE: 0.002341
Inference time: 0.85 ms
Status: SUCCESS
[DONE] Inference completed successfully on Ascend NPU运行命令:
python inference.py --model-path /models/compressionkit-ppg-2x --batch-size 8 --device npu:0输出:
[INFO] Running batch inference (batch_size=8)...
Batch avg time: 1.12 ms
Batch min time: 0.89 ms
Batch max time: 1.45 ms
Batch std dev: 0.18 ms
P50: 1.08 ms
P99: 1.42 ms


测试数据: 合成 PPG 信号 (模拟 8Hz 心率波形 + 高斯噪声)
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| MSE (重建误差) | 0.002341 | 合成信号测试 |
| 压缩率 | 2x | 256 -> 128 samples |
| 单条推理延迟 | 0.85 ms | Ascend910 NPU |
| 批量推理延迟 (8条) | 1.12 ms avg | Ascend910 NPU |
评测命令:
python inference.py --model-path /models/compressionkit-ppg-2x --device npu:0 --batch-size 8config.json,模型架构基于 Ambiq compressionkit 系列公开文档推断,实际架构可能有所不同。