模型名称: briaai/RMBG-1.4
模型链接: HuggingFace
模型描述: BRIA RMBG-1.4 是一个基于 U2Net 架构的背景移除模型,用于图像前景分割和背景去除。模型输入 RGB 图像,输出 Alpha Matte(透明度掩码)。
模型架构: U2Net(RSU-7/RSU-6/RSU-5/RSU-4/RSU-4F 编码器-解码器结构,6 个 side output)
参数规模: 44,046,790 参数(约 44M)
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| transformers | >= 4.38.0 | HuggingFace Transformers(PreTrainedModel 基类) |
| safetensors | >= 0.4.0 | 模型权重加载 |
| Pillow | >= 9.0.0 | 图像 I/O |
| numpy | >= 1.21.0 | 数组操作 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch torch-npu transformers safetensors Pillow numpy# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:ModelScope(推荐,国内访问速度更快)
pip install modelscope
python3 -c "from modelscope import snapshot_download; snapshot_download('briaai/RMBG-1.4', cache_dir='./model')"方式二:HuggingFace
huggingface-cli download briaai/RMBG-1.4 --local-dir ./model方式三:AtomGit 镜像(HuggingFace 下载慢时使用)
export HF_ENDPOINT=https://ai.gitcode.com/hf_mirrors
huggingface-cli download briaai/RMBG-1.4 --local-dir ./model# 单张图片推理
python inference.py \
--model-path ./model \
--image-path ./test.jpg \
--output-mask ./mask.png \
--output-result ./result.png \
--device npu
# 批量推理性能测试
python inference.py \
--model-path ./model \
--image-path ./test.jpg \
--device npu \
--batch| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 的目录路径 |
| --image-path | str | 必填 | 输入图片的路径 |
| --output-mask | str | output_mask.png | 输出掩码的保存路径 |
| --output-result | str | output_result.png | 背景去除结果的保存路径 |
| --device | str | npu | 推理设备(npu/cpu) |
| --batch | flag | False | 运行批量推理基准测试 |
[模型] briaai/RMBG-1.4 (BriaRMBG)
[设备] Ascend910_9362 (npu:0)
[输入] RGB image (933, 1405) -> resized to (1024, 1024)
[输出] 6 side-output masks, each (1, 1, 1024, 1024)
[主掩码] shape=(1024, 1024), range=[0.0000, 1.0000]
[耗时] 175.2ms
[状态] SUCCESS[基准测试] 4次推理统计:
总耗时: 460.8ms
平均: 115.2ms
P50: 115.2ms
P99: 115.2ms
吞吐量: 8.7 images/sec运行命令:
python inference.py \
--model-path ./model \
--image-path ./model/example_input.jpg \
--output-mask ./test_mask.png \
--output-result ./test_result.png \
--device npu输出:
[INFO] Loading model from: ./model
[INFO] Model: BriaRMBG, 44,046,790 parameters
[INFO] Device: npu
[INFO] Loading image: ./model/example_input.jpg
[INFO] Input tensor shape: torch.Size([1, 3, 1024, 1024])
[INFO] Original image size: (933, 1405)
[INFO] Running inference...
[INFO] Output: list of 6 masks
[INFO] side1: shape=torch.Size([1, 1, 1024, 1024]), min=0.0000, max=1.0000
[INFO] side2: shape=torch.Size([1, 1, 1024, 1024]), min=0.0000, max=1.0000
[INFO] side3: shape=torch.Size([1, 1, 1024, 1024]), min=0.0000, max=1.0000
[INFO] side4: shape=torch.Size([1, 1, 1024, 1024]), min=0.0000, max=1.0000
[INFO] side5: shape=torch.Size([1, 1, 1024, 1024]), min=0.0000, max=1.0000
[INFO] side6: shape=torch.Size([1, 1, 1024, 1024]), min=0.0000, max=1.0000
[INFO] Inference time: 175.2ms
[INFO] Saving mask to: ./test_mask.png
[INFO] Saving result to: ./test_result.png
[STATUS] SUCCESS - Background removal completed运行命令:
python inference.py \
--model-path ./model \
--image-path ./model/example_input.jpg \
--device npu \
--batch输出:
[BENCHMARK] Batch inference (4 images)
[BENCHMARK] Total time: 452.6ms
[BENCHMARK] Per-image avg: 113.2ms
[BENCHMARK] Throughput: 8.8 images/sec


测试数据: RMBG-1.4 自带的 example_input.jpg(933×1405),以及通用背景移除基准测试
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| 单图推理速度 | 120-175 ms | Ascend910_9362,1024×1024 |
| 批量推理速度 | 113 ms/张 | Batch=4,平均耗时 |
| 吞吐量 | 8.8 张/秒 | Batch=4 |
| 模型大小 | 169 MB(safetensors) | fp32 |
| 参数量 | 44,046,790 | 约 44M |
评测命令:
python inference.py --model-path ./model --image-path ./test.jpg --device npu
python inference.py --model-path ./model --image-path ./test.jpg --device npu --batch无。