w
willwell888/wifi-densepose-pretrained
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

wifi-densepose-pretrained on Ascend NPU

1. 简介

本文档记录 wifi-densepose-pretrained 在华为 Ascend NPU 上的推理适配与验证结果。wifi-densepose-pretrained 是基于 WiFi CSI(信道状态信息)的感知模型,能够从 WiFi 信号中提取人员存在性特征,支持通过墙壁进行人员检测。

该模型是 RuView 项目中的 CSI Encoder 模块,基于 2 层全连接网络(8→64→128)配合 BatchNorm、GELU 激活和 L2 归一化,将 8 维 CSI 特征映射到 128 维嵌入向量,可进一步用于人员存在性检测、活动识别等下游任务。

模型链接(HuggingFace):https://huggingface.co/ruvnet/wifi-densepose-pretrained

2. 验证环境

组件版本
torch2.9.0+cpu
torch_npu2.9.0.post1+gitee7ba04
numpy1.26.4
safetensors0.7.0
CANN8.5.1
  • NPU:Ascend 910(单卡)
  • 模型路径:/opt/atomgit/0821/wifi-densepose-pretrained
  • Python:3.11

3. 依赖安装

pip install -r requirements.txt

如需使用阿里云镜像:

pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --extra-index-url https://pypi.org/simple/

4. 模型推理

推理脚本 inference.py 加载模型并在 NPU 上执行推理:

python inference.py --device npu:0

指定其他设备:

python inference.py --device cpu
python inference.py --device cuda:0

5. Smoke 验证

python inference.py --device npu:0

验证结果:

  • CSI Encoder 加载成功,参数量 9,409
  • 推理正常输出 128 维归一化嵌入向量 + 人员存在概率
  • NPU 推理耗时:约 0.16s
  • NPU 进程峰值内存:约 222 MB HBM

推理日志(run_npu.log)中包含完整终端输出和 npu-smi 进程占用采样:

[INFO] WiFi DensePose 加载成功 | 参数量: 9,409
[INFO] 推理耗时: 0.1625s
----- 推理结果 -----
  样本 1: |embed|=1.0000, mean=0.0420, P(presence)=0.9997 → 有人
  样本 2: |embed|=1.0000, mean=0.0496, P(presence)=0.9998 → 有人
  样本 3: |embed|=1.0000, mean=0.0424, P(presence)=0.9994 → 有人

NPU 进程占用:

| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
| 7       0                 | 7790         | python3                  | 222                     |

6. 模型结构

6.1 CSI Encoder

层次输入维度输出维度说明
FC1864全连接层 + BatchNorm + GELU
FC264128全连接层 + BatchNorm + GELU
L2 Norm128128归一化到单位球面

总计 9,409 参数量(包含 Presence Head)。

6.2 Presence Head

层次输入维度输出维度说明
Dot Product1281嵌入与可学习权重的点积 + bias
Sigmoid11输出人员存在概率 P(presence)

6.3 LoRA 适配

模型支持 LoRA(Low-Rank Adaptation)权重适配:

  • LoRA A: [rank=8, 128]
  • LoRA B: [128, rank=8]
  • Scaling: 标量系数

在推理时,LoRA 调整以残差形式添加到归一化嵌入上:

embedding_final = embedding_frozen + scale * (lora_B @ lora_A) @ embedding_frozen

7. CSI 输入规格

参数值
输入 shape(B, 8)
值域[0, 1](示例数据)
特征含义8 个子载波的幅值/相位信息

8. 注意事项

  • CSI Encoder 权重存储在自定义 safetensors 格式中(8 字节长度前缀 + JSON 头 + F32 二进制),需自定义解析
  • Presence Head 权重存储在独立的 presence-head.json 中(JSON 数组格式)
  • LoRA 适配权重以残差方式应用,可选加载
  • 模型支持 int4/int8 量化权重文件(model-q2.bin, model-q4.bin, model-q8.bin),但当前推理脚本使用 FP32 全精度权重
  • 人员存在概率阈值默认 0.5,可根据场景调整