facebook/mask2former-swin-large-ade-semantic (commit aa25c92404a40599614215e76514c79b427c7527)Mask2FormerForUniversalSegmentation (model_type: mask2former, Swin-Large backbone depths [2,2,18,2] embed_dim 192 hidden 1536, hidden_dim 256, num_queries 100, num_labels 150, common_stride 4)Mask2FormerImageProcessor (Resize 384x384, rescale 1/255, normalize mean [0.485,0.456,0.406] std [0.229,0.224,0.225], size_divisor 32) 输出 100个 query 的 masks_queries_logits [1,100,96,96] 与 class_queries_logits [1,100,151],经 post_process_semantic_segmentation 融合为原图尺寸语义图 [H,W] (150类)Mask2FormerForUniversalSegmentation.from_pretrained(local, torch_dtype=float32).to(npu:0) + AutoImageProcessor, 无隐式联网,本地缓存 /opt/atomgit/.cache/huggingface/hub/models--facebook--mask2former-swin-large-ade-semantic/snapshots/aa25c92404a40599614215e76514c79b427c7527 (HF_ENDPOINT=https://hf-mirror.com)npu:0 (Phy 4 Bus 0000:0B:00.0 Health OK, HBM 4373/65536 MB 使用, Temp 44C, npu-smi 25.5.5)/usr/local/Ascend/cann-8.5.1)torch_dtype float32, device npu:0, 首参 npu:0 float32, 215.49M 参数pixel_values [1,3,384,384] float32 + pixel_mask [1,384,384]pip install -r requirements.txt
# 需预装 CANN Toolkit 8.5.1 使 torch_npu 可用
# 权重已缓存于 /opt/atomgit/.cache/huggingface/hub/models--facebook--mask2former-swin-large-ade-semantic/snapshots/aa25c92404a40599614215e76514c79b427c7527 (model.safetensors 826M)
# 离线可通过 HF_ENDPOINT=https://hf-mirror.com 走国内镜像 snapshot_downloadpython inference.py
# 或指定模式
python inference.py --mode validate # CPU vs NPU 一致性 (pixel agreement / IoU)
python inference.py --mode benchmark # 3 warmup + 10 iters 同步计时
python inference.py --device npu:0 --dtype float32python inference.py (device npu:0, float32, 合成图 seed 0, torch.npu.synchronize 计时)npu:0 Ascend910_9362, torch_npu 2.9.0.post1, torch.npu.is_available() True, 模型首参 npu:0 float32pixel_values [1,3,384,384] float32 (processor 384x384)masks_queries_logits: [1, 100, 96, 96] float32class_queries_logits: [1, 100, 151] float32semantic [384,384] int64 via processor.post_process_semantic_segmentation Semantic map unique classes: [2] (total 1)
class 2: 147456 pixels (100.00%)
Top predicted class: 2 (147456 pixels)(class 2 = sky in ADE20K id2label)
PASS (semantic shape [384,384] matches 384x384, masks finite)python inference.py --mode validatenpu:0 同步推理CPU masks_queries_logits (1, 100, 96, 96) class (1, 100, 151)
CPU semantic unique [2]
NPU masks_queries_logits (1, 100, 96, 96) class (1, 100, 151)
NPU semantic unique [2]
Max abs diff masks_queries_logits: 13.697899
Mean abs diff masks_queries_logits: 0.125415
Max abs diff class_queries_logits: 1.415354
Pixel agreement: 1.000000 (100.00%)
Mean IoU: 1.000000
class 2 IoU 1.000000
CPU top class 2 NPU top 2 match=TruePASS (阈值 0.99, NPU 与 CPU 语义图完全一致; raw logits 存在浮点数值差异但 argmax 融合后一致, 属 NPU/CPU 浮点实现预期差异)python inference.py --mode benchmark (torch.npu.synchronize 前后计时)npu:0, float32, 输入 [1,3,384,384], 3 warmup + 10 iters iter 1: 48.47 ms
iter 2: 49.90 ms
iter 3: 51.22 ms
iter 4: 50.85 ms
iter 5: 50.92 ms
iter 6: 51.01 ms
iter 7: 51.22 ms
iter 8: 50.69 ms
iter 9: 50.52 ms
iter 10: 50.86 ms
avg 50.57 ms min 48.47 max 51.22 p50 50.86 p90 51.22 p95 51.22
throughput 19.78 images/s (batch 1, (384, 384))
NPU memory free 61162.6 MB total 62740.0 MBassets/agent_workflow.png - 下载、侦察、加载、NPU 推理、验证、性能全流程日志assets/npu_device_call.png - npu-smi info + torch.npu.is_available() + 设备名 + 模型参数 device/dtypeassets/model_result.png - python inference.py 默认输出 (任务结果、语义图、延迟、PASS)Hardware: NPU, NPU, Ascend, Ascend910, Mask2Former, Swin, ADE20K, semantic-segmentation, vision