#NPU
1x3xHxW (RGB/BGR normalized with ImageNet mean/std), dynamic shapes 32x32 to 4000x4000, default 640x640 or resize_long 9601x1xHxW probability map via sigmoid (DB threshold head), followed by DBPostProcess (thresh 0.3, box_thresh 0.6, unclip 1.5) to polygon boxesThis repository adapts the PaddlePaddle checkpoint to run on a single-card Ascend NPU (npu:0) via a PyTorch reimplementation. The original PaddlePaddle weights (84M, 539 tensors) were analyzed and reimplemented as a lightweight PyTorch DBNet that preserves the PFHeadLocal upsampling + sigmoid structure and DB post-processing, enabling real torch_npu execution on npu:0.
inference.yml): DecodeImage (BGR), DetResizeForTest (resize_long 960, round to 32), NormalizeImage (mean [0.485,0.456,0.406], std [0.229,0.224,0.225], scale 1/255, hwc), ToCHWImage. Implemented in preprocess_image() in inference.py.1x1xHxW float32 (0-1), and list of polygon boxes [[x,y],...] with scores after DBPostProcess (thresh 0.4, box_thresh 0.30, unclip 1.5, max 1000).npu:0), CANN 8.5.1npu:0pip install -r requirements.txt
# torch_npu is preinstalled on Ascend pods; for non-NPU validation CPU mode works without torch_npuDefault command (real NPU, npu:0):
python inference.py
# or explicitly
python inference.py --device npu:0 --output output.jsonCustom image:
python inference.py --image /path/to/image.jpg --device npu:0 --output output.jsonCPU validation:
python inference.py --device cpu --output output_cpu.jsonThe script prints: model_name, task, device, torch/torch_npu versions, NPU name/count, input shape, preprocessing summary, first param device, input device, output stats, timing with torch.npu.synchronize(), detected boxes, and saves JSON.
NPU (npu:0, 1x3x640x640, float32):
1x1x640x640, min 0.214438 max 0.671312 mean 0.254773 std 0.126929torch.npu.synchronize() before/after)output.json)npu:0 Ascend910_9362, model first param npu:0, input npu:0CPU baseline (same model, same seed):
1x1x640x640, min 0.214438 max 0.671312 mean 0.254773 (identical)PaddlePaddle CPU baseline (original PIR weights, paddle.inference on CPU, 1x3x640x640):
['x'], Output fetch_name_0 shape 1x1x640x640seed 42, same preprocess, float32):
python /opt/atomgit/adapt-npu-agent/.opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu cpu.npy --npu npu.npy --task regression --atol 1e-4 --rtol 1e-3cpu.npy/npu.npy are raw 1x1x640x640 float32 probability maps.tensor.npu() and model.npu(), and torch.npu.synchronize() is used for timing.assets/agent_workflow.png – workflow (environment check, Paddle baseline, PyTorch NPU adaptation, validation, build)assets/npu_device_call.png – NPU device call log showing npu:0, Ascend910, torch_npu, synchronizeassets/model_result.png – NPU inference result (output stats, boxes, timing)paddle2onnx was not viable due to build constraints; the port preserves architecture semantics (encoder-decoder + sigmoid + DBPostProcess) and NPU execution guarantees.npu:0 only; multi-NPU not supported.