本目录包含 DUIX 数字人模型的 PyTorch 复现版本。
| 文件 | 描述 | 推荐度 |
|---|---|---|
MobileNet_Fixed.py |
✅ PyTorch 复现模型 | ⭐⭐⭐⭐⭐ |
from MobileNet_Fixed import MobileNetV2Unet
import torch
# 创建模型
model = MobileNetV2Unet(use_groupnorm=False)
model.eval()
# 输入
audio = torch.randn(1, 256, 20) # 音频特征
face = torch.randn(1, 6, 160, 160) # 6通道人脸图像
# 推理
with torch.no_grad():
output = model(face, audio)
print(f"输出: {output.shape}") # [1, 3, 160, 160]
print(f"范围: [{output.min():.2f}, {output.max():.2f}]") # [-1, 1]| 组件 | 参数量 |
|---|---|
| Image Encoder (MobileNetV2) | 1.92M |
| Audio Encoder | 0.55M |
| U-Net Decoder | 2.06M |
| 总计 | 约 7.51M(PyTorch;官方约 7.54M FP16 权重) |
- ✅ 输出激活函数正确 (TanH)
- ✅ 音频编码器完整 (8层)
- ✅ 按解密后的
dh_model.p对齐音频、图像、解码器和 GroupNorm - ✅ 可直接用于推理和进一步研究
# 使用 BatchNorm(推荐用于训练)
model = MobileNetV2Unet(use_groupnorm=False)
# 使用 GroupNorm(完全对齐 NCNN)
model = MobileNetV2Unet(use_groupnorm=True)# 形状: [B, 256, 20]
# - B: batch size
# - 256: 特征维度(如 Wenet 输出)
# - 20: 时间步数
audio = torch.randn(batch_size, 256, 20)# 形状: [B, 6, H, W]
# - B: batch size
# - 6: 通道数 = 当前帧(3) + 参考帧(3)
# - H, W: 图像尺寸(通常 160x160)
# 图像归一化到 [-1, 1]
current_frame = (current_frame / 255.0) * 2 - 1 # [3, H, W]
reference_frame = (reference_frame / 255.0) * 2 - 1 # [3, H, W]
face = torch.cat([current_frame, reference_frame], dim=0) # [6, H, W]# 形状: [B, 3, H, W]
# 范围: [-1, 1] (TanH 激活)
output = model(face, audio)
# 转换为图像
output_image = (output + 1) / 2 * 255 # [0, 255]
output_image = output_image.clamp(0, 255).byte()cd models
python MobileNet_Fixed.py输出示例:
==================================================
测试修正后的模型
==================================================
Audio input shape: torch.Size([1, 256, 20])
Face input shape: torch.Size([1, 6, 160, 160])
Output shape: torch.Size([1, 3, 160, 160])
Output range: [-0.35, 0.42]
Expected range: [-1, 1] (TanH)
Total parameters: ~7.51M (PyTorch)
NCNN weight file: ~15.1 MB FP16 (约 7.54M 权重)
==================================================
✅ 模型测试完成
==================================================