File size: 5,696 Bytes
321294f 482ca4f 321294f b5f3bf4 321294f 919e20b 321294f 0b5f349 d584a2d 0b5f349 321294f 4588002 321294f 46de267 321294f 0b5f349 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
---
license: mit
language:
- en
base_model:
- zhiqi-li/BEVFormer
pipeline_tag: object-detection
tags:
- Axera
- NPU
- Pulsar2
- BEVFormer
- Autonomous-Driving
- Bird-Eye-View
---
# BEVFormer on Axera NPU
This repository contains the [BEVFormer](https://arxiv.org/abs/2203.17270) model converted for high-performance inference on the Axera NPU. BEVFormer is a paradigm-shifting transformer-based framework for 3D object detection that learns unified spatio-temporal bird's-eye-view (BEV) representations from multi-camera inputs.
This version is optimized with **w8a16** quantization and is compatible with **Pulsar2 version 4.2**.
## Convert Tools Links
For model conversion and deployment guidance:
- [AXera Platform GitHub Repo](https://github.com/AXERA-TECH/bevformer.axera): Sample code and optimization guides for Axera NPU.
- [Pulsar2 Documentation](https://pulsar2-docs.readthedocs.io/en/latest/pulsar2/introduction.html): Guide for converting ONNX models to `.axmodel`.
## Support Platforms
- **AX650**
- [M4N-Dock (η±θ―ζ΄ΎPro)](https://wiki.sipeed.com/hardware/zh/maixIV/m4ndock/m4ndock.html)
- [M.2 Accelerator card](https://axcl-docs.readthedocs.io/zh-cn/latest/doc_guide_hardware.html)
| Chips | Model Variant | NPU1 Latency (Per Frame) |NPU3 Latency (Per Frame) |
|---|---|---|---|
| AX650 | BEVFormer-Tiny | 253.966 ms | 91.209 ms |
## How to Use
BEVFormer requires multi-view camera inputs (typically 6 views: front, front-left, front-right, back, back-left, back-right).
### Prerequisites
1. **Environment:** Ensure you have the required Python environment activated (e.g., using Conda or a virtual environment) with the following core packages installed:
* **NPU Runtime:** `axengine` (PyAXEngine)
* **Core Libraries:** `numpy` (>= 1.22.0), `opencv-python` (`cv2`), `tqdm`, and `cffi`.
*
*(Recommended: Use a dedicated Conda environment to manage these dependencies.)*
2. **Model/Data:** Ensure the compiled `.axmodel`, `inference_config.json`, and input data (`inference_data/`) are available on the host.
### Inference Command
Run the inference script by providing the compiled model, configuration, and data directory.
```bash
python inference_axmodel.py compiled.axmodel inference_config.json inference_data/ --output-dir inference_results
```
### Inference with AX650 Host
```
(base) root@ax650:~/data# python inference_axmodel.py compiled.axmodel inference_config.json inference_data/ --output-dir ./inference_results
[INFO] Available providers: ['AXCLRTExecutionProvider', 'AxEngineExecutionProvider']
[INFO] Using provider: AxEngineExecutionProvider
[INFO] Chip type: ChipType.MC50
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Engine version: 2.12.0s
[INFO] Model type: 0 (single core)
[INFO] Compiler version: 5.1-patch1 82190926
Processing scene 1/2: fcbccedd61424f1b85dcbf8f897f9754 (40 frames)
Scene fcbccedd61424f1b85dcbf8f897f9754: 28%|ββββββββββββββββββββββ | 11/40 [00:12<00:33, 1.15s/it]/root/guofangming/inference_axmodel.py:389: RuntimeWarning: invalid value encountered in cast
corners = imgfov_pts_2d[i].astype(np.int32)
Scene fcbccedd61424f1b85dcbf8f897f9754: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 40/40 [00:47<00:00, 1.18s/it]Processing scene 2/2: 325cef682f064c55a255f2625c533b75 (41 frames)
Scene 325cef682f064c55a255f2625c533b75: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 41/41 [00:48<00:00, 1.18s/it]Creating video: fcbccedd61424f1b85dcbf8f897f9754_result.mp4: 100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 40/40 [00:08<00:00, 4.83it/s]β Scene fcbccedd61424f1b85dcbf8f897f9754: 40 frames, video: ./inference_results/fcbccedd61424f1b85dcbf8f897f9754/fcbccedd61424f1b85dcbf8f897f9754_result.mp4]Save scene results: 50%|βββββββββββββββββββββββββββββββββββββββββββββββββββ | 1/2 [00:23<00:23, 23.05s/it]
Creating video: 325cef682f064c55a255f2625c533b75_result.mp4: 7%|ββ | 3/41 [00:00<00:07, 4.92it/s]
Creating video: 325cef682f064c55a255f2625c533b75_result.mp4: 100%|ββββββββββββββββββββββ| 41/41 [00:08<00:00, 4.78it/s]
β Scene 325cef682f064c55a255f2625c533b75: 41 frames, video: ./inference_results/325cef682f064c55a255f2625c533b75/325cef682f064c55a255f2625c533b75_result.mp4
Save scene results: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 2/2 [00:47<00:00, 23.79s/it]
```
### Results
The model generates a 3D detection map projected onto the Bird's-Eye-View plane. Results are saved as images and videos which visualize the ego-vehicle and surrounding detected objects.
**Example Visualization:**

|