Agora board builds (Model Farm, verified on real boards)
Browse files- .gitattributes +16 -0
- LICENSE_MODEL_FARM.pdf +0 -0
- NOTICE.md +5 -0
- README.md +36 -0
- SHA256SUMS +34 -0
- targets/QCS8550/FP16/calibration.json +301 -0
- targets/QCS8550/FP16/composite.json +79 -0
- targets/QCS8550/FP16/frustum.npy +3 -0
- targets/QCS8550/FP16/geometry-ranks.npz +3 -0
- targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part1_qcs8550_fp16.qnn236.ctx.bin.amf +3 -0
- targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part3_qcs8550_fp16.qnn236.ctx.bin.amf +3 -0
- targets/QCS8550/FP16/reference/deployment/bev_pool_v2_cpu.py +199 -0
- targets/QCS8550/FP16/reference/deployment/postprocess_flashocc_qnn.py +104 -0
- targets/QCS8550/FP16/reference/part1.py +50 -0
- targets/QCS8550/FP16/reference/part3.py +49 -0
- targets/QCS8550/FP16/reference/run_flashocc_split_onboard.py +728 -0
- targets/QCS8550/FP16/samples/back.jpg +3 -0
- targets/QCS8550/FP16/samples/back_left.jpg +3 -0
- targets/QCS8550/FP16/samples/back_right.jpg +3 -0
- targets/QCS8550/FP16/samples/front.jpg +3 -0
- targets/QCS8550/FP16/samples/front_left.jpg +3 -0
- targets/QCS8550/FP16/samples/front_right.jpg +3 -0
- targets/QCS8550/W8A16/calibration.json +301 -0
- targets/QCS8550/W8A16/composite.json +79 -0
- targets/QCS8550/W8A16/frustum.npy +3 -0
- targets/QCS8550/W8A16/geometry-ranks.npz +3 -0
- targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part1_qcs8550_w8a16.qnn236.ctx.bin.amf +3 -0
- targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part3_qcs8550_w8a16.qnn236.ctx.bin.aidem +3 -0
- targets/QCS8550/W8A16/reference/deployment/bev_pool_v2_cpu.py +199 -0
- targets/QCS8550/W8A16/reference/deployment/postprocess_flashocc_qnn.py +104 -0
- targets/QCS8550/W8A16/reference/part1.py +50 -0
- targets/QCS8550/W8A16/reference/part3.py +49 -0
- targets/QCS8550/W8A16/reference/run_flashocc_split_onboard.py +728 -0
- targets/QCS8550/W8A16/samples/back.jpg +3 -0
- targets/QCS8550/W8A16/samples/back_left.jpg +3 -0
- targets/QCS8550/W8A16/samples/back_right.jpg +3 -0
- targets/QCS8550/W8A16/samples/front.jpg +3 -0
- targets/QCS8550/W8A16/samples/front_left.jpg +3 -0
- targets/QCS8550/W8A16/samples/front_right.jpg +3 -0
- targets/QCS8550/model.json +8 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,19 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part1_qcs8550_fp16.qnn236.ctx.bin.amf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part3_qcs8550_fp16.qnn236.ctx.bin.amf filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
targets/QCS8550/FP16/samples/back.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
targets/QCS8550/FP16/samples/back_left.jpg filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
targets/QCS8550/FP16/samples/back_right.jpg filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
targets/QCS8550/FP16/samples/front.jpg filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
targets/QCS8550/FP16/samples/front_left.jpg filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
targets/QCS8550/FP16/samples/front_right.jpg filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part1_qcs8550_w8a16.qnn236.ctx.bin.amf filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part3_qcs8550_w8a16.qnn236.ctx.bin.aidem filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
targets/QCS8550/W8A16/samples/back.jpg filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
targets/QCS8550/W8A16/samples/back_left.jpg filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
targets/QCS8550/W8A16/samples/back_right.jpg filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
targets/QCS8550/W8A16/samples/front.jpg filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
targets/QCS8550/W8A16/samples/front_left.jpg filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
targets/QCS8550/W8A16/samples/front_right.jpg filter=lfs diff=lfs merge=lfs -text
|
LICENSE_MODEL_FARM.pdf
ADDED
|
Binary file (71.1 kB). View file
|
|
|
NOTICE.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Provenance
|
| 2 |
+
|
| 3 |
+
Resources are copied without binary changes from the APLUX Model Farm build `FlashOCC` that Agora verified on real boards (decoded sample check, then measured), pinned by sha256 in SHA256SUMS.
|
| 4 |
+
|
| 5 |
+
Agora arranges files under targets/<SoC>/<precision>/ and adds model.json. AidLite, AidGen, AidVoice and the Qualcomm QNN runtime are separate dependencies with their own terms.
|
README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: aplux-model-farm
|
| 4 |
+
license_link: https://huggingface.co/APLUX-Agora/FlashOCC/blob/main/LICENSE_MODEL_FARM.pdf
|
| 5 |
+
tags: [Agora, QNN, AIoT, Qualcomm]
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# FlashOCC model resources
|
| 9 |
+
|
| 10 |
+
输入六路相机及标定,使用 NPU 图像编码与占用预测,输出 200×200×16 三维语义体素。
|
| 11 |
+
|
| 12 |
+
Board builds that [Agora](https://mega.aidlux.com) runs and measures on real Qualcomm boards. Try it online, without a board: https://mega.aidlux.com/models/flashocc
|
| 13 |
+
|
| 14 |
+
| SoC · board | Precisions | Measured on Agora (default precision) |
|
| 15 |
+
| --- | --- | --- |
|
| 16 |
+
| QCS8550 · 犀牛派 X1 (Rhino Pi X1) | FP16, W8A16 | 278.7 ms |
|
| 17 |
+
|
| 18 |
+
Task: 其他. Inputs: front (image), front_right (image), front_left (image), back (image), back_left (image), back_right (image), calibration (text). Outputs: image (image), out (json).
|
| 19 |
+
|
| 20 |
+
## Download
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
export AGORA_WORKSPACE="$HOME/my-flashocc"
|
| 24 |
+
export AGORA_SOC='QCS8550'
|
| 25 |
+
hf download APLUX-Agora/FlashOCC \
|
| 26 |
+
--include "targets/$AGORA_SOC/*" --local-dir "$AGORA_WORKSPACE/resources"
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Each `targets/<SoC>/` holds `model.json` (default precision and variant paths) and one directory per precision. Context binaries are named `model.bin`; multi-file packages are kept as published by Model Farm.
|
| 30 |
+
|
| 31 |
+
Pre- and post-processing, the runner and an exported project: open the model on Agora and choose “部署指南”, or export any workflow that uses it.
|
| 32 |
+
|
| 33 |
+
## Licence and provenance
|
| 34 |
+
|
| 35 |
+
Source model licence: see the original model's terms.
|
| 36 |
+
Converted, deployable resources: APLUX Model Farm License (LICENSE_MODEL_FARM.pdf). See NOTICE.md and SHA256SUMS.
|
SHA256SUMS
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
c9bef4379a9cab2324cfc3ab5b18f3c3bbf4b4641d4b345b956c043928df67ce targets/QCS8550/FP16/calibration.json
|
| 2 |
+
259fea3902ebc50915438f13e1df3248d93c3a7785a7824a4d49863ec2e1d1f2 targets/QCS8550/FP16/composite.json
|
| 3 |
+
37dd2f50e2f7b6451541088ccd3db3d8cd5697c52dcc60255c85bc1cb825e20b targets/QCS8550/FP16/frustum.npy
|
| 4 |
+
40935c88bcc4b17aa5d4e661cbbab71f2b0627dadd754083fb4d91d95458fa43 targets/QCS8550/FP16/geometry-ranks.npz
|
| 5 |
+
085d557642bba9d458e84fc5493325c9e59372192b450f6fbf4da40b070e1ddc targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part1_qcs8550_fp16.qnn236.ctx.bin.amf
|
| 6 |
+
741eacb785a6ef715126ba7d6f4a4ade294a13f9719c032a7ca34b57e3fa8811 targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part3_qcs8550_fp16.qnn236.ctx.bin.amf
|
| 7 |
+
62c2c566ded450425aabbcf6e08cec72f02e63800c41f0afbb82a722abf80918 targets/QCS8550/FP16/reference/deployment/bev_pool_v2_cpu.py
|
| 8 |
+
4dc7a2a9f2ffa5ea209e8d14ed34fa628258eb953400b41f762849127b6123ed targets/QCS8550/FP16/reference/deployment/postprocess_flashocc_qnn.py
|
| 9 |
+
a9177064f8ddf5cd9df17033ed35414bb96ca26f02e44dec8dd7e27f74922eeb targets/QCS8550/FP16/reference/part1.py
|
| 10 |
+
ab2e976ec9ec229a4e12ba06896320fd6a8597f82466e654f23d4469b3962be1 targets/QCS8550/FP16/reference/part3.py
|
| 11 |
+
e13d4f407085e2a0db91c947ac4717803bd08f3f47130e82382930f006f3ae24 targets/QCS8550/FP16/reference/run_flashocc_split_onboard.py
|
| 12 |
+
fdbdaa77e60ed5a6a762a4ea9a8eb1cb2ca9a3d94c610a55a2399a05c04b6ba6 targets/QCS8550/FP16/samples/back.jpg
|
| 13 |
+
000f7943769e91ffa842a7dfd1bfc31e0c3f4b37325a98846e8261304028f2ad targets/QCS8550/FP16/samples/back_left.jpg
|
| 14 |
+
39d28a8a5a6f61370a7e7e1e965a6d8610b571195c50fd29da960e1fb2fbee80 targets/QCS8550/FP16/samples/back_right.jpg
|
| 15 |
+
d5624fcecf12310c3d0760362e097c38cdcdce987e032aaf2883071cd14e2732 targets/QCS8550/FP16/samples/front.jpg
|
| 16 |
+
0fe15c0581db41e084df27acb2183b0ab9b0fd36da136ef1b4bcbda6f1a84c58 targets/QCS8550/FP16/samples/front_left.jpg
|
| 17 |
+
dd64d7463bc06bfd5d5378bdd494b40d68d0894307f3ed971eaaaf131022cf68 targets/QCS8550/FP16/samples/front_right.jpg
|
| 18 |
+
c9bef4379a9cab2324cfc3ab5b18f3c3bbf4b4641d4b345b956c043928df67ce targets/QCS8550/W8A16/calibration.json
|
| 19 |
+
ee4a727cb5c17c375813f245904de589f1176cfc0b079e92e8ed48fc4c97bf20 targets/QCS8550/W8A16/composite.json
|
| 20 |
+
37dd2f50e2f7b6451541088ccd3db3d8cd5697c52dcc60255c85bc1cb825e20b targets/QCS8550/W8A16/frustum.npy
|
| 21 |
+
40935c88bcc4b17aa5d4e661cbbab71f2b0627dadd754083fb4d91d95458fa43 targets/QCS8550/W8A16/geometry-ranks.npz
|
| 22 |
+
e8d78968fa25557786cca663b5f5f377c93368083adec12c8cc3a85f58e34527 targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part1_qcs8550_w8a16.qnn236.ctx.bin.amf
|
| 23 |
+
74de4b0257372adcb4bfb52b4fadfcaef4c84f7a41e50e117171cde17dc58570 targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part3_qcs8550_w8a16.qnn236.ctx.bin.aidem
|
| 24 |
+
62c2c566ded450425aabbcf6e08cec72f02e63800c41f0afbb82a722abf80918 targets/QCS8550/W8A16/reference/deployment/bev_pool_v2_cpu.py
|
| 25 |
+
4dc7a2a9f2ffa5ea209e8d14ed34fa628258eb953400b41f762849127b6123ed targets/QCS8550/W8A16/reference/deployment/postprocess_flashocc_qnn.py
|
| 26 |
+
a9177064f8ddf5cd9df17033ed35414bb96ca26f02e44dec8dd7e27f74922eeb targets/QCS8550/W8A16/reference/part1.py
|
| 27 |
+
ab2e976ec9ec229a4e12ba06896320fd6a8597f82466e654f23d4469b3962be1 targets/QCS8550/W8A16/reference/part3.py
|
| 28 |
+
e13d4f407085e2a0db91c947ac4717803bd08f3f47130e82382930f006f3ae24 targets/QCS8550/W8A16/reference/run_flashocc_split_onboard.py
|
| 29 |
+
fdbdaa77e60ed5a6a762a4ea9a8eb1cb2ca9a3d94c610a55a2399a05c04b6ba6 targets/QCS8550/W8A16/samples/back.jpg
|
| 30 |
+
000f7943769e91ffa842a7dfd1bfc31e0c3f4b37325a98846e8261304028f2ad targets/QCS8550/W8A16/samples/back_left.jpg
|
| 31 |
+
39d28a8a5a6f61370a7e7e1e965a6d8610b571195c50fd29da960e1fb2fbee80 targets/QCS8550/W8A16/samples/back_right.jpg
|
| 32 |
+
d5624fcecf12310c3d0760362e097c38cdcdce987e032aaf2883071cd14e2732 targets/QCS8550/W8A16/samples/front.jpg
|
| 33 |
+
0fe15c0581db41e084df27acb2183b0ab9b0fd36da136ef1b4bcbda6f1a84c58 targets/QCS8550/W8A16/samples/front_left.jpg
|
| 34 |
+
dd64d7463bc06bfd5d5378bdd494b40d68d0894307f3ed971eaaaf131022cf68 targets/QCS8550/W8A16/samples/front_right.jpg
|
targets/QCS8550/FP16/calibration.json
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cameraOrder": [
|
| 3 |
+
"front",
|
| 4 |
+
"front_right",
|
| 5 |
+
"front_left",
|
| 6 |
+
"back",
|
| 7 |
+
"back_left",
|
| 8 |
+
"back_right"
|
| 9 |
+
],
|
| 10 |
+
"cameraToEgo": [
|
| 11 |
+
[
|
| 12 |
+
[
|
| 13 |
+
0.009793734177947044,
|
| 14 |
+
0.008477547205984592,
|
| 15 |
+
0.999916136264801,
|
| 16 |
+
1.786743402481079
|
| 17 |
+
],
|
| 18 |
+
[
|
| 19 |
+
-0.9998770952224731,
|
| 20 |
+
0.012321611866354942,
|
| 21 |
+
0.009688900783658028,
|
| 22 |
+
0.0036235980223864317
|
| 23 |
+
],
|
| 24 |
+
[
|
| 25 |
+
-0.012238440103828907,
|
| 26 |
+
-0.9998881816864014,
|
| 27 |
+
0.008597181178629398,
|
| 28 |
+
1.4961199760437012
|
| 29 |
+
],
|
| 30 |
+
[
|
| 31 |
+
0.0,
|
| 32 |
+
0.0,
|
| 33 |
+
0.0,
|
| 34 |
+
1.0
|
| 35 |
+
]
|
| 36 |
+
],
|
| 37 |
+
[
|
| 38 |
+
[
|
| 39 |
+
-0.8444615602493286,
|
| 40 |
+
0.016537705436348915,
|
| 41 |
+
0.5353609323501587,
|
| 42 |
+
1.7133985757827759
|
| 43 |
+
],
|
| 44 |
+
[
|
| 45 |
+
-0.535379946231842,
|
| 46 |
+
0.003624292556196451,
|
| 47 |
+
-0.8446035385131836,
|
| 48 |
+
-0.5012373924255371
|
| 49 |
+
],
|
| 50 |
+
[
|
| 51 |
+
-0.01590810902416706,
|
| 52 |
+
-0.99985671043396,
|
| 53 |
+
0.00579338101670146,
|
| 54 |
+
1.5199543237686157
|
| 55 |
+
],
|
| 56 |
+
[
|
| 57 |
+
0.0,
|
| 58 |
+
0.0,
|
| 59 |
+
0.0,
|
| 60 |
+
1.0
|
| 61 |
+
]
|
| 62 |
+
],
|
| 63 |
+
[
|
| 64 |
+
[
|
| 65 |
+
0.8225460648536682,
|
| 66 |
+
0.006478320807218552,
|
| 67 |
+
0.568661630153656,
|
| 68 |
+
1.5752559900283813
|
| 69 |
+
],
|
| 70 |
+
[
|
| 71 |
+
-0.5686843395233154,
|
| 72 |
+
0.016434065997600555,
|
| 73 |
+
0.8223916888237,
|
| 74 |
+
0.5005193948745728
|
| 75 |
+
],
|
| 76 |
+
[
|
| 77 |
+
-0.004017705097794533,
|
| 78 |
+
-0.999843955039978,
|
| 79 |
+
0.017201894894242287,
|
| 80 |
+
1.5069602727890015
|
| 81 |
+
],
|
| 82 |
+
[
|
| 83 |
+
0.0,
|
| 84 |
+
0.0,
|
| 85 |
+
0.0,
|
| 86 |
+
1.0
|
| 87 |
+
]
|
| 88 |
+
],
|
| 89 |
+
[
|
| 90 |
+
[
|
| 91 |
+
0.010747148655354977,
|
| 92 |
+
-0.0066407592967152596,
|
| 93 |
+
-0.9999202489852905,
|
| 94 |
+
0.3301053047180176
|
| 95 |
+
],
|
| 96 |
+
[
|
| 97 |
+
0.9998782277107239,
|
| 98 |
+
0.011386878788471222,
|
| 99 |
+
0.010671093128621578,
|
| 100 |
+
0.008498914539813995
|
| 101 |
+
],
|
| 102 |
+
[
|
| 103 |
+
0.011315105482935905,
|
| 104 |
+
-0.9999130964279175,
|
| 105 |
+
0.006762326695024967,
|
| 106 |
+
1.5727975368499756
|
| 107 |
+
],
|
| 108 |
+
[
|
| 109 |
+
0.0,
|
| 110 |
+
0.0,
|
| 111 |
+
0.0,
|
| 112 |
+
1.0
|
| 113 |
+
]
|
| 114 |
+
],
|
| 115 |
+
[
|
| 116 |
+
[
|
| 117 |
+
0.9485073685646057,
|
| 118 |
+
-0.008619013242423534,
|
| 119 |
+
-0.3166378438472748,
|
| 120 |
+
1.4057787656784058
|
| 121 |
+
],
|
| 122 |
+
[
|
| 123 |
+
0.3167478144168854,
|
| 124 |
+
0.01902088336646557,
|
| 125 |
+
0.9483190178871155,
|
| 126 |
+
0.4778013229370117
|
| 127 |
+
],
|
| 128 |
+
[
|
| 129 |
+
-0.002150842687115073,
|
| 130 |
+
-0.9997819066047668,
|
| 131 |
+
0.02077149972319603,
|
| 132 |
+
1.5687693357467651
|
| 133 |
+
],
|
| 134 |
+
[
|
| 135 |
+
0.0,
|
| 136 |
+
0.0,
|
| 137 |
+
0.0,
|
| 138 |
+
1.0
|
| 139 |
+
]
|
| 140 |
+
],
|
| 141 |
+
[
|
| 142 |
+
[
|
| 143 |
+
-0.9232780933380127,
|
| 144 |
+
-0.0025498708710074425,
|
| 145 |
+
-0.38412362337112427,
|
| 146 |
+
1.257399082183838
|
| 147 |
+
],
|
| 148 |
+
[
|
| 149 |
+
0.384126752614975,
|
| 150 |
+
-0.011398540809750557,
|
| 151 |
+
-0.9232099652290344,
|
| 152 |
+
-0.46987396478652954
|
| 153 |
+
],
|
| 154 |
+
[
|
| 155 |
+
-0.0020243842154741287,
|
| 156 |
+
-0.999931812286377,
|
| 157 |
+
0.011503497138619423,
|
| 158 |
+
1.554057002067566
|
| 159 |
+
],
|
| 160 |
+
[
|
| 161 |
+
0.0,
|
| 162 |
+
0.0,
|
| 163 |
+
0.0,
|
| 164 |
+
1.0
|
| 165 |
+
]
|
| 166 |
+
]
|
| 167 |
+
],
|
| 168 |
+
"frame": 0,
|
| 169 |
+
"imageSizes": [
|
| 170 |
+
[
|
| 171 |
+
900,
|
| 172 |
+
1600
|
| 173 |
+
],
|
| 174 |
+
[
|
| 175 |
+
900,
|
| 176 |
+
1600
|
| 177 |
+
],
|
| 178 |
+
[
|
| 179 |
+
900,
|
| 180 |
+
1600
|
| 181 |
+
],
|
| 182 |
+
[
|
| 183 |
+
900,
|
| 184 |
+
1600
|
| 185 |
+
],
|
| 186 |
+
[
|
| 187 |
+
900,
|
| 188 |
+
1600
|
| 189 |
+
],
|
| 190 |
+
[
|
| 191 |
+
900,
|
| 192 |
+
1600
|
| 193 |
+
]
|
| 194 |
+
],
|
| 195 |
+
"intrinsics": [
|
| 196 |
+
[
|
| 197 |
+
[
|
| 198 |
+
1252.8131103515625,
|
| 199 |
+
0.0,
|
| 200 |
+
826.588134765625
|
| 201 |
+
],
|
| 202 |
+
[
|
| 203 |
+
0.0,
|
| 204 |
+
1252.8131103515625,
|
| 205 |
+
469.9846496582031
|
| 206 |
+
],
|
| 207 |
+
[
|
| 208 |
+
0.0,
|
| 209 |
+
0.0,
|
| 210 |
+
1.0
|
| 211 |
+
]
|
| 212 |
+
],
|
| 213 |
+
[
|
| 214 |
+
[
|
| 215 |
+
1256.74853515625,
|
| 216 |
+
0.0,
|
| 217 |
+
817.7887573242188
|
| 218 |
+
],
|
| 219 |
+
[
|
| 220 |
+
0.0,
|
| 221 |
+
1256.74853515625,
|
| 222 |
+
451.9541931152344
|
| 223 |
+
],
|
| 224 |
+
[
|
| 225 |
+
0.0,
|
| 226 |
+
0.0,
|
| 227 |
+
1.0
|
| 228 |
+
]
|
| 229 |
+
],
|
| 230 |
+
[
|
| 231 |
+
[
|
| 232 |
+
1257.862548828125,
|
| 233 |
+
0.0,
|
| 234 |
+
827.2410888671875
|
| 235 |
+
],
|
| 236 |
+
[
|
| 237 |
+
0.0,
|
| 238 |
+
1257.862548828125,
|
| 239 |
+
450.9154968261719
|
| 240 |
+
],
|
| 241 |
+
[
|
| 242 |
+
0.0,
|
| 243 |
+
0.0,
|
| 244 |
+
1.0
|
| 245 |
+
]
|
| 246 |
+
],
|
| 247 |
+
[
|
| 248 |
+
[
|
| 249 |
+
796.8910522460938,
|
| 250 |
+
0.0,
|
| 251 |
+
857.7774047851562
|
| 252 |
+
],
|
| 253 |
+
[
|
| 254 |
+
0.0,
|
| 255 |
+
796.8910522460938,
|
| 256 |
+
476.8848876953125
|
| 257 |
+
],
|
| 258 |
+
[
|
| 259 |
+
0.0,
|
| 260 |
+
0.0,
|
| 261 |
+
1.0
|
| 262 |
+
]
|
| 263 |
+
],
|
| 264 |
+
[
|
| 265 |
+
[
|
| 266 |
+
1254.986083984375,
|
| 267 |
+
0.0,
|
| 268 |
+
829.576904296875
|
| 269 |
+
],
|
| 270 |
+
[
|
| 271 |
+
0.0,
|
| 272 |
+
1254.986083984375,
|
| 273 |
+
467.1680603027344
|
| 274 |
+
],
|
| 275 |
+
[
|
| 276 |
+
0.0,
|
| 277 |
+
0.0,
|
| 278 |
+
1.0
|
| 279 |
+
]
|
| 280 |
+
],
|
| 281 |
+
[
|
| 282 |
+
[
|
| 283 |
+
1249.962890625,
|
| 284 |
+
0.0,
|
| 285 |
+
825.3768310546875
|
| 286 |
+
],
|
| 287 |
+
[
|
| 288 |
+
0.0,
|
| 289 |
+
1249.962890625,
|
| 290 |
+
462.54815673828125
|
| 291 |
+
],
|
| 292 |
+
[
|
| 293 |
+
0.0,
|
| 294 |
+
0.0,
|
| 295 |
+
1.0
|
| 296 |
+
]
|
| 297 |
+
]
|
| 298 |
+
],
|
| 299 |
+
"sceneId": "3950bd41f74548429c0f7700ff3d8269",
|
| 300 |
+
"version": 1
|
| 301 |
+
}
|
targets/QCS8550/FP16/composite.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"assets": {
|
| 3 |
+
"calibration": "calibration.json",
|
| 4 |
+
"frustum": "frustum.npy",
|
| 5 |
+
"ranks": "geometry-ranks.npz"
|
| 6 |
+
},
|
| 7 |
+
"components": {
|
| 8 |
+
"part1": "models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part1_qcs8550_fp16.qnn236.ctx.bin.amf",
|
| 9 |
+
"part3": "models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part3_qcs8550_fp16.qnn236.ctx.bin.amf"
|
| 10 |
+
},
|
| 11 |
+
"derivation": {
|
| 12 |
+
"files": {
|
| 13 |
+
"calibration.json": "c9bef4379a9cab2324cfc3ab5b18f3c3bbf4b4641d4b345b956c043928df67ce",
|
| 14 |
+
"frustum.npy": "37dd2f50e2f7b6451541088ccd3db3d8cd5697c52dcc60255c85bc1cb825e20b",
|
| 15 |
+
"geometry-ranks.npz": "40935c88bcc4b17aa5d4e661cbbab71f2b0627dadd754083fb4d91d95458fa43",
|
| 16 |
+
"models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part1_qcs8550_fp16.qnn236.ctx.bin.amf": "085d557642bba9d458e84fc5493325c9e59372192b450f6fbf4da40b070e1ddc",
|
| 17 |
+
"models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part3_qcs8550_fp16.qnn236.ctx.bin.amf": "741eacb785a6ef715126ba7d6f4a4ade294a13f9719c032a7ca34b57e3fa8811",
|
| 18 |
+
"reference/deployment/bev_pool_v2_cpu.py": "62c2c566ded450425aabbcf6e08cec72f02e63800c41f0afbb82a722abf80918",
|
| 19 |
+
"reference/deployment/postprocess_flashocc_qnn.py": "4dc7a2a9f2ffa5ea209e8d14ed34fa628258eb953400b41f762849127b6123ed",
|
| 20 |
+
"reference/part1.py": "a9177064f8ddf5cd9df17033ed35414bb96ca26f02e44dec8dd7e27f74922eeb",
|
| 21 |
+
"reference/part3.py": "ab2e976ec9ec229a4e12ba06896320fd6a8597f82466e654f23d4469b3962be1",
|
| 22 |
+
"reference/run_flashocc_split_onboard.py": "e13d4f407085e2a0db91c947ac4717803bd08f3f47130e82382930f006f3ae24",
|
| 23 |
+
"samples/back.jpg": "fdbdaa77e60ed5a6a762a4ea9a8eb1cb2ca9a3d94c610a55a2399a05c04b6ba6",
|
| 24 |
+
"samples/back_left.jpg": "000f7943769e91ffa842a7dfd1bfc31e0c3f4b37325a98846e8261304028f2ad",
|
| 25 |
+
"samples/back_right.jpg": "39d28a8a5a6f61370a7e7e1e965a6d8610b571195c50fd29da960e1fb2fbee80",
|
| 26 |
+
"samples/front.jpg": "d5624fcecf12310c3d0760362e097c38cdcdce987e032aaf2883071cd14e2732",
|
| 27 |
+
"samples/front_left.jpg": "0fe15c0581db41e084df27acb2183b0ab9b0fd36da136ef1b4bcbda6f1a84c58",
|
| 28 |
+
"samples/front_right.jpg": "dd64d7463bc06bfd5d5378bdd494b40d68d0894307f3ed971eaaaf131022cf68"
|
| 29 |
+
},
|
| 30 |
+
"numpyMatchesOriginalTorchAssignments": true,
|
| 31 |
+
"providedCachePointCount": 196321,
|
| 32 |
+
"recomputedPointCount": 300957,
|
| 33 |
+
"sourceCache": "code/python/datas/.flashocc_cache/n008-2018-08-01-15-16-36-0400__CAM_BACK__1533151603637558.jpg.stub.npz",
|
| 34 |
+
"sourceCacheSha256": "174c33d7798502a836f1f15ed02f23f19f158d806f4f8d5cfd77dab3161c7bd6",
|
| 35 |
+
"sourcePackageSha256": "7f5ae8b96b9086020fe22b928b24ec184ad91b61f66498596e252a86f2f74568",
|
| 36 |
+
"torch": "2.10.0+cu128"
|
| 37 |
+
},
|
| 38 |
+
"frames": [
|
| 39 |
+
{
|
| 40 |
+
"calibration": "calibration.json",
|
| 41 |
+
"images": [
|
| 42 |
+
{
|
| 43 |
+
"name": "CAM_FRONT",
|
| 44 |
+
"path": "samples/front.jpg",
|
| 45 |
+
"sha256": "d5624fcecf12310c3d0760362e097c38cdcdce987e032aaf2883071cd14e2732"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "CAM_FRONT_RIGHT",
|
| 49 |
+
"path": "samples/front_right.jpg",
|
| 50 |
+
"sha256": "dd64d7463bc06bfd5d5378bdd494b40d68d0894307f3ed971eaaaf131022cf68"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"name": "CAM_FRONT_LEFT",
|
| 54 |
+
"path": "samples/front_left.jpg",
|
| 55 |
+
"sha256": "0fe15c0581db41e084df27acb2183b0ab9b0fd36da136ef1b4bcbda6f1a84c58"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"name": "CAM_BACK",
|
| 59 |
+
"path": "samples/back.jpg",
|
| 60 |
+
"sha256": "fdbdaa77e60ed5a6a762a4ea9a8eb1cb2ca9a3d94c610a55a2399a05c04b6ba6"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"name": "CAM_BACK_LEFT",
|
| 64 |
+
"path": "samples/back_left.jpg",
|
| 65 |
+
"sha256": "000f7943769e91ffa842a7dfd1bfc31e0c3f4b37325a98846e8261304028f2ad"
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "CAM_BACK_RIGHT",
|
| 69 |
+
"path": "samples/back_right.jpg",
|
| 70 |
+
"sha256": "39d28a8a5a6f61370a7e7e1e965a6d8610b571195c50fd29da960e1fb2fbee80"
|
| 71 |
+
}
|
| 72 |
+
],
|
| 73 |
+
"key": "official"
|
| 74 |
+
}
|
| 75 |
+
],
|
| 76 |
+
"geometryKey": "400592a6a2df4d0179222689b8c876814f2125cb20473059476614e866c1d9f2",
|
| 77 |
+
"kind": "flashocc",
|
| 78 |
+
"version": 1
|
| 79 |
+
}
|
targets/QCS8550/FP16/frustum.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37dd2f50e2f7b6451541088ccd3db3d8cd5697c52dcc60255c85bc1cb825e20b
|
| 3 |
+
size 743552
|
targets/QCS8550/FP16/geometry-ranks.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40935c88bcc4b17aa5d4e661cbbab71f2b0627dadd754083fb4d91d95458fa43
|
| 3 |
+
size 3797788
|
targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part1_qcs8550_fp16.qnn236.ctx.bin.amf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:085d557642bba9d458e84fc5493325c9e59372192b450f6fbf4da40b070e1ddc
|
| 3 |
+
size 51956984
|
targets/QCS8550/FP16/models/QCS8550/FP16/bevdet_qnn_val_full_fuse_part3_qcs8550_fp16.qnn236.ctx.bin.amf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:741eacb785a6ef715126ba7d6f4a4ade294a13f9719c032a7ca34b57e3fa8811
|
| 3 |
+
size 40444856
|
targets/QCS8550/FP16/reference/deployment/bev_pool_v2_cpu.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
import os
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
from . import _bev_pool_v2_ext
|
| 9 |
+
except ImportError:
|
| 10 |
+
_bev_pool_v2_ext = None
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class BEVPoolV2Workspace:
|
| 14 |
+
def __init__(self, point_count, interval_count, bev_hw, channels, bev_indices=None):
|
| 15 |
+
self.point_count = int(point_count)
|
| 16 |
+
self.interval_count = int(interval_count)
|
| 17 |
+
self.bev_hw = int(bev_hw)
|
| 18 |
+
self.channels = int(channels)
|
| 19 |
+
self.gathered_feat = np.empty((self.point_count, self.channels), dtype=np.float32)
|
| 20 |
+
self.depth_values = np.empty((self.point_count,), dtype=np.float32)
|
| 21 |
+
self.weighted_feat = np.empty((self.point_count, self.channels), dtype=np.float32)
|
| 22 |
+
self.flat_bev = np.zeros((self.bev_hw, self.channels), dtype=np.float32)
|
| 23 |
+
self.bev_indices = None if bev_indices is None else np.asarray(bev_indices, dtype=np.int32)
|
| 24 |
+
|
| 25 |
+
@classmethod
|
| 26 |
+
def from_inputs(cls, ranks_feat, interval_starts, ranks_bev, bev_shape):
|
| 27 |
+
bev_height = int(bev_shape[1])
|
| 28 |
+
bev_width = int(bev_shape[2])
|
| 29 |
+
channels = int(bev_shape[3])
|
| 30 |
+
bev_indices = ranks_bev[interval_starts]
|
| 31 |
+
return cls(
|
| 32 |
+
point_count=ranks_feat.shape[0],
|
| 33 |
+
interval_count=interval_starts.shape[0],
|
| 34 |
+
bev_hw=bev_height * bev_width,
|
| 35 |
+
channels=channels,
|
| 36 |
+
bev_indices=bev_indices,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def validate(self, ranks_feat, interval_starts, bev_shape):
|
| 40 |
+
expected = (
|
| 41 |
+
int(ranks_feat.shape[0]),
|
| 42 |
+
int(interval_starts.shape[0]),
|
| 43 |
+
int(bev_shape[1]) * int(bev_shape[2]),
|
| 44 |
+
int(bev_shape[3]),
|
| 45 |
+
)
|
| 46 |
+
actual = (self.point_count, self.interval_count, self.bev_hw, self.channels)
|
| 47 |
+
if actual != expected:
|
| 48 |
+
raise ValueError(f'workspace shape mismatch: expected={expected}, actual={actual}')
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def has_cpp_backend():
|
| 52 |
+
return _bev_pool_v2_ext is not None
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def has_cpp_prepare_backend():
|
| 56 |
+
return _bev_pool_v2_ext is not None and hasattr(_bev_pool_v2_ext, 'voxel_pooling_prepare_v2_forward')
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def voxel_pooling_prepare_v2_cpp(coordinates, grid_lower_bound, grid_interval, grid_size):
|
| 60 |
+
if not has_cpp_prepare_backend():
|
| 61 |
+
raise RuntimeError('C++ voxel_pooling_prepare_v2 backend is unavailable')
|
| 62 |
+
return _bev_pool_v2_ext.voxel_pooling_prepare_v2_forward(
|
| 63 |
+
np.ascontiguousarray(coordinates, dtype=np.float32),
|
| 64 |
+
np.ascontiguousarray(grid_lower_bound, dtype=np.float32),
|
| 65 |
+
np.ascontiguousarray(grid_interval, dtype=np.float32),
|
| 66 |
+
np.ascontiguousarray(grid_size, dtype=np.int32),
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def parse_args():
|
| 71 |
+
parser = argparse.ArgumentParser(description='Run FlashOCC bev_pool_v2 on CPU with NumPy')
|
| 72 |
+
parser.add_argument('tran_feat_path', help='raw or npy file for part1 tran_feat output')
|
| 73 |
+
parser.add_argument('depth_path', help='raw or npy file for part1 depth output')
|
| 74 |
+
parser.add_argument('sample_manifest', help='split_qnn_sample.json generated by prepare_flashocc_split_qnn_sample.py')
|
| 75 |
+
parser.add_argument('output_dir', help='directory to save bev_feat for part3 input')
|
| 76 |
+
parser.add_argument('--save-npy', action='store_true', help='also save .npy files beside .raw')
|
| 77 |
+
return parser.parse_args()
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def load_manifest(path):
|
| 81 |
+
with open(path, 'r', encoding='utf-8') as handle:
|
| 82 |
+
return json.load(handle)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def load_array(path, dtype, shape):
|
| 86 |
+
if path.endswith('.npy'):
|
| 87 |
+
array = np.load(path)
|
| 88 |
+
else:
|
| 89 |
+
array = np.fromfile(path, dtype=np.dtype(dtype))
|
| 90 |
+
return array.reshape(shape)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def resolve_meta_path(base_dir, entry):
|
| 94 |
+
return os.path.join(base_dir, entry['file'])
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def validate_intervals(interval_starts, interval_lengths, total_points):
|
| 98 |
+
if interval_starts.ndim != 1 or interval_lengths.ndim != 1:
|
| 99 |
+
raise ValueError('interval_starts and interval_lengths must be 1D arrays')
|
| 100 |
+
if interval_starts.shape[0] != interval_lengths.shape[0]:
|
| 101 |
+
raise ValueError('interval_starts and interval_lengths length mismatch')
|
| 102 |
+
if interval_starts.shape[0] == 0:
|
| 103 |
+
return
|
| 104 |
+
expected_lengths = np.empty_like(interval_lengths)
|
| 105 |
+
expected_lengths[:-1] = interval_starts[1:] - interval_starts[:-1]
|
| 106 |
+
expected_lengths[-1] = total_points - interval_starts[-1]
|
| 107 |
+
if not np.array_equal(expected_lengths, interval_lengths):
|
| 108 |
+
raise ValueError('interval metadata is inconsistent with contiguous grouped points')
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def bev_pool_v2_cpu(tran_feat, depth, ranks_depth, ranks_feat, ranks_bev,
|
| 112 |
+
interval_starts, interval_lengths, bev_shape, workspace=None):
|
| 113 |
+
validate_intervals(interval_starts, interval_lengths, ranks_bev.shape[0])
|
| 114 |
+
|
| 115 |
+
bev_height = int(bev_shape[1])
|
| 116 |
+
bev_width = int(bev_shape[2])
|
| 117 |
+
channels = int(bev_shape[3])
|
| 118 |
+
bev_indices = ranks_bev[interval_starts]
|
| 119 |
+
|
| 120 |
+
if _bev_pool_v2_ext is not None:
|
| 121 |
+
if workspace is None:
|
| 122 |
+
workspace = BEVPoolV2Workspace.from_inputs(ranks_feat, interval_starts, ranks_bev, bev_shape)
|
| 123 |
+
workspace.validate(ranks_feat, interval_starts, bev_shape)
|
| 124 |
+
_bev_pool_v2_ext.bev_pool_v2_forward(
|
| 125 |
+
np.ascontiguousarray(tran_feat, dtype=np.float32),
|
| 126 |
+
np.ascontiguousarray(depth, dtype=np.float32),
|
| 127 |
+
np.ascontiguousarray(ranks_depth, dtype=np.int32),
|
| 128 |
+
np.ascontiguousarray(ranks_feat, dtype=np.int32),
|
| 129 |
+
np.ascontiguousarray(workspace.bev_indices if workspace.bev_indices is not None else bev_indices, dtype=np.int32),
|
| 130 |
+
np.ascontiguousarray(interval_starts, dtype=np.int32),
|
| 131 |
+
np.ascontiguousarray(interval_lengths, dtype=np.int32),
|
| 132 |
+
workspace.flat_bev,
|
| 133 |
+
)
|
| 134 |
+
return workspace.flat_bev.reshape(bev_shape)
|
| 135 |
+
|
| 136 |
+
if workspace is not None:
|
| 137 |
+
workspace.validate(ranks_feat, interval_starts, bev_shape)
|
| 138 |
+
np.take(tran_feat, ranks_feat, axis=0, out=workspace.gathered_feat)
|
| 139 |
+
np.take(depth, ranks_depth, axis=0, out=workspace.depth_values)
|
| 140 |
+
np.multiply(workspace.gathered_feat, workspace.depth_values[:, None], out=workspace.weighted_feat)
|
| 141 |
+
reduced_feat = np.add.reduceat(workspace.weighted_feat, interval_starts, axis=0)
|
| 142 |
+
workspace.flat_bev.fill(0)
|
| 143 |
+
workspace.flat_bev[workspace.bev_indices if workspace.bev_indices is not None else bev_indices] = reduced_feat.astype(np.float32, copy=False)
|
| 144 |
+
return workspace.flat_bev.reshape(bev_shape)
|
| 145 |
+
|
| 146 |
+
weighted_feat = tran_feat[ranks_feat] * depth[ranks_depth][:, None]
|
| 147 |
+
reduced_feat = np.add.reduceat(weighted_feat, interval_starts, axis=0)
|
| 148 |
+
flat_bev = np.zeros((bev_height * bev_width, channels), dtype=np.float32)
|
| 149 |
+
flat_bev[bev_indices] = reduced_feat.astype(np.float32, copy=False)
|
| 150 |
+
return flat_bev.reshape(bev_shape)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def save_array(output_dir, name, array, save_npy):
|
| 154 |
+
raw_path = os.path.join(output_dir, f'{name}.raw')
|
| 155 |
+
array.tofile(raw_path)
|
| 156 |
+
print('saved:', raw_path, list(array.shape), array.dtype)
|
| 157 |
+
if save_npy:
|
| 158 |
+
npy_path = os.path.join(output_dir, f'{name}.npy')
|
| 159 |
+
np.save(npy_path, array)
|
| 160 |
+
print('saved:', npy_path)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def main():
|
| 164 |
+
args = parse_args()
|
| 165 |
+
os.makedirs(args.output_dir, exist_ok=True)
|
| 166 |
+
|
| 167 |
+
manifest = load_manifest(args.sample_manifest)
|
| 168 |
+
base_dir = os.path.dirname(args.sample_manifest)
|
| 169 |
+
|
| 170 |
+
tran_feat_shape = manifest['part1_outputs'][0]['shape']
|
| 171 |
+
depth_shape = manifest['part1_outputs'][1]['shape']
|
| 172 |
+
bev_shape = manifest['part3_inputs'][0]['unflattened_shape']
|
| 173 |
+
|
| 174 |
+
tran_feat = load_array(args.tran_feat_path, 'float32', tran_feat_shape).astype(np.float32, copy=False)
|
| 175 |
+
depth = load_array(args.depth_path, 'float32', depth_shape).astype(np.float32, copy=False)
|
| 176 |
+
|
| 177 |
+
bev_inputs = {entry['name']: entry for entry in manifest['bev_pool_inputs']}
|
| 178 |
+
ranks_depth = load_array(resolve_meta_path(base_dir, bev_inputs['ranks_depth']), 'int32', bev_inputs['ranks_depth']['shape'])
|
| 179 |
+
ranks_feat = load_array(resolve_meta_path(base_dir, bev_inputs['ranks_feat']), 'int32', bev_inputs['ranks_feat']['shape'])
|
| 180 |
+
ranks_bev = load_array(resolve_meta_path(base_dir, bev_inputs['ranks_bev']), 'int32', bev_inputs['ranks_bev']['shape'])
|
| 181 |
+
interval_starts = load_array(resolve_meta_path(base_dir, bev_inputs['interval_starts']), 'int32', bev_inputs['interval_starts']['shape'])
|
| 182 |
+
interval_lengths = load_array(resolve_meta_path(base_dir, bev_inputs['interval_lengths']), 'int32', bev_inputs['interval_lengths']['shape'])
|
| 183 |
+
|
| 184 |
+
bev_feat = bev_pool_v2_cpu(
|
| 185 |
+
tran_feat=tran_feat,
|
| 186 |
+
depth=depth,
|
| 187 |
+
ranks_depth=ranks_depth,
|
| 188 |
+
ranks_feat=ranks_feat,
|
| 189 |
+
ranks_bev=ranks_bev,
|
| 190 |
+
interval_starts=interval_starts,
|
| 191 |
+
interval_lengths=interval_lengths,
|
| 192 |
+
bev_shape=bev_shape,
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
save_array(args.output_dir, 'bev_feat', bev_feat.reshape(-1).astype(np.float32, copy=False), args.save_npy)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
if __name__ == '__main__':
|
| 199 |
+
main()
|
targets/QCS8550/FP16/reference/deployment/postprocess_flashocc_qnn.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import cv2
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
COLORS_MAP = np.array(
|
| 10 |
+
[
|
| 11 |
+
[0, 0, 0, 255],
|
| 12 |
+
[255, 158, 0, 255],
|
| 13 |
+
[0, 0, 230, 255],
|
| 14 |
+
[47, 79, 79, 255],
|
| 15 |
+
[220, 20, 60, 255],
|
| 16 |
+
[255, 69, 0, 255],
|
| 17 |
+
[255, 140, 0, 255],
|
| 18 |
+
[233, 150, 70, 255],
|
| 19 |
+
[255, 61, 99, 255],
|
| 20 |
+
[112, 128, 144, 255],
|
| 21 |
+
[222, 184, 135, 255],
|
| 22 |
+
[0, 175, 0, 255],
|
| 23 |
+
[165, 42, 42, 255],
|
| 24 |
+
[0, 207, 191, 255],
|
| 25 |
+
[75, 0, 75, 255],
|
| 26 |
+
[255, 0, 0, 255],
|
| 27 |
+
[0, 0, 0, 0],
|
| 28 |
+
[0, 0, 0, 0],
|
| 29 |
+
],
|
| 30 |
+
dtype=np.uint8)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def parse_args():
|
| 34 |
+
parser = argparse.ArgumentParser(description='Postprocess FlashOCC QNN output')
|
| 35 |
+
parser.add_argument('output_path', help='QNN output raw or npy file for output_0')
|
| 36 |
+
parser.add_argument('save_dir', help='directory to save postprocessed results')
|
| 37 |
+
parser.add_argument('--meta', default=None, help='metadata json generated during export')
|
| 38 |
+
parser.add_argument(
|
| 39 |
+
'--output-shape',
|
| 40 |
+
default='1,200,200,16,18',
|
| 41 |
+
help='fallback output shape if metadata is not provided')
|
| 42 |
+
parser.add_argument('--dtype', default='float32', help='output dtype, default float32')
|
| 43 |
+
return parser.parse_args()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def load_output_shape(args):
|
| 47 |
+
if args.meta:
|
| 48 |
+
with open(args.meta, 'r', encoding='utf-8') as handle:
|
| 49 |
+
metadata = json.load(handle)
|
| 50 |
+
if metadata['outputs']:
|
| 51 |
+
shape = metadata['outputs'][0]['shape']
|
| 52 |
+
if all(isinstance(dim, int) for dim in shape):
|
| 53 |
+
return shape
|
| 54 |
+
return [int(item) for item in args.output_shape.split(',')]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def load_output_array(path, dtype, shape):
|
| 58 |
+
if path.endswith('.npy'):
|
| 59 |
+
array = np.load(path)
|
| 60 |
+
else:
|
| 61 |
+
array = np.fromfile(path, dtype=np.dtype(dtype))
|
| 62 |
+
return array.reshape(shape)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def logits_to_occ_labels(logits):
|
| 66 |
+
return np.argmax(logits, axis=-1).astype(np.uint8)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def vis_occ(semantics):
|
| 70 |
+
semantics_valid = np.logical_not(semantics == 17)
|
| 71 |
+
depth_axis = np.arange(semantics.shape[2]).reshape(1, 1, semantics.shape[2])
|
| 72 |
+
depth_axis = np.repeat(depth_axis, semantics.shape[0], axis=0)
|
| 73 |
+
depth_axis = np.repeat(depth_axis, semantics.shape[1], axis=1).astype(np.float32)
|
| 74 |
+
depth_axis = depth_axis * semantics_valid
|
| 75 |
+
selected = np.argmax(depth_axis, axis=2)
|
| 76 |
+
occ_bev = np.take_along_axis(semantics, selected[..., None], axis=2)
|
| 77 |
+
occ_bev = occ_bev.reshape(semantics.shape[0], semantics.shape[1]).astype(np.int32)
|
| 78 |
+
occ_bev_vis = COLORS_MAP[occ_bev].reshape(semantics.shape[0], semantics.shape[1], 4)[::-1, ::-1, :3]
|
| 79 |
+
return cv2.resize(occ_bev_vis, (400, 400))
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def main():
|
| 83 |
+
args = parse_args()
|
| 84 |
+
os.makedirs(args.save_dir, exist_ok=True)
|
| 85 |
+
|
| 86 |
+
output_shape = load_output_shape(args)
|
| 87 |
+
logits = load_output_array(args.output_path, args.dtype, output_shape)
|
| 88 |
+
occ_labels = logits_to_occ_labels(logits)
|
| 89 |
+
bev_vis = vis_occ(occ_labels[0])
|
| 90 |
+
|
| 91 |
+
logits_path = os.path.join(args.save_dir, 'output_0.npy')
|
| 92 |
+
labels_path = os.path.join(args.save_dir, 'occ_labels.npy')
|
| 93 |
+
vis_path = os.path.join(args.save_dir, 'occ_bev.png')
|
| 94 |
+
np.save(logits_path, logits)
|
| 95 |
+
np.save(labels_path, occ_labels)
|
| 96 |
+
cv2.imwrite(vis_path, bev_vis)
|
| 97 |
+
|
| 98 |
+
print('saved:', logits_path)
|
| 99 |
+
print('saved:', labels_path)
|
| 100 |
+
print('saved:', vis_path)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
if __name__ == '__main__':
|
| 104 |
+
main()
|
targets/QCS8550/FP16/reference/part1.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import aidlite
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class FlashOccPart1(object):
|
| 7 |
+
def __init__(self, model_path, verbose=False):
|
| 8 |
+
self.input_shape = [[6, 256, 704, 3]]
|
| 9 |
+
self.output_shape = [[4224,64], [371712]]
|
| 10 |
+
self.verbose = verbose
|
| 11 |
+
|
| 12 |
+
self.model = aidlite.Model.create_instance(model_path)
|
| 13 |
+
if self.model is None:
|
| 14 |
+
print("Create model failed !")
|
| 15 |
+
return
|
| 16 |
+
self.model.set_model_properties(self.input_shape, aidlite.DataType.TYPE_FLOAT32, self.output_shape,
|
| 17 |
+
aidlite.DataType.TYPE_FLOAT32)
|
| 18 |
+
|
| 19 |
+
self.config = aidlite.Config.create_instance()
|
| 20 |
+
if self.config is None:
|
| 21 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
self.config.implement_type = aidlite.ImplementType.TYPE_LOCAL
|
| 25 |
+
self.config.framework_type = aidlite.FrameworkType.TYPE_QNN
|
| 26 |
+
self.config.accelerate_type = aidlite.AccelerateType.TYPE_DSP
|
| 27 |
+
self.config.is_quantify_model = 1
|
| 28 |
+
|
| 29 |
+
self.interpreter = aidlite.InterpreterBuilder.build_interpretper_from_model_and_config(self.model, self.config)
|
| 30 |
+
if self.interpreter is None:
|
| 31 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
self.interpreter.init()
|
| 35 |
+
self.interpreter.load_model()
|
| 36 |
+
|
| 37 |
+
def __del__(self):
|
| 38 |
+
self.interpreter.destory()
|
| 39 |
+
|
| 40 |
+
def __call__(self, img):
|
| 41 |
+
self.interpreter.set_input_tensor(0, img.data)
|
| 42 |
+
t1 = time.perf_counter()
|
| 43 |
+
self.interpreter.invoke()
|
| 44 |
+
cost_time = (time.perf_counter() - t1) * 1000
|
| 45 |
+
if self.verbose:
|
| 46 |
+
print(f'part1 qnn invoke: {cost_time:.3f}ms')
|
| 47 |
+
qnn_out_0 = self.interpreter.get_output_tensor(0).reshape(4224,64)
|
| 48 |
+
qnn_out_1 = self.interpreter.get_output_tensor(1)
|
| 49 |
+
outputs = qnn_out_0, qnn_out_1
|
| 50 |
+
return outputs
|
targets/QCS8550/FP16/reference/part3.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import aidlite
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class FlashOccPart3(object):
|
| 7 |
+
def __init__(self, model_path, verbose=False):
|
| 8 |
+
self.input_shape = [[2560000]]
|
| 9 |
+
self.output_shape = [[1,200,200,16,18]]
|
| 10 |
+
self.verbose = verbose
|
| 11 |
+
|
| 12 |
+
self.model = aidlite.Model.create_instance(model_path)
|
| 13 |
+
if self.model is None:
|
| 14 |
+
print("Create model failed !")
|
| 15 |
+
return
|
| 16 |
+
self.model.set_model_properties(self.input_shape, aidlite.DataType.TYPE_FLOAT32, self.output_shape,
|
| 17 |
+
aidlite.DataType.TYPE_FLOAT32)
|
| 18 |
+
|
| 19 |
+
self.config = aidlite.Config.create_instance()
|
| 20 |
+
if self.config is None:
|
| 21 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
self.config.implement_type = aidlite.ImplementType.TYPE_LOCAL
|
| 25 |
+
self.config.framework_type = aidlite.FrameworkType.TYPE_QNN
|
| 26 |
+
self.config.accelerate_type = aidlite.AccelerateType.TYPE_DSP
|
| 27 |
+
self.config.is_quantify_model = 1
|
| 28 |
+
|
| 29 |
+
self.interpreter = aidlite.InterpreterBuilder.build_interpretper_from_model_and_config(self.model, self.config)
|
| 30 |
+
if self.interpreter is None:
|
| 31 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
self.interpreter.init()
|
| 35 |
+
self.interpreter.load_model()
|
| 36 |
+
|
| 37 |
+
def __del__(self):
|
| 38 |
+
self.interpreter.destory()
|
| 39 |
+
|
| 40 |
+
def __call__(self, img):
|
| 41 |
+
self.interpreter.set_input_tensor(0, img.data)
|
| 42 |
+
t1 = time.perf_counter()
|
| 43 |
+
self.interpreter.invoke()
|
| 44 |
+
cost_time = (time.perf_counter() - t1) * 1000
|
| 45 |
+
if self.verbose:
|
| 46 |
+
print(f'part3 qnn invoke: {cost_time:.3f}ms')
|
| 47 |
+
qnn_out_0 = self.interpreter.get_output_tensor(0).reshape(1,200,200,16,18)
|
| 48 |
+
outputs = qnn_out_0
|
| 49 |
+
return outputs
|
targets/QCS8550/FP16/reference/run_flashocc_split_onboard.py
ADDED
|
@@ -0,0 +1,728 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
import torch
|
| 12 |
+
from pyquaternion import Quaternion
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
from turbojpeg import TJPF_BGR, TurboJPEG
|
| 16 |
+
TURBOJPEG_IMPORT_ERROR = None
|
| 17 |
+
except ImportError:
|
| 18 |
+
TJPF_BGR = None
|
| 19 |
+
TurboJPEG = None
|
| 20 |
+
TURBOJPEG_IMPORT_ERROR = sys.exc_info()[1]
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
from deployment import _image_preprocess_ext
|
| 24 |
+
except ImportError:
|
| 25 |
+
_image_preprocess_ext = None
|
| 26 |
+
|
| 27 |
+
sys.path.insert(0, os.getcwd())
|
| 28 |
+
|
| 29 |
+
from deployment.bev_pool_v2_cpu import (
|
| 30 |
+
BEVPoolV2Workspace,
|
| 31 |
+
bev_pool_v2_cpu,
|
| 32 |
+
has_cpp_prepare_backend,
|
| 33 |
+
voxel_pooling_prepare_v2_cpp,
|
| 34 |
+
)
|
| 35 |
+
from deployment.postprocess_flashocc_qnn import logits_to_occ_labels, vis_occ
|
| 36 |
+
|
| 37 |
+
DATA_CONFIG = {
|
| 38 |
+
'cams': [
|
| 39 |
+
'CAM_FRONT_LEFT', 'CAM_FRONT', 'CAM_FRONT_RIGHT',
|
| 40 |
+
'CAM_BACK_LEFT', 'CAM_BACK', 'CAM_BACK_RIGHT'
|
| 41 |
+
],
|
| 42 |
+
'Ncams': 6,
|
| 43 |
+
'input_size': (256, 704),
|
| 44 |
+
'src_size': (900, 1600),
|
| 45 |
+
'resize': (-0.06, 0.11),
|
| 46 |
+
'rot': (-5.4, 5.4),
|
| 47 |
+
'flip': True,
|
| 48 |
+
'crop_h': (0.0, 0.0),
|
| 49 |
+
'resize_test': 0.0,
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
GRID_CONFIG = {
|
| 53 |
+
'x': [-40, 40, 0.4],
|
| 54 |
+
'y': [-40, 40, 0.4],
|
| 55 |
+
'z': [-1, 5.4, 6.4],
|
| 56 |
+
'depth': [1.0, 45.0, 0.5],
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
IMG_MEAN = np.array([123.675, 116.28, 103.53], dtype=np.float32)
|
| 60 |
+
IMG_STD = np.array([58.395, 57.12, 57.375], dtype=np.float32)
|
| 61 |
+
TO_RGB = True
|
| 62 |
+
BEV_OUT_CHANNELS = 64
|
| 63 |
+
DOWNSAMPLE = 16
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_args():
|
| 67 |
+
parser = argparse.ArgumentParser(
|
| 68 |
+
description='Run split FlashOCC inference from data_predict without mmcv/mmdet3d dependencies')
|
| 69 |
+
parser.add_argument(
|
| 70 |
+
'--predict-root',
|
| 71 |
+
required=True,
|
| 72 |
+
help='directory containing v1.0-mini metadata and samples/CAM_* images')
|
| 73 |
+
parser.add_argument(
|
| 74 |
+
'--target-image',
|
| 75 |
+
required=True,
|
| 76 |
+
help='target image filename used to resolve the parent sample token')
|
| 77 |
+
parser.add_argument(
|
| 78 |
+
'--backend',
|
| 79 |
+
choices=['stub', 'onnxruntime'],
|
| 80 |
+
default='stub',
|
| 81 |
+
help='execution backend for part1/part3; replace stub with your QNN SDK calls on board')
|
| 82 |
+
parser.add_argument('--part1-model', default=None, help='path to part1 model file for onnxruntime debug mode')
|
| 83 |
+
parser.add_argument('--part3-model', default=None, help='path to part3 model file for onnxruntime debug mode')
|
| 84 |
+
parser.add_argument(
|
| 85 |
+
'--image-backend',
|
| 86 |
+
choices=['auto', 'cv2', 'turbojpeg'],
|
| 87 |
+
default='cv2',
|
| 88 |
+
help='jpeg decode backend for camera images; auto prefers turbojpeg when available')
|
| 89 |
+
parser.add_argument(
|
| 90 |
+
'--preprocess-backend',
|
| 91 |
+
choices=['auto', 'python', 'process', 'cpp'],
|
| 92 |
+
default='cpp',
|
| 93 |
+
help='image preprocessing backend; auto prefers cpp, then process, then python')
|
| 94 |
+
parser.add_argument('--save-dir', default=None, help='optional directory to save final png/json only')
|
| 95 |
+
parser.add_argument('--dump-logits', action='store_true', help='save output_0.npy to save-dir or current directory')
|
| 96 |
+
parser.add_argument('--verbose', action='store_true', help='print detailed per-stage logs')
|
| 97 |
+
return parser.parse_args()
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def load_json(path):
|
| 101 |
+
with open(path, 'r', encoding='utf-8') as handle:
|
| 102 |
+
return json.load(handle)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@lru_cache(maxsize=4)
|
| 106 |
+
def load_predict_metadata(meta_root):
|
| 107 |
+
sample_data = load_json(os.path.join(meta_root, 'sample_data.json'))
|
| 108 |
+
calibrated_sensor = build_token_index(load_json(os.path.join(meta_root, 'calibrated_sensor.json')))
|
| 109 |
+
ego_pose = build_token_index(load_json(os.path.join(meta_root, 'ego_pose.json')))
|
| 110 |
+
sensor = build_token_index(load_json(os.path.join(meta_root, 'sensor.json')))
|
| 111 |
+
return sample_data, calibrated_sensor, ego_pose, sensor
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def build_token_index(items):
|
| 115 |
+
return {item['token']: item for item in items}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def resolve_existing_path(root_dir, relative_path):
|
| 119 |
+
candidate = os.path.join(root_dir, relative_path)
|
| 120 |
+
if os.path.exists(candidate):
|
| 121 |
+
return candidate
|
| 122 |
+
|
| 123 |
+
basename = os.path.basename(relative_path)
|
| 124 |
+
for base_dir in ['samples', 'sweeps', '.']:
|
| 125 |
+
base_path = os.path.join(root_dir, base_dir)
|
| 126 |
+
if not os.path.isdir(base_path):
|
| 127 |
+
continue
|
| 128 |
+
for current_root, _, files in os.walk(base_path):
|
| 129 |
+
if basename in files:
|
| 130 |
+
return os.path.join(current_root, basename)
|
| 131 |
+
return candidate
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def normalize_image(img):
|
| 135 |
+
array = np.asarray(img, dtype=np.float32)
|
| 136 |
+
if TO_RGB:
|
| 137 |
+
array = array[..., ::-1]
|
| 138 |
+
array = (array - IMG_MEAN) / IMG_STD
|
| 139 |
+
return np.ascontiguousarray(array)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@lru_cache(maxsize=1)
|
| 143 |
+
def get_turbojpeg_decoder():
|
| 144 |
+
if TurboJPEG is None:
|
| 145 |
+
return None
|
| 146 |
+
try:
|
| 147 |
+
return TurboJPEG()
|
| 148 |
+
except Exception:
|
| 149 |
+
get_turbojpeg_decoder.last_error = sys.exc_info()[1]
|
| 150 |
+
return None
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
get_turbojpeg_decoder.last_error = None
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def resolve_image_backend(image_backend):
|
| 157 |
+
if image_backend == 'cv2':
|
| 158 |
+
return 'cv2', None
|
| 159 |
+
|
| 160 |
+
decoder = get_turbojpeg_decoder()
|
| 161 |
+
if decoder is not None:
|
| 162 |
+
return 'turbojpeg', decoder
|
| 163 |
+
|
| 164 |
+
if image_backend == 'turbojpeg':
|
| 165 |
+
if TURBOJPEG_IMPORT_ERROR is not None:
|
| 166 |
+
raise RuntimeError(
|
| 167 |
+
'turbojpeg backend requested, but importing turbojpeg failed: '
|
| 168 |
+
f'{TURBOJPEG_IMPORT_ERROR}. Install PyTurboJPEG into the same Python environment used to run this script.'
|
| 169 |
+
)
|
| 170 |
+
if get_turbojpeg_decoder.last_error is not None:
|
| 171 |
+
decoder_error = str(get_turbojpeg_decoder.last_error)
|
| 172 |
+
if 'requires libjpeg-turbo 3.0 or later' in decoder_error:
|
| 173 |
+
raise RuntimeError(
|
| 174 |
+
'turbojpeg backend requested, but creating TurboJPEG() failed: '
|
| 175 |
+
f'{decoder_error}. Your board currently has libjpeg-turbo 2.x; use PyTurboJPEG<2, '
|
| 176 |
+
'or upgrade the system libjpeg-turbo to 3.x before using PyTurboJPEG 2.x.'
|
| 177 |
+
)
|
| 178 |
+
raise RuntimeError(
|
| 179 |
+
'turbojpeg backend requested, but creating TurboJPEG() failed: '
|
| 180 |
+
f'{get_turbojpeg_decoder.last_error}. This usually means libturbojpeg is missing or not visible to the loader.'
|
| 181 |
+
)
|
| 182 |
+
raise RuntimeError('turbojpeg backend requested, but PyTurboJPEG or libturbojpeg is unavailable')
|
| 183 |
+
return 'cv2', None
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def load_camera_image(image_path, backend, turbojpeg_decoder=None):
|
| 187 |
+
if backend == 'turbojpeg':
|
| 188 |
+
with open(image_path, 'rb') as handle:
|
| 189 |
+
encoded = handle.read()
|
| 190 |
+
image = turbojpeg_decoder.decode(encoded, pixel_format=TJPF_BGR)
|
| 191 |
+
else:
|
| 192 |
+
image = cv2.imread(image_path, cv2.IMREAD_COLOR)
|
| 193 |
+
|
| 194 |
+
if image is None:
|
| 195 |
+
raise FileNotFoundError(f'failed to read image: {image_path}')
|
| 196 |
+
return image
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def has_cpp_preprocess_backend():
|
| 200 |
+
return _image_preprocess_ext is not None
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def resolve_preprocess_backend(preprocess_backend):
|
| 204 |
+
if preprocess_backend == 'python':
|
| 205 |
+
return 'python'
|
| 206 |
+
if preprocess_backend == 'process':
|
| 207 |
+
return 'process'
|
| 208 |
+
if preprocess_backend == 'cpp':
|
| 209 |
+
if not has_cpp_preprocess_backend():
|
| 210 |
+
raise RuntimeError(
|
| 211 |
+
'cpp preprocess backend requested, but deployment/_image_preprocess_ext is unavailable. '
|
| 212 |
+
'Build it first with: cd deployment && python setup_image_preprocess_ext.py build_ext --inplace'
|
| 213 |
+
)
|
| 214 |
+
return 'cpp'
|
| 215 |
+
if has_cpp_preprocess_backend():
|
| 216 |
+
return 'cpp'
|
| 217 |
+
if (os.cpu_count() or 1) > 1:
|
| 218 |
+
return 'process'
|
| 219 |
+
return 'python'
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def load_and_preprocess_one_image(image_path, image_backend):
|
| 223 |
+
resolved_image_backend, turbojpeg_decoder = resolve_image_backend(image_backend)
|
| 224 |
+
image = load_camera_image(image_path, resolved_image_backend, turbojpeg_decoder)
|
| 225 |
+
resize, resize_dims, crop, flip, rotate = sample_test_augmentation(image.shape[0], image.shape[1])
|
| 226 |
+
image, post_rot, post_tran = transform_image(image, resize, resize_dims, crop, flip, rotate)
|
| 227 |
+
return {
|
| 228 |
+
'image': normalize_image(image),
|
| 229 |
+
'post_rot': post_rot.numpy(),
|
| 230 |
+
'post_tran': post_tran.numpy(),
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def load_and_preprocess_images_process_pool(image_paths, image_backend):
|
| 235 |
+
max_workers = min(len(image_paths), max(1, os.cpu_count() or 1))
|
| 236 |
+
with concurrent.futures.ProcessPoolExecutor(max_workers=max_workers) as executor:
|
| 237 |
+
results = list(executor.map(load_and_preprocess_one_image, image_paths, [image_backend] * len(image_paths)))
|
| 238 |
+
return results
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def sample_test_augmentation(height, width):
|
| 242 |
+
final_height, final_width = DATA_CONFIG['input_size']
|
| 243 |
+
resize = float(final_width) / float(width) + DATA_CONFIG.get('resize_test', 0.0)
|
| 244 |
+
resize_dims = (int(width * resize), int(height * resize))
|
| 245 |
+
new_width, new_height = resize_dims
|
| 246 |
+
crop_h = int((1 - np.mean(DATA_CONFIG['crop_h'])) * new_height) - final_height
|
| 247 |
+
crop_w = int(max(0, new_width - final_width) / 2)
|
| 248 |
+
crop = (crop_w, crop_h, crop_w + final_width, crop_h + final_height)
|
| 249 |
+
flip = False
|
| 250 |
+
rotate = 0.0
|
| 251 |
+
return resize, resize_dims, crop, flip, rotate
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def get_rot_matrix(angle_radians):
|
| 255 |
+
return torch.tensor([
|
| 256 |
+
[np.cos(angle_radians), np.sin(angle_radians)],
|
| 257 |
+
[-np.sin(angle_radians), np.cos(angle_radians)],
|
| 258 |
+
], dtype=torch.float32)
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def apply_image_transform(img, resize_dims, crop, flip, rotate):
|
| 262 |
+
img = cv2.resize(img, resize_dims, interpolation=cv2.INTER_LINEAR)
|
| 263 |
+
crop_w0, crop_h0, crop_w1, crop_h1 = crop
|
| 264 |
+
img = img[crop_h0:crop_h1, crop_w0:crop_w1]
|
| 265 |
+
if flip:
|
| 266 |
+
img = cv2.flip(img, 1)
|
| 267 |
+
if rotate:
|
| 268 |
+
center = ((img.shape[1] - 1) * 0.5, (img.shape[0] - 1) * 0.5)
|
| 269 |
+
matrix = cv2.getRotationMatrix2D(center, rotate, 1.0)
|
| 270 |
+
img = cv2.warpAffine(img, matrix, (img.shape[1], img.shape[0]), flags=cv2.INTER_LINEAR)
|
| 271 |
+
return img
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def compute_post_transform(resize, crop, flip, rotate):
|
| 275 |
+
post_rot = torch.eye(2, dtype=torch.float32)
|
| 276 |
+
post_tran = torch.zeros(2, dtype=torch.float32)
|
| 277 |
+
|
| 278 |
+
post_rot *= resize
|
| 279 |
+
post_tran -= torch.tensor(crop[:2], dtype=torch.float32)
|
| 280 |
+
if flip:
|
| 281 |
+
flip_matrix = torch.tensor([[-1, 0], [0, 1]], dtype=torch.float32)
|
| 282 |
+
flip_bias = torch.tensor([crop[2] - crop[0], 0], dtype=torch.float32)
|
| 283 |
+
post_rot = flip_matrix.matmul(post_rot)
|
| 284 |
+
post_tran = flip_matrix.matmul(post_tran) + flip_bias
|
| 285 |
+
|
| 286 |
+
rotate_matrix = get_rot_matrix(rotate / 180.0 * np.pi)
|
| 287 |
+
rotate_bias = torch.tensor([crop[2] - crop[0], crop[3] - crop[1]], dtype=torch.float32) / 2.0
|
| 288 |
+
rotate_bias = rotate_matrix.matmul(-rotate_bias) + rotate_bias
|
| 289 |
+
post_rot = rotate_matrix.matmul(post_rot)
|
| 290 |
+
post_tran = rotate_matrix.matmul(post_tran) + rotate_bias
|
| 291 |
+
|
| 292 |
+
post_rot3 = torch.eye(3, dtype=torch.float32)
|
| 293 |
+
post_tran3 = torch.zeros(3, dtype=torch.float32)
|
| 294 |
+
post_rot3[:2, :2] = post_rot
|
| 295 |
+
post_tran3[:2] = post_tran
|
| 296 |
+
return post_rot3, post_tran3
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def transform_image(img, resize, resize_dims, crop, flip, rotate):
|
| 300 |
+
img = apply_image_transform(img, resize_dims, crop, flip, rotate)
|
| 301 |
+
post_rot3, post_tran3 = compute_post_transform(resize, crop, flip, rotate)
|
| 302 |
+
return img, post_rot3, post_tran3
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def build_transform_matrix(rotation, translation):
|
| 306 |
+
matrix = torch.eye(4, dtype=torch.float32)
|
| 307 |
+
matrix[:3, :3] = torch.tensor(Quaternion(rotation).rotation_matrix, dtype=torch.float32)
|
| 308 |
+
matrix[:3, 3] = torch.tensor(translation, dtype=torch.float32)
|
| 309 |
+
return matrix
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
@lru_cache(maxsize=1)
|
| 313 |
+
def create_frustum(depth_cfg, input_size, downsample):
|
| 314 |
+
height_in, width_in = input_size
|
| 315 |
+
feat_height, feat_width = height_in // downsample, width_in // downsample
|
| 316 |
+
depth = torch.arange(*depth_cfg, dtype=torch.float32).view(-1, 1, 1).expand(-1, feat_height, feat_width)
|
| 317 |
+
x_coords = torch.linspace(0, width_in - 1, feat_width, dtype=torch.float32).view(1, 1, feat_width)
|
| 318 |
+
x_coords = x_coords.expand(depth.shape[0], feat_height, feat_width)
|
| 319 |
+
y_coords = torch.linspace(0, height_in - 1, feat_height, dtype=torch.float32).view(1, feat_height, 1)
|
| 320 |
+
y_coords = y_coords.expand(depth.shape[0], feat_height, feat_width)
|
| 321 |
+
return torch.stack((x_coords, y_coords, depth), dim=-1)
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
@lru_cache(maxsize=1)
|
| 325 |
+
def create_grid_infos(grid_key):
|
| 326 |
+
config = {axis: list(values) for axis, *values in grid_key}
|
| 327 |
+
lower_bound = torch.tensor([config[axis][0] for axis in ['x', 'y', 'z']], dtype=torch.float32)
|
| 328 |
+
interval = torch.tensor([config[axis][2] for axis in ['x', 'y', 'z']], dtype=torch.float32)
|
| 329 |
+
size = torch.tensor([
|
| 330 |
+
(config[axis][1] - config[axis][0]) / config[axis][2]
|
| 331 |
+
for axis in ['x', 'y', 'z']
|
| 332 |
+
], dtype=torch.float32)
|
| 333 |
+
return lower_bound, interval, size
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
def prepare_inputs(imgs, sensor2egos, ego2globals, intrins, post_rots, post_trans, bda):
|
| 337 |
+
keyego2global = ego2globals[:, 0, ...].unsqueeze(1)
|
| 338 |
+
global2keyego = torch.inverse(keyego2global.double())
|
| 339 |
+
sensor2keyegos = global2keyego @ ego2globals.double() @ sensor2egos.double()
|
| 340 |
+
return [
|
| 341 |
+
imgs,
|
| 342 |
+
sensor2keyegos.float(),
|
| 343 |
+
ego2globals.float(),
|
| 344 |
+
intrins.float(),
|
| 345 |
+
post_rots.float(),
|
| 346 |
+
post_trans.float(),
|
| 347 |
+
bda.float(),
|
| 348 |
+
]
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def get_ego_coordinates(frustum, sensor2ego, ego2global, cam2imgs, post_rots, post_trans, bda):
|
| 352 |
+
batch_size, num_cams, _, _ = sensor2ego.shape
|
| 353 |
+
points = frustum.to(sensor2ego) - post_trans.view(batch_size, num_cams, 1, 1, 1, 3)
|
| 354 |
+
points = torch.inverse(post_rots).view(batch_size, num_cams, 1, 1, 1, 3, 3).matmul(points.unsqueeze(-1))
|
| 355 |
+
points = torch.cat((points[..., :2, :] * points[..., 2:3, :], points[..., 2:3, :]), dim=5)
|
| 356 |
+
combine = sensor2ego[:, :, :3, :3].matmul(torch.inverse(cam2imgs))
|
| 357 |
+
points = combine.view(batch_size, num_cams, 1, 1, 1, 3, 3).matmul(points).squeeze(-1)
|
| 358 |
+
points += sensor2ego[:, :, :3, 3].view(batch_size, num_cams, 1, 1, 1, 3)
|
| 359 |
+
points = bda.view(batch_size, 1, 1, 1, 1, 3, 3).matmul(points.unsqueeze(-1)).squeeze(-1)
|
| 360 |
+
return points
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def voxel_pooling_prepare_v2(coordinates, grid_lower_bound, grid_interval, grid_size):
|
| 364 |
+
if coordinates.device.type == 'cpu' and has_cpp_prepare_backend():
|
| 365 |
+
ranks_bev, ranks_depth, ranks_feat, interval_starts, interval_lengths = voxel_pooling_prepare_v2_cpp(
|
| 366 |
+
coordinates.numpy(),
|
| 367 |
+
grid_lower_bound.numpy(),
|
| 368 |
+
grid_interval.numpy(),
|
| 369 |
+
grid_size.numpy(),
|
| 370 |
+
)
|
| 371 |
+
return (
|
| 372 |
+
torch.from_numpy(ranks_bev),
|
| 373 |
+
torch.from_numpy(ranks_depth),
|
| 374 |
+
torch.from_numpy(ranks_feat),
|
| 375 |
+
torch.from_numpy(interval_starts),
|
| 376 |
+
torch.from_numpy(interval_lengths),
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
batch_size, num_cams, depth_bins, feat_height, feat_width, _ = coordinates.shape
|
| 380 |
+
num_points = batch_size * num_cams * depth_bins * feat_height * feat_width
|
| 381 |
+
|
| 382 |
+
ranks_depth = torch.arange(num_points, dtype=torch.int32, device=coordinates.device)
|
| 383 |
+
ranks_feat = torch.arange(num_points // depth_bins, dtype=torch.int32, device=coordinates.device)
|
| 384 |
+
ranks_feat = ranks_feat.reshape(batch_size, num_cams, 1, feat_height, feat_width)
|
| 385 |
+
ranks_feat = ranks_feat.expand(batch_size, num_cams, depth_bins, feat_height, feat_width).reshape(-1)
|
| 386 |
+
|
| 387 |
+
coordinates = ((coordinates - grid_lower_bound.to(coordinates)) / grid_interval.to(coordinates)).long()
|
| 388 |
+
coordinates = coordinates.view(num_points, 3)
|
| 389 |
+
batch_idx = torch.arange(batch_size, dtype=torch.long, device=coordinates.device).view(batch_size, 1)
|
| 390 |
+
batch_idx = batch_idx.expand(batch_size, num_points // batch_size).reshape(num_points, 1)
|
| 391 |
+
coordinates = torch.cat((coordinates, batch_idx), dim=1)
|
| 392 |
+
|
| 393 |
+
kept = (
|
| 394 |
+
(coordinates[:, 0] >= 0) & (coordinates[:, 0] < grid_size[0]) &
|
| 395 |
+
(coordinates[:, 1] >= 0) & (coordinates[:, 1] < grid_size[1]) &
|
| 396 |
+
(coordinates[:, 2] >= 0) & (coordinates[:, 2] < grid_size[2])
|
| 397 |
+
)
|
| 398 |
+
if kept.sum() == 0:
|
| 399 |
+
raise RuntimeError('no valid points remain inside the BEV grid')
|
| 400 |
+
|
| 401 |
+
coordinates = coordinates[kept]
|
| 402 |
+
ranks_depth = ranks_depth[kept]
|
| 403 |
+
ranks_feat = ranks_feat[kept]
|
| 404 |
+
|
| 405 |
+
ranks_bev = coordinates[:, 3] * (grid_size[2] * grid_size[1] * grid_size[0])
|
| 406 |
+
ranks_bev += coordinates[:, 2] * (grid_size[1] * grid_size[0])
|
| 407 |
+
ranks_bev += coordinates[:, 1] * grid_size[0] + coordinates[:, 0]
|
| 408 |
+
order = ranks_bev.argsort()
|
| 409 |
+
ranks_bev = ranks_bev[order]
|
| 410 |
+
ranks_depth = ranks_depth[order]
|
| 411 |
+
ranks_feat = ranks_feat[order]
|
| 412 |
+
|
| 413 |
+
kept = torch.ones(ranks_bev.shape[0], dtype=torch.bool, device=ranks_bev.device)
|
| 414 |
+
kept[1:] = ranks_bev[1:] != ranks_bev[:-1]
|
| 415 |
+
interval_starts = torch.where(kept)[0].int()
|
| 416 |
+
interval_lengths = torch.zeros_like(interval_starts)
|
| 417 |
+
interval_lengths[:-1] = interval_starts[1:] - interval_starts[:-1]
|
| 418 |
+
interval_lengths[-1] = ranks_bev.shape[0] - interval_starts[-1]
|
| 419 |
+
|
| 420 |
+
return (
|
| 421 |
+
ranks_bev.int().contiguous(),
|
| 422 |
+
ranks_depth.int().contiguous(),
|
| 423 |
+
ranks_feat.int().contiguous(),
|
| 424 |
+
interval_starts.int().contiguous(),
|
| 425 |
+
interval_lengths.int().contiguous(),
|
| 426 |
+
)
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def load_sample_from_predict_root(predict_root, target_image):
|
| 430 |
+
meta_root = os.path.join(predict_root, 'v1.0-mini')
|
| 431 |
+
sample_data, calibrated_sensor, ego_pose, sensor = load_predict_metadata(meta_root)
|
| 432 |
+
|
| 433 |
+
target_entry = next((item for item in sample_data if item.get('filename', '').endswith(target_image)), None)
|
| 434 |
+
if target_entry is None:
|
| 435 |
+
raise FileNotFoundError(f'target image not found in sample_data.json: {target_image}')
|
| 436 |
+
|
| 437 |
+
sample_token = target_entry['sample_token']
|
| 438 |
+
keyframe_entries = [
|
| 439 |
+
item for item in sample_data
|
| 440 |
+
if item.get('sample_token') == sample_token and item.get('is_key_frame')
|
| 441 |
+
]
|
| 442 |
+
|
| 443 |
+
cam_entries = {}
|
| 444 |
+
for item in keyframe_entries:
|
| 445 |
+
calibrated = calibrated_sensor[item['calibrated_sensor_token']]
|
| 446 |
+
sensor_info = sensor[calibrated['sensor_token']]
|
| 447 |
+
channel = sensor_info['channel']
|
| 448 |
+
if channel.startswith('CAM_'):
|
| 449 |
+
cam_entries[channel] = {
|
| 450 |
+
'data_path': resolve_existing_path(predict_root, item['filename']),
|
| 451 |
+
'cam_intrinsic': calibrated['camera_intrinsic'],
|
| 452 |
+
'sensor2ego_rotation': calibrated['rotation'],
|
| 453 |
+
'sensor2ego_translation': calibrated['translation'],
|
| 454 |
+
'ego2global_rotation': ego_pose[item['ego_pose_token']]['rotation'],
|
| 455 |
+
'ego2global_translation': ego_pose[item['ego_pose_token']]['translation'],
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
missing_cams = [cam for cam in DATA_CONFIG['cams'] if cam not in cam_entries]
|
| 459 |
+
if missing_cams:
|
| 460 |
+
raise ValueError(f'missing camera metadata for sample {sample_token}: {missing_cams}')
|
| 461 |
+
|
| 462 |
+
for cam_name, cam_info in cam_entries.items():
|
| 463 |
+
if not os.path.exists(cam_info['data_path']):
|
| 464 |
+
raise FileNotFoundError(f'missing image for {cam_name}: {cam_info["data_path"]}')
|
| 465 |
+
|
| 466 |
+
return sample_token, cam_entries
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
def build_sample_inputs_from_predict_root(
|
| 470 |
+
predict_root,
|
| 471 |
+
target_image,
|
| 472 |
+
backend='stub',
|
| 473 |
+
image_backend='auto',
|
| 474 |
+
preprocess_backend='auto'):
|
| 475 |
+
sample_token, cam_entries = load_sample_from_predict_root(predict_root, target_image)
|
| 476 |
+
resolved_image_backend, turbojpeg_decoder = resolve_image_backend(image_backend)
|
| 477 |
+
resolved_preprocess_backend = resolve_preprocess_backend(preprocess_backend)
|
| 478 |
+
|
| 479 |
+
imgs_nhwc = []
|
| 480 |
+
sensor2egos = []
|
| 481 |
+
ego2globals = []
|
| 482 |
+
intrins = []
|
| 483 |
+
post_rots = []
|
| 484 |
+
post_trans = []
|
| 485 |
+
|
| 486 |
+
cam_names = list(DATA_CONFIG['cams'])
|
| 487 |
+
|
| 488 |
+
if resolved_preprocess_backend == 'cpp':
|
| 489 |
+
src_height, src_width = DATA_CONFIG['src_size']
|
| 490 |
+
resize, resize_dims, crop, flip, rotate = sample_test_augmentation(src_height, src_width)
|
| 491 |
+
if flip or rotate:
|
| 492 |
+
raise RuntimeError('cpp preprocess backend currently supports the test-time no-flip/no-rotate path only')
|
| 493 |
+
img_nhwc = _image_preprocess_ext.load_and_preprocess_images(
|
| 494 |
+
[cam_entries[cam_name]['data_path'] for cam_name in cam_names],
|
| 495 |
+
int(resize_dims[0]),
|
| 496 |
+
int(resize_dims[1]),
|
| 497 |
+
int(crop[0]),
|
| 498 |
+
int(crop[1]),
|
| 499 |
+
int(crop[2] - crop[0]),
|
| 500 |
+
int(crop[3] - crop[1]),
|
| 501 |
+
IMG_MEAN.tolist(),
|
| 502 |
+
IMG_STD.tolist(),
|
| 503 |
+
bool(TO_RGB),
|
| 504 |
+
len(cam_names),
|
| 505 |
+
)
|
| 506 |
+
shared_post_rot, shared_post_tran = compute_post_transform(resize, crop, flip, rotate)
|
| 507 |
+
elif resolved_preprocess_backend == 'process':
|
| 508 |
+
process_results = load_and_preprocess_images_process_pool(
|
| 509 |
+
[cam_entries[cam_name]['data_path'] for cam_name in cam_names],
|
| 510 |
+
image_backend,
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
for cam_name in cam_names:
|
| 514 |
+
cam_info = cam_entries[cam_name]
|
| 515 |
+
if resolved_preprocess_backend == 'python':
|
| 516 |
+
image = load_camera_image(cam_info['data_path'], resolved_image_backend, turbojpeg_decoder)
|
| 517 |
+
resize, resize_dims, crop, flip, rotate = sample_test_augmentation(image.shape[0], image.shape[1])
|
| 518 |
+
image, post_rot, post_tran = transform_image(image, resize, resize_dims, crop, flip, rotate)
|
| 519 |
+
imgs_nhwc.append(normalize_image(image))
|
| 520 |
+
elif resolved_preprocess_backend == 'process':
|
| 521 |
+
result = process_results[len(imgs_nhwc)]
|
| 522 |
+
imgs_nhwc.append(result['image'])
|
| 523 |
+
post_rot = torch.from_numpy(result['post_rot']).float()
|
| 524 |
+
post_tran = torch.from_numpy(result['post_tran']).float()
|
| 525 |
+
else:
|
| 526 |
+
post_rot = shared_post_rot
|
| 527 |
+
post_tran = shared_post_tran
|
| 528 |
+
|
| 529 |
+
sensor2egos.append(build_transform_matrix(cam_info['sensor2ego_rotation'], cam_info['sensor2ego_translation']))
|
| 530 |
+
ego2globals.append(build_transform_matrix(cam_info['ego2global_rotation'], cam_info['ego2global_translation']))
|
| 531 |
+
intrins.append(torch.tensor(cam_info['cam_intrinsic'], dtype=torch.float32))
|
| 532 |
+
post_rots.append(post_rot)
|
| 533 |
+
post_trans.append(post_tran)
|
| 534 |
+
|
| 535 |
+
if resolved_preprocess_backend in ('python', 'process'):
|
| 536 |
+
img_nhwc = np.ascontiguousarray(np.stack(imgs_nhwc, axis=0).astype(np.float32, copy=False))
|
| 537 |
+
img_nchw = np.ascontiguousarray(np.transpose(img_nhwc, (0, 3, 1, 2)))
|
| 538 |
+
imgs = torch.from_numpy(img_nchw).unsqueeze(0).contiguous()
|
| 539 |
+
sensor2egos = torch.stack(sensor2egos, dim=0).unsqueeze(0).contiguous()
|
| 540 |
+
ego2globals = torch.stack(ego2globals, dim=0).unsqueeze(0).contiguous()
|
| 541 |
+
intrins = torch.stack(intrins, dim=0).unsqueeze(0).contiguous()
|
| 542 |
+
post_rots = torch.stack(post_rots, dim=0).unsqueeze(0).contiguous()
|
| 543 |
+
post_trans = torch.stack(post_trans, dim=0).unsqueeze(0).contiguous()
|
| 544 |
+
bda = torch.eye(3, dtype=torch.float32).unsqueeze(0).contiguous()
|
| 545 |
+
|
| 546 |
+
prepared = prepare_inputs(imgs, sensor2egos, ego2globals, intrins, post_rots, post_trans, bda)
|
| 547 |
+
frustum = create_frustum(tuple(GRID_CONFIG['depth']), tuple(DATA_CONFIG['input_size']), DOWNSAMPLE)
|
| 548 |
+
grid_key = tuple((axis, *GRID_CONFIG[axis]) for axis in ['x', 'y', 'z'])
|
| 549 |
+
grid_lower_bound, grid_interval, grid_size = create_grid_infos(grid_key)
|
| 550 |
+
coordinates = get_ego_coordinates(frustum, *prepared[1:7])
|
| 551 |
+
ranks_bev, ranks_depth, ranks_feat, interval_starts, interval_lengths = voxel_pooling_prepare_v2(
|
| 552 |
+
coordinates, grid_lower_bound, grid_interval, grid_size.long())
|
| 553 |
+
|
| 554 |
+
bev_shape = [1, int(grid_size[1].item()), int(grid_size[0].item()), BEV_OUT_CHANNELS]
|
| 555 |
+
|
| 556 |
+
return {
|
| 557 |
+
'sample_index': None,
|
| 558 |
+
'sample_token': sample_token,
|
| 559 |
+
'camera_paths': {key: value['data_path'] for key, value in cam_entries.items()},
|
| 560 |
+
'image_backend': resolved_image_backend,
|
| 561 |
+
'preprocess_backend': resolved_preprocess_backend,
|
| 562 |
+
'img_nchw': img_nchw,
|
| 563 |
+
'img_nhwc': img_nhwc,
|
| 564 |
+
'ranks_bev': ranks_bev.cpu().numpy().astype(np.int32),
|
| 565 |
+
'ranks_depth': ranks_depth.cpu().numpy().astype(np.int32),
|
| 566 |
+
'ranks_feat': ranks_feat.cpu().numpy().astype(np.int32),
|
| 567 |
+
'interval_starts': interval_starts.cpu().numpy().astype(np.int32),
|
| 568 |
+
'interval_lengths': interval_lengths.cpu().numpy().astype(np.int32),
|
| 569 |
+
'bev_shape': bev_shape,
|
| 570 |
+
'source_target_image': target_image,
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
class BaseSplitRunner:
|
| 575 |
+
def run_part1(self, img):
|
| 576 |
+
raise NotImplementedError()
|
| 577 |
+
|
| 578 |
+
def run_part3(self, bev_feat):
|
| 579 |
+
raise NotImplementedError()
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
class StubQNNRunner(BaseSplitRunner):
|
| 583 |
+
def __init__(self, part1_model=None, part3_model=None, verbose=False):
|
| 584 |
+
from part1 import FlashOccPart1
|
| 585 |
+
from part3 import FlashOccPart3
|
| 586 |
+
|
| 587 |
+
self.model_part1 = FlashOccPart1(part1_model, verbose=verbose)
|
| 588 |
+
self.model_part_3 = FlashOccPart3(part3_model, verbose=verbose)
|
| 589 |
+
|
| 590 |
+
def run_part1(self, img):
|
| 591 |
+
return self.model_part1(img)
|
| 592 |
+
|
| 593 |
+
def run_part3(self, bev_feat):
|
| 594 |
+
return self.model_part_3(bev_feat)
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
class OnnxRuntimeRunner(BaseSplitRunner):
|
| 598 |
+
def __init__(self, part1_model, part3_model):
|
| 599 |
+
if not part1_model or not part3_model:
|
| 600 |
+
raise ValueError('onnxruntime backend requires --part1-model and --part3-model')
|
| 601 |
+
import onnxruntime as ort
|
| 602 |
+
|
| 603 |
+
self.part1_session = ort.InferenceSession(part1_model, providers=['CPUExecutionProvider'])
|
| 604 |
+
self.part3_session = ort.InferenceSession(part3_model, providers=['CPUExecutionProvider'])
|
| 605 |
+
|
| 606 |
+
def run_part1(self, img):
|
| 607 |
+
tran_feat, depth = self.part1_session.run(None, {'img': img})
|
| 608 |
+
return tran_feat.astype(np.float32), depth.astype(np.float32)
|
| 609 |
+
|
| 610 |
+
def run_part3(self, bev_feat):
|
| 611 |
+
output_0 = self.part3_session.run(None, {'bev_feat': bev_feat})[0]
|
| 612 |
+
return output_0.astype(np.float32)
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
def build_runner(args):
|
| 616 |
+
if args.backend == 'onnxruntime':
|
| 617 |
+
return OnnxRuntimeRunner(args.part1_model, args.part3_model)
|
| 618 |
+
return StubQNNRunner(args.part1_model, args.part3_model, verbose=args.verbose)
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def summarize_prediction(logits, occ_labels, sample_inputs):
|
| 622 |
+
class_hist = np.bincount(occ_labels.reshape(-1), minlength=18)
|
| 623 |
+
return {
|
| 624 |
+
'sample_index': sample_inputs['sample_index'],
|
| 625 |
+
'sample_token': sample_inputs['sample_token'],
|
| 626 |
+
'camera_paths': sample_inputs['camera_paths'],
|
| 627 |
+
'source_target_image': sample_inputs.get('source_target_image'),
|
| 628 |
+
'img_shape': list(sample_inputs['img_nchw'].shape),
|
| 629 |
+
'tran_feat_points': int(sample_inputs['ranks_feat'].shape[0]),
|
| 630 |
+
'bev_intervals': int(sample_inputs['interval_starts'].shape[0]),
|
| 631 |
+
'bev_shape': sample_inputs['bev_shape'],
|
| 632 |
+
'output_shape': list(logits.shape),
|
| 633 |
+
'predicted_class_histogram': class_hist.tolist(),
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
def maybe_save_outputs(save_dir, summary, occ_bev, logits=None):
|
| 638 |
+
if not save_dir:
|
| 639 |
+
return
|
| 640 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 641 |
+
summary_path = os.path.join(save_dir, 'prediction_summary.json')
|
| 642 |
+
occ_bev_path = os.path.join(save_dir, 'occ_bev.png')
|
| 643 |
+
if logits is not None:
|
| 644 |
+
logits_path = os.path.join(save_dir, 'output_0.npy')
|
| 645 |
+
np.save(logits_path, logits)
|
| 646 |
+
print('saved:', logits_path)
|
| 647 |
+
with open(summary_path, 'w', encoding='utf-8') as handle:
|
| 648 |
+
json.dump(summary, handle, indent=2, ensure_ascii=False)
|
| 649 |
+
cv2.imwrite(occ_bev_path, occ_bev)
|
| 650 |
+
print('saved:', summary_path)
|
| 651 |
+
print('saved:', occ_bev_path)
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
def build_bev_pool_workspace(sample_inputs):
|
| 655 |
+
return BEVPoolV2Workspace.from_inputs(
|
| 656 |
+
ranks_feat=sample_inputs['ranks_feat'],
|
| 657 |
+
interval_starts=sample_inputs['interval_starts'],
|
| 658 |
+
ranks_bev=sample_inputs['ranks_bev'],
|
| 659 |
+
bev_shape=sample_inputs['bev_shape'],
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
def main():
|
| 664 |
+
args = parse_args()
|
| 665 |
+
stat_time = time.perf_counter()
|
| 666 |
+
sample_inputs = build_sample_inputs_from_predict_root(
|
| 667 |
+
args.predict_root,
|
| 668 |
+
args.target_image,
|
| 669 |
+
backend=args.backend,
|
| 670 |
+
image_backend=args.image_backend,
|
| 671 |
+
preprocess_backend=args.preprocess_backend,
|
| 672 |
+
)
|
| 673 |
+
print('前处理耗时:', f'{(time.perf_counter() - stat_time) * 1000}ms')
|
| 674 |
+
if args.verbose:
|
| 675 |
+
print('image backend:', sample_inputs['image_backend'])
|
| 676 |
+
print('preprocess backend:', sample_inputs['preprocess_backend'])
|
| 677 |
+
bev_workspace = build_bev_pool_workspace(sample_inputs)
|
| 678 |
+
runner = build_runner(args)
|
| 679 |
+
|
| 680 |
+
if args.verbose:
|
| 681 |
+
print('Running part1...')
|
| 682 |
+
infer_start = time.perf_counter()
|
| 683 |
+
part1_input = sample_inputs['img_nhwc'] if args.backend == 'stub' else sample_inputs['img_nchw']
|
| 684 |
+
tran_feat, depth = runner.run_part1(part1_input)
|
| 685 |
+
if args.verbose:
|
| 686 |
+
print('part1 outputs:', list(tran_feat.shape), list(depth.shape))
|
| 687 |
+
|
| 688 |
+
if args.verbose:
|
| 689 |
+
print('Running CPU bev_pool_v2...')
|
| 690 |
+
bev_time = time.perf_counter()
|
| 691 |
+
bev_feat = bev_pool_v2_cpu(
|
| 692 |
+
tran_feat=tran_feat,
|
| 693 |
+
depth=depth,
|
| 694 |
+
ranks_depth=sample_inputs['ranks_depth'],
|
| 695 |
+
ranks_feat=sample_inputs['ranks_feat'],
|
| 696 |
+
ranks_bev=sample_inputs['ranks_bev'],
|
| 697 |
+
interval_starts=sample_inputs['interval_starts'],
|
| 698 |
+
interval_lengths=sample_inputs['interval_lengths'],
|
| 699 |
+
bev_shape=sample_inputs['bev_shape'],
|
| 700 |
+
workspace=bev_workspace,
|
| 701 |
+
).reshape(-1).astype(np.float32, copy=False)
|
| 702 |
+
print('bev分析耗时:', f'{(time.perf_counter() - bev_time) * 1000}ms')
|
| 703 |
+
if args.verbose:
|
| 704 |
+
print('bev_feat shape:', list(bev_feat.shape))
|
| 705 |
+
|
| 706 |
+
if args.verbose:
|
| 707 |
+
print('Running part3...')
|
| 708 |
+
logits = runner.run_part3(bev_feat)
|
| 709 |
+
print('模型分析总耗时:', f'{(time.perf_counter() - infer_start) * 1000}ms')
|
| 710 |
+
print('*' * 50)
|
| 711 |
+
print('output shape:', logits.shape)
|
| 712 |
+
if args.dump_logits:
|
| 713 |
+
output_dir = args.save_dir if args.save_dir else os.getcwd()
|
| 714 |
+
if not os.path.exists(output_dir):
|
| 715 |
+
os.makedirs(output_dir)
|
| 716 |
+
output_path = os.path.join(output_dir, 'output_0.npy')
|
| 717 |
+
np.save(output_path, logits)
|
| 718 |
+
print('saved:', output_path)
|
| 719 |
+
print('*' * 50)
|
| 720 |
+
occ_labels = logits_to_occ_labels(logits)
|
| 721 |
+
summary = summarize_prediction(logits, occ_labels, sample_inputs)
|
| 722 |
+
print(json.dumps(summary, indent=2, ensure_ascii=False))
|
| 723 |
+
occ_bev = vis_occ(occ_labels[0]) if args.save_dir else None
|
| 724 |
+
maybe_save_outputs(args.save_dir, summary, occ_bev, None)
|
| 725 |
+
|
| 726 |
+
|
| 727 |
+
if __name__ == '__main__':
|
| 728 |
+
main()
|
targets/QCS8550/FP16/samples/back.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/FP16/samples/back_left.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/FP16/samples/back_right.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/FP16/samples/front.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/FP16/samples/front_left.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/FP16/samples/front_right.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/W8A16/calibration.json
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cameraOrder": [
|
| 3 |
+
"front",
|
| 4 |
+
"front_right",
|
| 5 |
+
"front_left",
|
| 6 |
+
"back",
|
| 7 |
+
"back_left",
|
| 8 |
+
"back_right"
|
| 9 |
+
],
|
| 10 |
+
"cameraToEgo": [
|
| 11 |
+
[
|
| 12 |
+
[
|
| 13 |
+
0.009793734177947044,
|
| 14 |
+
0.008477547205984592,
|
| 15 |
+
0.999916136264801,
|
| 16 |
+
1.786743402481079
|
| 17 |
+
],
|
| 18 |
+
[
|
| 19 |
+
-0.9998770952224731,
|
| 20 |
+
0.012321611866354942,
|
| 21 |
+
0.009688900783658028,
|
| 22 |
+
0.0036235980223864317
|
| 23 |
+
],
|
| 24 |
+
[
|
| 25 |
+
-0.012238440103828907,
|
| 26 |
+
-0.9998881816864014,
|
| 27 |
+
0.008597181178629398,
|
| 28 |
+
1.4961199760437012
|
| 29 |
+
],
|
| 30 |
+
[
|
| 31 |
+
0.0,
|
| 32 |
+
0.0,
|
| 33 |
+
0.0,
|
| 34 |
+
1.0
|
| 35 |
+
]
|
| 36 |
+
],
|
| 37 |
+
[
|
| 38 |
+
[
|
| 39 |
+
-0.8444615602493286,
|
| 40 |
+
0.016537705436348915,
|
| 41 |
+
0.5353609323501587,
|
| 42 |
+
1.7133985757827759
|
| 43 |
+
],
|
| 44 |
+
[
|
| 45 |
+
-0.535379946231842,
|
| 46 |
+
0.003624292556196451,
|
| 47 |
+
-0.8446035385131836,
|
| 48 |
+
-0.5012373924255371
|
| 49 |
+
],
|
| 50 |
+
[
|
| 51 |
+
-0.01590810902416706,
|
| 52 |
+
-0.99985671043396,
|
| 53 |
+
0.00579338101670146,
|
| 54 |
+
1.5199543237686157
|
| 55 |
+
],
|
| 56 |
+
[
|
| 57 |
+
0.0,
|
| 58 |
+
0.0,
|
| 59 |
+
0.0,
|
| 60 |
+
1.0
|
| 61 |
+
]
|
| 62 |
+
],
|
| 63 |
+
[
|
| 64 |
+
[
|
| 65 |
+
0.8225460648536682,
|
| 66 |
+
0.006478320807218552,
|
| 67 |
+
0.568661630153656,
|
| 68 |
+
1.5752559900283813
|
| 69 |
+
],
|
| 70 |
+
[
|
| 71 |
+
-0.5686843395233154,
|
| 72 |
+
0.016434065997600555,
|
| 73 |
+
0.8223916888237,
|
| 74 |
+
0.5005193948745728
|
| 75 |
+
],
|
| 76 |
+
[
|
| 77 |
+
-0.004017705097794533,
|
| 78 |
+
-0.999843955039978,
|
| 79 |
+
0.017201894894242287,
|
| 80 |
+
1.5069602727890015
|
| 81 |
+
],
|
| 82 |
+
[
|
| 83 |
+
0.0,
|
| 84 |
+
0.0,
|
| 85 |
+
0.0,
|
| 86 |
+
1.0
|
| 87 |
+
]
|
| 88 |
+
],
|
| 89 |
+
[
|
| 90 |
+
[
|
| 91 |
+
0.010747148655354977,
|
| 92 |
+
-0.0066407592967152596,
|
| 93 |
+
-0.9999202489852905,
|
| 94 |
+
0.3301053047180176
|
| 95 |
+
],
|
| 96 |
+
[
|
| 97 |
+
0.9998782277107239,
|
| 98 |
+
0.011386878788471222,
|
| 99 |
+
0.010671093128621578,
|
| 100 |
+
0.008498914539813995
|
| 101 |
+
],
|
| 102 |
+
[
|
| 103 |
+
0.011315105482935905,
|
| 104 |
+
-0.9999130964279175,
|
| 105 |
+
0.006762326695024967,
|
| 106 |
+
1.5727975368499756
|
| 107 |
+
],
|
| 108 |
+
[
|
| 109 |
+
0.0,
|
| 110 |
+
0.0,
|
| 111 |
+
0.0,
|
| 112 |
+
1.0
|
| 113 |
+
]
|
| 114 |
+
],
|
| 115 |
+
[
|
| 116 |
+
[
|
| 117 |
+
0.9485073685646057,
|
| 118 |
+
-0.008619013242423534,
|
| 119 |
+
-0.3166378438472748,
|
| 120 |
+
1.4057787656784058
|
| 121 |
+
],
|
| 122 |
+
[
|
| 123 |
+
0.3167478144168854,
|
| 124 |
+
0.01902088336646557,
|
| 125 |
+
0.9483190178871155,
|
| 126 |
+
0.4778013229370117
|
| 127 |
+
],
|
| 128 |
+
[
|
| 129 |
+
-0.002150842687115073,
|
| 130 |
+
-0.9997819066047668,
|
| 131 |
+
0.02077149972319603,
|
| 132 |
+
1.5687693357467651
|
| 133 |
+
],
|
| 134 |
+
[
|
| 135 |
+
0.0,
|
| 136 |
+
0.0,
|
| 137 |
+
0.0,
|
| 138 |
+
1.0
|
| 139 |
+
]
|
| 140 |
+
],
|
| 141 |
+
[
|
| 142 |
+
[
|
| 143 |
+
-0.9232780933380127,
|
| 144 |
+
-0.0025498708710074425,
|
| 145 |
+
-0.38412362337112427,
|
| 146 |
+
1.257399082183838
|
| 147 |
+
],
|
| 148 |
+
[
|
| 149 |
+
0.384126752614975,
|
| 150 |
+
-0.011398540809750557,
|
| 151 |
+
-0.9232099652290344,
|
| 152 |
+
-0.46987396478652954
|
| 153 |
+
],
|
| 154 |
+
[
|
| 155 |
+
-0.0020243842154741287,
|
| 156 |
+
-0.999931812286377,
|
| 157 |
+
0.011503497138619423,
|
| 158 |
+
1.554057002067566
|
| 159 |
+
],
|
| 160 |
+
[
|
| 161 |
+
0.0,
|
| 162 |
+
0.0,
|
| 163 |
+
0.0,
|
| 164 |
+
1.0
|
| 165 |
+
]
|
| 166 |
+
]
|
| 167 |
+
],
|
| 168 |
+
"frame": 0,
|
| 169 |
+
"imageSizes": [
|
| 170 |
+
[
|
| 171 |
+
900,
|
| 172 |
+
1600
|
| 173 |
+
],
|
| 174 |
+
[
|
| 175 |
+
900,
|
| 176 |
+
1600
|
| 177 |
+
],
|
| 178 |
+
[
|
| 179 |
+
900,
|
| 180 |
+
1600
|
| 181 |
+
],
|
| 182 |
+
[
|
| 183 |
+
900,
|
| 184 |
+
1600
|
| 185 |
+
],
|
| 186 |
+
[
|
| 187 |
+
900,
|
| 188 |
+
1600
|
| 189 |
+
],
|
| 190 |
+
[
|
| 191 |
+
900,
|
| 192 |
+
1600
|
| 193 |
+
]
|
| 194 |
+
],
|
| 195 |
+
"intrinsics": [
|
| 196 |
+
[
|
| 197 |
+
[
|
| 198 |
+
1252.8131103515625,
|
| 199 |
+
0.0,
|
| 200 |
+
826.588134765625
|
| 201 |
+
],
|
| 202 |
+
[
|
| 203 |
+
0.0,
|
| 204 |
+
1252.8131103515625,
|
| 205 |
+
469.9846496582031
|
| 206 |
+
],
|
| 207 |
+
[
|
| 208 |
+
0.0,
|
| 209 |
+
0.0,
|
| 210 |
+
1.0
|
| 211 |
+
]
|
| 212 |
+
],
|
| 213 |
+
[
|
| 214 |
+
[
|
| 215 |
+
1256.74853515625,
|
| 216 |
+
0.0,
|
| 217 |
+
817.7887573242188
|
| 218 |
+
],
|
| 219 |
+
[
|
| 220 |
+
0.0,
|
| 221 |
+
1256.74853515625,
|
| 222 |
+
451.9541931152344
|
| 223 |
+
],
|
| 224 |
+
[
|
| 225 |
+
0.0,
|
| 226 |
+
0.0,
|
| 227 |
+
1.0
|
| 228 |
+
]
|
| 229 |
+
],
|
| 230 |
+
[
|
| 231 |
+
[
|
| 232 |
+
1257.862548828125,
|
| 233 |
+
0.0,
|
| 234 |
+
827.2410888671875
|
| 235 |
+
],
|
| 236 |
+
[
|
| 237 |
+
0.0,
|
| 238 |
+
1257.862548828125,
|
| 239 |
+
450.9154968261719
|
| 240 |
+
],
|
| 241 |
+
[
|
| 242 |
+
0.0,
|
| 243 |
+
0.0,
|
| 244 |
+
1.0
|
| 245 |
+
]
|
| 246 |
+
],
|
| 247 |
+
[
|
| 248 |
+
[
|
| 249 |
+
796.8910522460938,
|
| 250 |
+
0.0,
|
| 251 |
+
857.7774047851562
|
| 252 |
+
],
|
| 253 |
+
[
|
| 254 |
+
0.0,
|
| 255 |
+
796.8910522460938,
|
| 256 |
+
476.8848876953125
|
| 257 |
+
],
|
| 258 |
+
[
|
| 259 |
+
0.0,
|
| 260 |
+
0.0,
|
| 261 |
+
1.0
|
| 262 |
+
]
|
| 263 |
+
],
|
| 264 |
+
[
|
| 265 |
+
[
|
| 266 |
+
1254.986083984375,
|
| 267 |
+
0.0,
|
| 268 |
+
829.576904296875
|
| 269 |
+
],
|
| 270 |
+
[
|
| 271 |
+
0.0,
|
| 272 |
+
1254.986083984375,
|
| 273 |
+
467.1680603027344
|
| 274 |
+
],
|
| 275 |
+
[
|
| 276 |
+
0.0,
|
| 277 |
+
0.0,
|
| 278 |
+
1.0
|
| 279 |
+
]
|
| 280 |
+
],
|
| 281 |
+
[
|
| 282 |
+
[
|
| 283 |
+
1249.962890625,
|
| 284 |
+
0.0,
|
| 285 |
+
825.3768310546875
|
| 286 |
+
],
|
| 287 |
+
[
|
| 288 |
+
0.0,
|
| 289 |
+
1249.962890625,
|
| 290 |
+
462.54815673828125
|
| 291 |
+
],
|
| 292 |
+
[
|
| 293 |
+
0.0,
|
| 294 |
+
0.0,
|
| 295 |
+
1.0
|
| 296 |
+
]
|
| 297 |
+
]
|
| 298 |
+
],
|
| 299 |
+
"sceneId": "3950bd41f74548429c0f7700ff3d8269",
|
| 300 |
+
"version": 1
|
| 301 |
+
}
|
targets/QCS8550/W8A16/composite.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"assets": {
|
| 3 |
+
"calibration": "calibration.json",
|
| 4 |
+
"frustum": "frustum.npy",
|
| 5 |
+
"ranks": "geometry-ranks.npz"
|
| 6 |
+
},
|
| 7 |
+
"components": {
|
| 8 |
+
"part1": "models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part1_qcs8550_w8a16.qnn236.ctx.bin.amf",
|
| 9 |
+
"part3": "models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part3_qcs8550_w8a16.qnn236.ctx.bin.aidem"
|
| 10 |
+
},
|
| 11 |
+
"derivation": {
|
| 12 |
+
"files": {
|
| 13 |
+
"calibration.json": "c9bef4379a9cab2324cfc3ab5b18f3c3bbf4b4641d4b345b956c043928df67ce",
|
| 14 |
+
"frustum.npy": "37dd2f50e2f7b6451541088ccd3db3d8cd5697c52dcc60255c85bc1cb825e20b",
|
| 15 |
+
"geometry-ranks.npz": "40935c88bcc4b17aa5d4e661cbbab71f2b0627dadd754083fb4d91d95458fa43",
|
| 16 |
+
"models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part1_qcs8550_w8a16.qnn236.ctx.bin.amf": "e8d78968fa25557786cca663b5f5f377c93368083adec12c8cc3a85f58e34527",
|
| 17 |
+
"models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part3_qcs8550_w8a16.qnn236.ctx.bin.aidem": "74de4b0257372adcb4bfb52b4fadfcaef4c84f7a41e50e117171cde17dc58570",
|
| 18 |
+
"reference/deployment/bev_pool_v2_cpu.py": "62c2c566ded450425aabbcf6e08cec72f02e63800c41f0afbb82a722abf80918",
|
| 19 |
+
"reference/deployment/postprocess_flashocc_qnn.py": "4dc7a2a9f2ffa5ea209e8d14ed34fa628258eb953400b41f762849127b6123ed",
|
| 20 |
+
"reference/part1.py": "a9177064f8ddf5cd9df17033ed35414bb96ca26f02e44dec8dd7e27f74922eeb",
|
| 21 |
+
"reference/part3.py": "ab2e976ec9ec229a4e12ba06896320fd6a8597f82466e654f23d4469b3962be1",
|
| 22 |
+
"reference/run_flashocc_split_onboard.py": "e13d4f407085e2a0db91c947ac4717803bd08f3f47130e82382930f006f3ae24",
|
| 23 |
+
"samples/back.jpg": "fdbdaa77e60ed5a6a762a4ea9a8eb1cb2ca9a3d94c610a55a2399a05c04b6ba6",
|
| 24 |
+
"samples/back_left.jpg": "000f7943769e91ffa842a7dfd1bfc31e0c3f4b37325a98846e8261304028f2ad",
|
| 25 |
+
"samples/back_right.jpg": "39d28a8a5a6f61370a7e7e1e965a6d8610b571195c50fd29da960e1fb2fbee80",
|
| 26 |
+
"samples/front.jpg": "d5624fcecf12310c3d0760362e097c38cdcdce987e032aaf2883071cd14e2732",
|
| 27 |
+
"samples/front_left.jpg": "0fe15c0581db41e084df27acb2183b0ab9b0fd36da136ef1b4bcbda6f1a84c58",
|
| 28 |
+
"samples/front_right.jpg": "dd64d7463bc06bfd5d5378bdd494b40d68d0894307f3ed971eaaaf131022cf68"
|
| 29 |
+
},
|
| 30 |
+
"numpyMatchesOriginalTorchAssignments": true,
|
| 31 |
+
"providedCachePointCount": 196321,
|
| 32 |
+
"recomputedPointCount": 300957,
|
| 33 |
+
"sourceCache": "code/python/datas/.flashocc_cache/n008-2018-08-01-15-16-36-0400__CAM_BACK__1533151603637558.jpg.stub.npz",
|
| 34 |
+
"sourceCacheSha256": "174c33d7798502a836f1f15ed02f23f19f158d806f4f8d5cfd77dab3161c7bd6",
|
| 35 |
+
"sourcePackageSha256": "0e13fc77ac9161b40c33276b807dc94c6d571675f7bb4b83636f532637dbce34",
|
| 36 |
+
"torch": "2.10.0+cu128"
|
| 37 |
+
},
|
| 38 |
+
"frames": [
|
| 39 |
+
{
|
| 40 |
+
"calibration": "calibration.json",
|
| 41 |
+
"images": [
|
| 42 |
+
{
|
| 43 |
+
"name": "CAM_FRONT",
|
| 44 |
+
"path": "samples/front.jpg",
|
| 45 |
+
"sha256": "d5624fcecf12310c3d0760362e097c38cdcdce987e032aaf2883071cd14e2732"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "CAM_FRONT_RIGHT",
|
| 49 |
+
"path": "samples/front_right.jpg",
|
| 50 |
+
"sha256": "dd64d7463bc06bfd5d5378bdd494b40d68d0894307f3ed971eaaaf131022cf68"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"name": "CAM_FRONT_LEFT",
|
| 54 |
+
"path": "samples/front_left.jpg",
|
| 55 |
+
"sha256": "0fe15c0581db41e084df27acb2183b0ab9b0fd36da136ef1b4bcbda6f1a84c58"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"name": "CAM_BACK",
|
| 59 |
+
"path": "samples/back.jpg",
|
| 60 |
+
"sha256": "fdbdaa77e60ed5a6a762a4ea9a8eb1cb2ca9a3d94c610a55a2399a05c04b6ba6"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"name": "CAM_BACK_LEFT",
|
| 64 |
+
"path": "samples/back_left.jpg",
|
| 65 |
+
"sha256": "000f7943769e91ffa842a7dfd1bfc31e0c3f4b37325a98846e8261304028f2ad"
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "CAM_BACK_RIGHT",
|
| 69 |
+
"path": "samples/back_right.jpg",
|
| 70 |
+
"sha256": "39d28a8a5a6f61370a7e7e1e965a6d8610b571195c50fd29da960e1fb2fbee80"
|
| 71 |
+
}
|
| 72 |
+
],
|
| 73 |
+
"key": "official"
|
| 74 |
+
}
|
| 75 |
+
],
|
| 76 |
+
"geometryKey": "400592a6a2df4d0179222689b8c876814f2125cb20473059476614e866c1d9f2",
|
| 77 |
+
"kind": "flashocc",
|
| 78 |
+
"version": 1
|
| 79 |
+
}
|
targets/QCS8550/W8A16/frustum.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37dd2f50e2f7b6451541088ccd3db3d8cd5697c52dcc60255c85bc1cb825e20b
|
| 3 |
+
size 743552
|
targets/QCS8550/W8A16/geometry-ranks.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40935c88bcc4b17aa5d4e661cbbab71f2b0627dadd754083fb4d91d95458fa43
|
| 3 |
+
size 3797788
|
targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part1_qcs8550_w8a16.qnn236.ctx.bin.amf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e8d78968fa25557786cca663b5f5f377c93368083adec12c8cc3a85f58e34527
|
| 3 |
+
size 26339240
|
targets/QCS8550/W8A16/models/QCS8550/W8A16/bevdet_qnn_val_full_fuse_part3_qcs8550_w8a16.qnn236.ctx.bin.aidem
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:74de4b0257372adcb4bfb52b4fadfcaef4c84f7a41e50e117171cde17dc58570
|
| 3 |
+
size 20599104
|
targets/QCS8550/W8A16/reference/deployment/bev_pool_v2_cpu.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
from . import _bev_pool_v2_ext
|
| 9 |
+
except ImportError:
|
| 10 |
+
_bev_pool_v2_ext = None
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class BEVPoolV2Workspace:
|
| 14 |
+
def __init__(self, point_count, interval_count, bev_hw, channels, bev_indices=None):
|
| 15 |
+
self.point_count = int(point_count)
|
| 16 |
+
self.interval_count = int(interval_count)
|
| 17 |
+
self.bev_hw = int(bev_hw)
|
| 18 |
+
self.channels = int(channels)
|
| 19 |
+
self.gathered_feat = np.empty((self.point_count, self.channels), dtype=np.float32)
|
| 20 |
+
self.depth_values = np.empty((self.point_count,), dtype=np.float32)
|
| 21 |
+
self.weighted_feat = np.empty((self.point_count, self.channels), dtype=np.float32)
|
| 22 |
+
self.flat_bev = np.zeros((self.bev_hw, self.channels), dtype=np.float32)
|
| 23 |
+
self.bev_indices = None if bev_indices is None else np.asarray(bev_indices, dtype=np.int32)
|
| 24 |
+
|
| 25 |
+
@classmethod
|
| 26 |
+
def from_inputs(cls, ranks_feat, interval_starts, ranks_bev, bev_shape):
|
| 27 |
+
bev_height = int(bev_shape[1])
|
| 28 |
+
bev_width = int(bev_shape[2])
|
| 29 |
+
channels = int(bev_shape[3])
|
| 30 |
+
bev_indices = ranks_bev[interval_starts]
|
| 31 |
+
return cls(
|
| 32 |
+
point_count=ranks_feat.shape[0],
|
| 33 |
+
interval_count=interval_starts.shape[0],
|
| 34 |
+
bev_hw=bev_height * bev_width,
|
| 35 |
+
channels=channels,
|
| 36 |
+
bev_indices=bev_indices,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def validate(self, ranks_feat, interval_starts, bev_shape):
|
| 40 |
+
expected = (
|
| 41 |
+
int(ranks_feat.shape[0]),
|
| 42 |
+
int(interval_starts.shape[0]),
|
| 43 |
+
int(bev_shape[1]) * int(bev_shape[2]),
|
| 44 |
+
int(bev_shape[3]),
|
| 45 |
+
)
|
| 46 |
+
actual = (self.point_count, self.interval_count, self.bev_hw, self.channels)
|
| 47 |
+
if actual != expected:
|
| 48 |
+
raise ValueError(f'workspace shape mismatch: expected={expected}, actual={actual}')
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def has_cpp_backend():
|
| 52 |
+
return _bev_pool_v2_ext is not None
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def has_cpp_prepare_backend():
|
| 56 |
+
return _bev_pool_v2_ext is not None and hasattr(_bev_pool_v2_ext, 'voxel_pooling_prepare_v2_forward')
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def voxel_pooling_prepare_v2_cpp(coordinates, grid_lower_bound, grid_interval, grid_size):
|
| 60 |
+
if not has_cpp_prepare_backend():
|
| 61 |
+
raise RuntimeError('C++ voxel_pooling_prepare_v2 backend is unavailable')
|
| 62 |
+
return _bev_pool_v2_ext.voxel_pooling_prepare_v2_forward(
|
| 63 |
+
np.ascontiguousarray(coordinates, dtype=np.float32),
|
| 64 |
+
np.ascontiguousarray(grid_lower_bound, dtype=np.float32),
|
| 65 |
+
np.ascontiguousarray(grid_interval, dtype=np.float32),
|
| 66 |
+
np.ascontiguousarray(grid_size, dtype=np.int32),
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def parse_args():
|
| 71 |
+
parser = argparse.ArgumentParser(description='Run FlashOCC bev_pool_v2 on CPU with NumPy')
|
| 72 |
+
parser.add_argument('tran_feat_path', help='raw or npy file for part1 tran_feat output')
|
| 73 |
+
parser.add_argument('depth_path', help='raw or npy file for part1 depth output')
|
| 74 |
+
parser.add_argument('sample_manifest', help='split_qnn_sample.json generated by prepare_flashocc_split_qnn_sample.py')
|
| 75 |
+
parser.add_argument('output_dir', help='directory to save bev_feat for part3 input')
|
| 76 |
+
parser.add_argument('--save-npy', action='store_true', help='also save .npy files beside .raw')
|
| 77 |
+
return parser.parse_args()
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def load_manifest(path):
|
| 81 |
+
with open(path, 'r', encoding='utf-8') as handle:
|
| 82 |
+
return json.load(handle)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def load_array(path, dtype, shape):
|
| 86 |
+
if path.endswith('.npy'):
|
| 87 |
+
array = np.load(path)
|
| 88 |
+
else:
|
| 89 |
+
array = np.fromfile(path, dtype=np.dtype(dtype))
|
| 90 |
+
return array.reshape(shape)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def resolve_meta_path(base_dir, entry):
|
| 94 |
+
return os.path.join(base_dir, entry['file'])
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def validate_intervals(interval_starts, interval_lengths, total_points):
|
| 98 |
+
if interval_starts.ndim != 1 or interval_lengths.ndim != 1:
|
| 99 |
+
raise ValueError('interval_starts and interval_lengths must be 1D arrays')
|
| 100 |
+
if interval_starts.shape[0] != interval_lengths.shape[0]:
|
| 101 |
+
raise ValueError('interval_starts and interval_lengths length mismatch')
|
| 102 |
+
if interval_starts.shape[0] == 0:
|
| 103 |
+
return
|
| 104 |
+
expected_lengths = np.empty_like(interval_lengths)
|
| 105 |
+
expected_lengths[:-1] = interval_starts[1:] - interval_starts[:-1]
|
| 106 |
+
expected_lengths[-1] = total_points - interval_starts[-1]
|
| 107 |
+
if not np.array_equal(expected_lengths, interval_lengths):
|
| 108 |
+
raise ValueError('interval metadata is inconsistent with contiguous grouped points')
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def bev_pool_v2_cpu(tran_feat, depth, ranks_depth, ranks_feat, ranks_bev,
|
| 112 |
+
interval_starts, interval_lengths, bev_shape, workspace=None):
|
| 113 |
+
validate_intervals(interval_starts, interval_lengths, ranks_bev.shape[0])
|
| 114 |
+
|
| 115 |
+
bev_height = int(bev_shape[1])
|
| 116 |
+
bev_width = int(bev_shape[2])
|
| 117 |
+
channels = int(bev_shape[3])
|
| 118 |
+
bev_indices = ranks_bev[interval_starts]
|
| 119 |
+
|
| 120 |
+
if _bev_pool_v2_ext is not None:
|
| 121 |
+
if workspace is None:
|
| 122 |
+
workspace = BEVPoolV2Workspace.from_inputs(ranks_feat, interval_starts, ranks_bev, bev_shape)
|
| 123 |
+
workspace.validate(ranks_feat, interval_starts, bev_shape)
|
| 124 |
+
_bev_pool_v2_ext.bev_pool_v2_forward(
|
| 125 |
+
np.ascontiguousarray(tran_feat, dtype=np.float32),
|
| 126 |
+
np.ascontiguousarray(depth, dtype=np.float32),
|
| 127 |
+
np.ascontiguousarray(ranks_depth, dtype=np.int32),
|
| 128 |
+
np.ascontiguousarray(ranks_feat, dtype=np.int32),
|
| 129 |
+
np.ascontiguousarray(workspace.bev_indices if workspace.bev_indices is not None else bev_indices, dtype=np.int32),
|
| 130 |
+
np.ascontiguousarray(interval_starts, dtype=np.int32),
|
| 131 |
+
np.ascontiguousarray(interval_lengths, dtype=np.int32),
|
| 132 |
+
workspace.flat_bev,
|
| 133 |
+
)
|
| 134 |
+
return workspace.flat_bev.reshape(bev_shape)
|
| 135 |
+
|
| 136 |
+
if workspace is not None:
|
| 137 |
+
workspace.validate(ranks_feat, interval_starts, bev_shape)
|
| 138 |
+
np.take(tran_feat, ranks_feat, axis=0, out=workspace.gathered_feat)
|
| 139 |
+
np.take(depth, ranks_depth, axis=0, out=workspace.depth_values)
|
| 140 |
+
np.multiply(workspace.gathered_feat, workspace.depth_values[:, None], out=workspace.weighted_feat)
|
| 141 |
+
reduced_feat = np.add.reduceat(workspace.weighted_feat, interval_starts, axis=0)
|
| 142 |
+
workspace.flat_bev.fill(0)
|
| 143 |
+
workspace.flat_bev[workspace.bev_indices if workspace.bev_indices is not None else bev_indices] = reduced_feat.astype(np.float32, copy=False)
|
| 144 |
+
return workspace.flat_bev.reshape(bev_shape)
|
| 145 |
+
|
| 146 |
+
weighted_feat = tran_feat[ranks_feat] * depth[ranks_depth][:, None]
|
| 147 |
+
reduced_feat = np.add.reduceat(weighted_feat, interval_starts, axis=0)
|
| 148 |
+
flat_bev = np.zeros((bev_height * bev_width, channels), dtype=np.float32)
|
| 149 |
+
flat_bev[bev_indices] = reduced_feat.astype(np.float32, copy=False)
|
| 150 |
+
return flat_bev.reshape(bev_shape)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def save_array(output_dir, name, array, save_npy):
|
| 154 |
+
raw_path = os.path.join(output_dir, f'{name}.raw')
|
| 155 |
+
array.tofile(raw_path)
|
| 156 |
+
print('saved:', raw_path, list(array.shape), array.dtype)
|
| 157 |
+
if save_npy:
|
| 158 |
+
npy_path = os.path.join(output_dir, f'{name}.npy')
|
| 159 |
+
np.save(npy_path, array)
|
| 160 |
+
print('saved:', npy_path)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def main():
|
| 164 |
+
args = parse_args()
|
| 165 |
+
os.makedirs(args.output_dir, exist_ok=True)
|
| 166 |
+
|
| 167 |
+
manifest = load_manifest(args.sample_manifest)
|
| 168 |
+
base_dir = os.path.dirname(args.sample_manifest)
|
| 169 |
+
|
| 170 |
+
tran_feat_shape = manifest['part1_outputs'][0]['shape']
|
| 171 |
+
depth_shape = manifest['part1_outputs'][1]['shape']
|
| 172 |
+
bev_shape = manifest['part3_inputs'][0]['unflattened_shape']
|
| 173 |
+
|
| 174 |
+
tran_feat = load_array(args.tran_feat_path, 'float32', tran_feat_shape).astype(np.float32, copy=False)
|
| 175 |
+
depth = load_array(args.depth_path, 'float32', depth_shape).astype(np.float32, copy=False)
|
| 176 |
+
|
| 177 |
+
bev_inputs = {entry['name']: entry for entry in manifest['bev_pool_inputs']}
|
| 178 |
+
ranks_depth = load_array(resolve_meta_path(base_dir, bev_inputs['ranks_depth']), 'int32', bev_inputs['ranks_depth']['shape'])
|
| 179 |
+
ranks_feat = load_array(resolve_meta_path(base_dir, bev_inputs['ranks_feat']), 'int32', bev_inputs['ranks_feat']['shape'])
|
| 180 |
+
ranks_bev = load_array(resolve_meta_path(base_dir, bev_inputs['ranks_bev']), 'int32', bev_inputs['ranks_bev']['shape'])
|
| 181 |
+
interval_starts = load_array(resolve_meta_path(base_dir, bev_inputs['interval_starts']), 'int32', bev_inputs['interval_starts']['shape'])
|
| 182 |
+
interval_lengths = load_array(resolve_meta_path(base_dir, bev_inputs['interval_lengths']), 'int32', bev_inputs['interval_lengths']['shape'])
|
| 183 |
+
|
| 184 |
+
bev_feat = bev_pool_v2_cpu(
|
| 185 |
+
tran_feat=tran_feat,
|
| 186 |
+
depth=depth,
|
| 187 |
+
ranks_depth=ranks_depth,
|
| 188 |
+
ranks_feat=ranks_feat,
|
| 189 |
+
ranks_bev=ranks_bev,
|
| 190 |
+
interval_starts=interval_starts,
|
| 191 |
+
interval_lengths=interval_lengths,
|
| 192 |
+
bev_shape=bev_shape,
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
save_array(args.output_dir, 'bev_feat', bev_feat.reshape(-1).astype(np.float32, copy=False), args.save_npy)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
if __name__ == '__main__':
|
| 199 |
+
main()
|
targets/QCS8550/W8A16/reference/deployment/postprocess_flashocc_qnn.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import cv2
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
COLORS_MAP = np.array(
|
| 10 |
+
[
|
| 11 |
+
[0, 0, 0, 255],
|
| 12 |
+
[255, 158, 0, 255],
|
| 13 |
+
[0, 0, 230, 255],
|
| 14 |
+
[47, 79, 79, 255],
|
| 15 |
+
[220, 20, 60, 255],
|
| 16 |
+
[255, 69, 0, 255],
|
| 17 |
+
[255, 140, 0, 255],
|
| 18 |
+
[233, 150, 70, 255],
|
| 19 |
+
[255, 61, 99, 255],
|
| 20 |
+
[112, 128, 144, 255],
|
| 21 |
+
[222, 184, 135, 255],
|
| 22 |
+
[0, 175, 0, 255],
|
| 23 |
+
[165, 42, 42, 255],
|
| 24 |
+
[0, 207, 191, 255],
|
| 25 |
+
[75, 0, 75, 255],
|
| 26 |
+
[255, 0, 0, 255],
|
| 27 |
+
[0, 0, 0, 0],
|
| 28 |
+
[0, 0, 0, 0],
|
| 29 |
+
],
|
| 30 |
+
dtype=np.uint8)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def parse_args():
|
| 34 |
+
parser = argparse.ArgumentParser(description='Postprocess FlashOCC QNN output')
|
| 35 |
+
parser.add_argument('output_path', help='QNN output raw or npy file for output_0')
|
| 36 |
+
parser.add_argument('save_dir', help='directory to save postprocessed results')
|
| 37 |
+
parser.add_argument('--meta', default=None, help='metadata json generated during export')
|
| 38 |
+
parser.add_argument(
|
| 39 |
+
'--output-shape',
|
| 40 |
+
default='1,200,200,16,18',
|
| 41 |
+
help='fallback output shape if metadata is not provided')
|
| 42 |
+
parser.add_argument('--dtype', default='float32', help='output dtype, default float32')
|
| 43 |
+
return parser.parse_args()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def load_output_shape(args):
|
| 47 |
+
if args.meta:
|
| 48 |
+
with open(args.meta, 'r', encoding='utf-8') as handle:
|
| 49 |
+
metadata = json.load(handle)
|
| 50 |
+
if metadata['outputs']:
|
| 51 |
+
shape = metadata['outputs'][0]['shape']
|
| 52 |
+
if all(isinstance(dim, int) for dim in shape):
|
| 53 |
+
return shape
|
| 54 |
+
return [int(item) for item in args.output_shape.split(',')]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def load_output_array(path, dtype, shape):
|
| 58 |
+
if path.endswith('.npy'):
|
| 59 |
+
array = np.load(path)
|
| 60 |
+
else:
|
| 61 |
+
array = np.fromfile(path, dtype=np.dtype(dtype))
|
| 62 |
+
return array.reshape(shape)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def logits_to_occ_labels(logits):
|
| 66 |
+
return np.argmax(logits, axis=-1).astype(np.uint8)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def vis_occ(semantics):
|
| 70 |
+
semantics_valid = np.logical_not(semantics == 17)
|
| 71 |
+
depth_axis = np.arange(semantics.shape[2]).reshape(1, 1, semantics.shape[2])
|
| 72 |
+
depth_axis = np.repeat(depth_axis, semantics.shape[0], axis=0)
|
| 73 |
+
depth_axis = np.repeat(depth_axis, semantics.shape[1], axis=1).astype(np.float32)
|
| 74 |
+
depth_axis = depth_axis * semantics_valid
|
| 75 |
+
selected = np.argmax(depth_axis, axis=2)
|
| 76 |
+
occ_bev = np.take_along_axis(semantics, selected[..., None], axis=2)
|
| 77 |
+
occ_bev = occ_bev.reshape(semantics.shape[0], semantics.shape[1]).astype(np.int32)
|
| 78 |
+
occ_bev_vis = COLORS_MAP[occ_bev].reshape(semantics.shape[0], semantics.shape[1], 4)[::-1, ::-1, :3]
|
| 79 |
+
return cv2.resize(occ_bev_vis, (400, 400))
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def main():
|
| 83 |
+
args = parse_args()
|
| 84 |
+
os.makedirs(args.save_dir, exist_ok=True)
|
| 85 |
+
|
| 86 |
+
output_shape = load_output_shape(args)
|
| 87 |
+
logits = load_output_array(args.output_path, args.dtype, output_shape)
|
| 88 |
+
occ_labels = logits_to_occ_labels(logits)
|
| 89 |
+
bev_vis = vis_occ(occ_labels[0])
|
| 90 |
+
|
| 91 |
+
logits_path = os.path.join(args.save_dir, 'output_0.npy')
|
| 92 |
+
labels_path = os.path.join(args.save_dir, 'occ_labels.npy')
|
| 93 |
+
vis_path = os.path.join(args.save_dir, 'occ_bev.png')
|
| 94 |
+
np.save(logits_path, logits)
|
| 95 |
+
np.save(labels_path, occ_labels)
|
| 96 |
+
cv2.imwrite(vis_path, bev_vis)
|
| 97 |
+
|
| 98 |
+
print('saved:', logits_path)
|
| 99 |
+
print('saved:', labels_path)
|
| 100 |
+
print('saved:', vis_path)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
if __name__ == '__main__':
|
| 104 |
+
main()
|
targets/QCS8550/W8A16/reference/part1.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import aidlite
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class FlashOccPart1(object):
|
| 7 |
+
def __init__(self, model_path, verbose=False):
|
| 8 |
+
self.input_shape = [[6, 256, 704, 3]]
|
| 9 |
+
self.output_shape = [[4224,64], [371712]]
|
| 10 |
+
self.verbose = verbose
|
| 11 |
+
|
| 12 |
+
self.model = aidlite.Model.create_instance(model_path)
|
| 13 |
+
if self.model is None:
|
| 14 |
+
print("Create model failed !")
|
| 15 |
+
return
|
| 16 |
+
self.model.set_model_properties(self.input_shape, aidlite.DataType.TYPE_FLOAT32, self.output_shape,
|
| 17 |
+
aidlite.DataType.TYPE_FLOAT32)
|
| 18 |
+
|
| 19 |
+
self.config = aidlite.Config.create_instance()
|
| 20 |
+
if self.config is None:
|
| 21 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
self.config.implement_type = aidlite.ImplementType.TYPE_LOCAL
|
| 25 |
+
self.config.framework_type = aidlite.FrameworkType.TYPE_QNN
|
| 26 |
+
self.config.accelerate_type = aidlite.AccelerateType.TYPE_DSP
|
| 27 |
+
self.config.is_quantify_model = 1
|
| 28 |
+
|
| 29 |
+
self.interpreter = aidlite.InterpreterBuilder.build_interpretper_from_model_and_config(self.model, self.config)
|
| 30 |
+
if self.interpreter is None:
|
| 31 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
self.interpreter.init()
|
| 35 |
+
self.interpreter.load_model()
|
| 36 |
+
|
| 37 |
+
def __del__(self):
|
| 38 |
+
self.interpreter.destory()
|
| 39 |
+
|
| 40 |
+
def __call__(self, img):
|
| 41 |
+
self.interpreter.set_input_tensor(0, img.data)
|
| 42 |
+
t1 = time.perf_counter()
|
| 43 |
+
self.interpreter.invoke()
|
| 44 |
+
cost_time = (time.perf_counter() - t1) * 1000
|
| 45 |
+
if self.verbose:
|
| 46 |
+
print(f'part1 qnn invoke: {cost_time:.3f}ms')
|
| 47 |
+
qnn_out_0 = self.interpreter.get_output_tensor(0).reshape(4224,64)
|
| 48 |
+
qnn_out_1 = self.interpreter.get_output_tensor(1)
|
| 49 |
+
outputs = qnn_out_0, qnn_out_1
|
| 50 |
+
return outputs
|
targets/QCS8550/W8A16/reference/part3.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import aidlite
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class FlashOccPart3(object):
|
| 7 |
+
def __init__(self, model_path, verbose=False):
|
| 8 |
+
self.input_shape = [[2560000]]
|
| 9 |
+
self.output_shape = [[1,200,200,16,18]]
|
| 10 |
+
self.verbose = verbose
|
| 11 |
+
|
| 12 |
+
self.model = aidlite.Model.create_instance(model_path)
|
| 13 |
+
if self.model is None:
|
| 14 |
+
print("Create model failed !")
|
| 15 |
+
return
|
| 16 |
+
self.model.set_model_properties(self.input_shape, aidlite.DataType.TYPE_FLOAT32, self.output_shape,
|
| 17 |
+
aidlite.DataType.TYPE_FLOAT32)
|
| 18 |
+
|
| 19 |
+
self.config = aidlite.Config.create_instance()
|
| 20 |
+
if self.config is None:
|
| 21 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
self.config.implement_type = aidlite.ImplementType.TYPE_LOCAL
|
| 25 |
+
self.config.framework_type = aidlite.FrameworkType.TYPE_QNN
|
| 26 |
+
self.config.accelerate_type = aidlite.AccelerateType.TYPE_DSP
|
| 27 |
+
self.config.is_quantify_model = 1
|
| 28 |
+
|
| 29 |
+
self.interpreter = aidlite.InterpreterBuilder.build_interpretper_from_model_and_config(self.model, self.config)
|
| 30 |
+
if self.interpreter is None:
|
| 31 |
+
print("build_interpretper_from_model_and_config failed !")
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
self.interpreter.init()
|
| 35 |
+
self.interpreter.load_model()
|
| 36 |
+
|
| 37 |
+
def __del__(self):
|
| 38 |
+
self.interpreter.destory()
|
| 39 |
+
|
| 40 |
+
def __call__(self, img):
|
| 41 |
+
self.interpreter.set_input_tensor(0, img.data)
|
| 42 |
+
t1 = time.perf_counter()
|
| 43 |
+
self.interpreter.invoke()
|
| 44 |
+
cost_time = (time.perf_counter() - t1) * 1000
|
| 45 |
+
if self.verbose:
|
| 46 |
+
print(f'part3 qnn invoke: {cost_time:.3f}ms')
|
| 47 |
+
qnn_out_0 = self.interpreter.get_output_tensor(0).reshape(1,200,200,16,18)
|
| 48 |
+
outputs = qnn_out_0
|
| 49 |
+
return outputs
|
targets/QCS8550/W8A16/reference/run_flashocc_split_onboard.py
ADDED
|
@@ -0,0 +1,728 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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import os
|
| 5 |
+
import sys
|
| 6 |
+
import time
|
| 7 |
+
from functools import lru_cache
|
| 8 |
+
|
| 9 |
+
import cv2
|
| 10 |
+
import numpy as np
|
| 11 |
+
import torch
|
| 12 |
+
from pyquaternion import Quaternion
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
from turbojpeg import TJPF_BGR, TurboJPEG
|
| 16 |
+
TURBOJPEG_IMPORT_ERROR = None
|
| 17 |
+
except ImportError:
|
| 18 |
+
TJPF_BGR = None
|
| 19 |
+
TurboJPEG = None
|
| 20 |
+
TURBOJPEG_IMPORT_ERROR = sys.exc_info()[1]
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
from deployment import _image_preprocess_ext
|
| 24 |
+
except ImportError:
|
| 25 |
+
_image_preprocess_ext = None
|
| 26 |
+
|
| 27 |
+
sys.path.insert(0, os.getcwd())
|
| 28 |
+
|
| 29 |
+
from deployment.bev_pool_v2_cpu import (
|
| 30 |
+
BEVPoolV2Workspace,
|
| 31 |
+
bev_pool_v2_cpu,
|
| 32 |
+
has_cpp_prepare_backend,
|
| 33 |
+
voxel_pooling_prepare_v2_cpp,
|
| 34 |
+
)
|
| 35 |
+
from deployment.postprocess_flashocc_qnn import logits_to_occ_labels, vis_occ
|
| 36 |
+
|
| 37 |
+
DATA_CONFIG = {
|
| 38 |
+
'cams': [
|
| 39 |
+
'CAM_FRONT_LEFT', 'CAM_FRONT', 'CAM_FRONT_RIGHT',
|
| 40 |
+
'CAM_BACK_LEFT', 'CAM_BACK', 'CAM_BACK_RIGHT'
|
| 41 |
+
],
|
| 42 |
+
'Ncams': 6,
|
| 43 |
+
'input_size': (256, 704),
|
| 44 |
+
'src_size': (900, 1600),
|
| 45 |
+
'resize': (-0.06, 0.11),
|
| 46 |
+
'rot': (-5.4, 5.4),
|
| 47 |
+
'flip': True,
|
| 48 |
+
'crop_h': (0.0, 0.0),
|
| 49 |
+
'resize_test': 0.0,
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
GRID_CONFIG = {
|
| 53 |
+
'x': [-40, 40, 0.4],
|
| 54 |
+
'y': [-40, 40, 0.4],
|
| 55 |
+
'z': [-1, 5.4, 6.4],
|
| 56 |
+
'depth': [1.0, 45.0, 0.5],
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
IMG_MEAN = np.array([123.675, 116.28, 103.53], dtype=np.float32)
|
| 60 |
+
IMG_STD = np.array([58.395, 57.12, 57.375], dtype=np.float32)
|
| 61 |
+
TO_RGB = True
|
| 62 |
+
BEV_OUT_CHANNELS = 64
|
| 63 |
+
DOWNSAMPLE = 16
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def parse_args():
|
| 67 |
+
parser = argparse.ArgumentParser(
|
| 68 |
+
description='Run split FlashOCC inference from data_predict without mmcv/mmdet3d dependencies')
|
| 69 |
+
parser.add_argument(
|
| 70 |
+
'--predict-root',
|
| 71 |
+
required=True,
|
| 72 |
+
help='directory containing v1.0-mini metadata and samples/CAM_* images')
|
| 73 |
+
parser.add_argument(
|
| 74 |
+
'--target-image',
|
| 75 |
+
required=True,
|
| 76 |
+
help='target image filename used to resolve the parent sample token')
|
| 77 |
+
parser.add_argument(
|
| 78 |
+
'--backend',
|
| 79 |
+
choices=['stub', 'onnxruntime'],
|
| 80 |
+
default='stub',
|
| 81 |
+
help='execution backend for part1/part3; replace stub with your QNN SDK calls on board')
|
| 82 |
+
parser.add_argument('--part1-model', default=None, help='path to part1 model file for onnxruntime debug mode')
|
| 83 |
+
parser.add_argument('--part3-model', default=None, help='path to part3 model file for onnxruntime debug mode')
|
| 84 |
+
parser.add_argument(
|
| 85 |
+
'--image-backend',
|
| 86 |
+
choices=['auto', 'cv2', 'turbojpeg'],
|
| 87 |
+
default='cv2',
|
| 88 |
+
help='jpeg decode backend for camera images; auto prefers turbojpeg when available')
|
| 89 |
+
parser.add_argument(
|
| 90 |
+
'--preprocess-backend',
|
| 91 |
+
choices=['auto', 'python', 'process', 'cpp'],
|
| 92 |
+
default='cpp',
|
| 93 |
+
help='image preprocessing backend; auto prefers cpp, then process, then python')
|
| 94 |
+
parser.add_argument('--save-dir', default=None, help='optional directory to save final png/json only')
|
| 95 |
+
parser.add_argument('--dump-logits', action='store_true', help='save output_0.npy to save-dir or current directory')
|
| 96 |
+
parser.add_argument('--verbose', action='store_true', help='print detailed per-stage logs')
|
| 97 |
+
return parser.parse_args()
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def load_json(path):
|
| 101 |
+
with open(path, 'r', encoding='utf-8') as handle:
|
| 102 |
+
return json.load(handle)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@lru_cache(maxsize=4)
|
| 106 |
+
def load_predict_metadata(meta_root):
|
| 107 |
+
sample_data = load_json(os.path.join(meta_root, 'sample_data.json'))
|
| 108 |
+
calibrated_sensor = build_token_index(load_json(os.path.join(meta_root, 'calibrated_sensor.json')))
|
| 109 |
+
ego_pose = build_token_index(load_json(os.path.join(meta_root, 'ego_pose.json')))
|
| 110 |
+
sensor = build_token_index(load_json(os.path.join(meta_root, 'sensor.json')))
|
| 111 |
+
return sample_data, calibrated_sensor, ego_pose, sensor
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def build_token_index(items):
|
| 115 |
+
return {item['token']: item for item in items}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def resolve_existing_path(root_dir, relative_path):
|
| 119 |
+
candidate = os.path.join(root_dir, relative_path)
|
| 120 |
+
if os.path.exists(candidate):
|
| 121 |
+
return candidate
|
| 122 |
+
|
| 123 |
+
basename = os.path.basename(relative_path)
|
| 124 |
+
for base_dir in ['samples', 'sweeps', '.']:
|
| 125 |
+
base_path = os.path.join(root_dir, base_dir)
|
| 126 |
+
if not os.path.isdir(base_path):
|
| 127 |
+
continue
|
| 128 |
+
for current_root, _, files in os.walk(base_path):
|
| 129 |
+
if basename in files:
|
| 130 |
+
return os.path.join(current_root, basename)
|
| 131 |
+
return candidate
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def normalize_image(img):
|
| 135 |
+
array = np.asarray(img, dtype=np.float32)
|
| 136 |
+
if TO_RGB:
|
| 137 |
+
array = array[..., ::-1]
|
| 138 |
+
array = (array - IMG_MEAN) / IMG_STD
|
| 139 |
+
return np.ascontiguousarray(array)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@lru_cache(maxsize=1)
|
| 143 |
+
def get_turbojpeg_decoder():
|
| 144 |
+
if TurboJPEG is None:
|
| 145 |
+
return None
|
| 146 |
+
try:
|
| 147 |
+
return TurboJPEG()
|
| 148 |
+
except Exception:
|
| 149 |
+
get_turbojpeg_decoder.last_error = sys.exc_info()[1]
|
| 150 |
+
return None
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
get_turbojpeg_decoder.last_error = None
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def resolve_image_backend(image_backend):
|
| 157 |
+
if image_backend == 'cv2':
|
| 158 |
+
return 'cv2', None
|
| 159 |
+
|
| 160 |
+
decoder = get_turbojpeg_decoder()
|
| 161 |
+
if decoder is not None:
|
| 162 |
+
return 'turbojpeg', decoder
|
| 163 |
+
|
| 164 |
+
if image_backend == 'turbojpeg':
|
| 165 |
+
if TURBOJPEG_IMPORT_ERROR is not None:
|
| 166 |
+
raise RuntimeError(
|
| 167 |
+
'turbojpeg backend requested, but importing turbojpeg failed: '
|
| 168 |
+
f'{TURBOJPEG_IMPORT_ERROR}. Install PyTurboJPEG into the same Python environment used to run this script.'
|
| 169 |
+
)
|
| 170 |
+
if get_turbojpeg_decoder.last_error is not None:
|
| 171 |
+
decoder_error = str(get_turbojpeg_decoder.last_error)
|
| 172 |
+
if 'requires libjpeg-turbo 3.0 or later' in decoder_error:
|
| 173 |
+
raise RuntimeError(
|
| 174 |
+
'turbojpeg backend requested, but creating TurboJPEG() failed: '
|
| 175 |
+
f'{decoder_error}. Your board currently has libjpeg-turbo 2.x; use PyTurboJPEG<2, '
|
| 176 |
+
'or upgrade the system libjpeg-turbo to 3.x before using PyTurboJPEG 2.x.'
|
| 177 |
+
)
|
| 178 |
+
raise RuntimeError(
|
| 179 |
+
'turbojpeg backend requested, but creating TurboJPEG() failed: '
|
| 180 |
+
f'{get_turbojpeg_decoder.last_error}. This usually means libturbojpeg is missing or not visible to the loader.'
|
| 181 |
+
)
|
| 182 |
+
raise RuntimeError('turbojpeg backend requested, but PyTurboJPEG or libturbojpeg is unavailable')
|
| 183 |
+
return 'cv2', None
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def load_camera_image(image_path, backend, turbojpeg_decoder=None):
|
| 187 |
+
if backend == 'turbojpeg':
|
| 188 |
+
with open(image_path, 'rb') as handle:
|
| 189 |
+
encoded = handle.read()
|
| 190 |
+
image = turbojpeg_decoder.decode(encoded, pixel_format=TJPF_BGR)
|
| 191 |
+
else:
|
| 192 |
+
image = cv2.imread(image_path, cv2.IMREAD_COLOR)
|
| 193 |
+
|
| 194 |
+
if image is None:
|
| 195 |
+
raise FileNotFoundError(f'failed to read image: {image_path}')
|
| 196 |
+
return image
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def has_cpp_preprocess_backend():
|
| 200 |
+
return _image_preprocess_ext is not None
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def resolve_preprocess_backend(preprocess_backend):
|
| 204 |
+
if preprocess_backend == 'python':
|
| 205 |
+
return 'python'
|
| 206 |
+
if preprocess_backend == 'process':
|
| 207 |
+
return 'process'
|
| 208 |
+
if preprocess_backend == 'cpp':
|
| 209 |
+
if not has_cpp_preprocess_backend():
|
| 210 |
+
raise RuntimeError(
|
| 211 |
+
'cpp preprocess backend requested, but deployment/_image_preprocess_ext is unavailable. '
|
| 212 |
+
'Build it first with: cd deployment && python setup_image_preprocess_ext.py build_ext --inplace'
|
| 213 |
+
)
|
| 214 |
+
return 'cpp'
|
| 215 |
+
if has_cpp_preprocess_backend():
|
| 216 |
+
return 'cpp'
|
| 217 |
+
if (os.cpu_count() or 1) > 1:
|
| 218 |
+
return 'process'
|
| 219 |
+
return 'python'
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def load_and_preprocess_one_image(image_path, image_backend):
|
| 223 |
+
resolved_image_backend, turbojpeg_decoder = resolve_image_backend(image_backend)
|
| 224 |
+
image = load_camera_image(image_path, resolved_image_backend, turbojpeg_decoder)
|
| 225 |
+
resize, resize_dims, crop, flip, rotate = sample_test_augmentation(image.shape[0], image.shape[1])
|
| 226 |
+
image, post_rot, post_tran = transform_image(image, resize, resize_dims, crop, flip, rotate)
|
| 227 |
+
return {
|
| 228 |
+
'image': normalize_image(image),
|
| 229 |
+
'post_rot': post_rot.numpy(),
|
| 230 |
+
'post_tran': post_tran.numpy(),
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def load_and_preprocess_images_process_pool(image_paths, image_backend):
|
| 235 |
+
max_workers = min(len(image_paths), max(1, os.cpu_count() or 1))
|
| 236 |
+
with concurrent.futures.ProcessPoolExecutor(max_workers=max_workers) as executor:
|
| 237 |
+
results = list(executor.map(load_and_preprocess_one_image, image_paths, [image_backend] * len(image_paths)))
|
| 238 |
+
return results
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def sample_test_augmentation(height, width):
|
| 242 |
+
final_height, final_width = DATA_CONFIG['input_size']
|
| 243 |
+
resize = float(final_width) / float(width) + DATA_CONFIG.get('resize_test', 0.0)
|
| 244 |
+
resize_dims = (int(width * resize), int(height * resize))
|
| 245 |
+
new_width, new_height = resize_dims
|
| 246 |
+
crop_h = int((1 - np.mean(DATA_CONFIG['crop_h'])) * new_height) - final_height
|
| 247 |
+
crop_w = int(max(0, new_width - final_width) / 2)
|
| 248 |
+
crop = (crop_w, crop_h, crop_w + final_width, crop_h + final_height)
|
| 249 |
+
flip = False
|
| 250 |
+
rotate = 0.0
|
| 251 |
+
return resize, resize_dims, crop, flip, rotate
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def get_rot_matrix(angle_radians):
|
| 255 |
+
return torch.tensor([
|
| 256 |
+
[np.cos(angle_radians), np.sin(angle_radians)],
|
| 257 |
+
[-np.sin(angle_radians), np.cos(angle_radians)],
|
| 258 |
+
], dtype=torch.float32)
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def apply_image_transform(img, resize_dims, crop, flip, rotate):
|
| 262 |
+
img = cv2.resize(img, resize_dims, interpolation=cv2.INTER_LINEAR)
|
| 263 |
+
crop_w0, crop_h0, crop_w1, crop_h1 = crop
|
| 264 |
+
img = img[crop_h0:crop_h1, crop_w0:crop_w1]
|
| 265 |
+
if flip:
|
| 266 |
+
img = cv2.flip(img, 1)
|
| 267 |
+
if rotate:
|
| 268 |
+
center = ((img.shape[1] - 1) * 0.5, (img.shape[0] - 1) * 0.5)
|
| 269 |
+
matrix = cv2.getRotationMatrix2D(center, rotate, 1.0)
|
| 270 |
+
img = cv2.warpAffine(img, matrix, (img.shape[1], img.shape[0]), flags=cv2.INTER_LINEAR)
|
| 271 |
+
return img
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def compute_post_transform(resize, crop, flip, rotate):
|
| 275 |
+
post_rot = torch.eye(2, dtype=torch.float32)
|
| 276 |
+
post_tran = torch.zeros(2, dtype=torch.float32)
|
| 277 |
+
|
| 278 |
+
post_rot *= resize
|
| 279 |
+
post_tran -= torch.tensor(crop[:2], dtype=torch.float32)
|
| 280 |
+
if flip:
|
| 281 |
+
flip_matrix = torch.tensor([[-1, 0], [0, 1]], dtype=torch.float32)
|
| 282 |
+
flip_bias = torch.tensor([crop[2] - crop[0], 0], dtype=torch.float32)
|
| 283 |
+
post_rot = flip_matrix.matmul(post_rot)
|
| 284 |
+
post_tran = flip_matrix.matmul(post_tran) + flip_bias
|
| 285 |
+
|
| 286 |
+
rotate_matrix = get_rot_matrix(rotate / 180.0 * np.pi)
|
| 287 |
+
rotate_bias = torch.tensor([crop[2] - crop[0], crop[3] - crop[1]], dtype=torch.float32) / 2.0
|
| 288 |
+
rotate_bias = rotate_matrix.matmul(-rotate_bias) + rotate_bias
|
| 289 |
+
post_rot = rotate_matrix.matmul(post_rot)
|
| 290 |
+
post_tran = rotate_matrix.matmul(post_tran) + rotate_bias
|
| 291 |
+
|
| 292 |
+
post_rot3 = torch.eye(3, dtype=torch.float32)
|
| 293 |
+
post_tran3 = torch.zeros(3, dtype=torch.float32)
|
| 294 |
+
post_rot3[:2, :2] = post_rot
|
| 295 |
+
post_tran3[:2] = post_tran
|
| 296 |
+
return post_rot3, post_tran3
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def transform_image(img, resize, resize_dims, crop, flip, rotate):
|
| 300 |
+
img = apply_image_transform(img, resize_dims, crop, flip, rotate)
|
| 301 |
+
post_rot3, post_tran3 = compute_post_transform(resize, crop, flip, rotate)
|
| 302 |
+
return img, post_rot3, post_tran3
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def build_transform_matrix(rotation, translation):
|
| 306 |
+
matrix = torch.eye(4, dtype=torch.float32)
|
| 307 |
+
matrix[:3, :3] = torch.tensor(Quaternion(rotation).rotation_matrix, dtype=torch.float32)
|
| 308 |
+
matrix[:3, 3] = torch.tensor(translation, dtype=torch.float32)
|
| 309 |
+
return matrix
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
@lru_cache(maxsize=1)
|
| 313 |
+
def create_frustum(depth_cfg, input_size, downsample):
|
| 314 |
+
height_in, width_in = input_size
|
| 315 |
+
feat_height, feat_width = height_in // downsample, width_in // downsample
|
| 316 |
+
depth = torch.arange(*depth_cfg, dtype=torch.float32).view(-1, 1, 1).expand(-1, feat_height, feat_width)
|
| 317 |
+
x_coords = torch.linspace(0, width_in - 1, feat_width, dtype=torch.float32).view(1, 1, feat_width)
|
| 318 |
+
x_coords = x_coords.expand(depth.shape[0], feat_height, feat_width)
|
| 319 |
+
y_coords = torch.linspace(0, height_in - 1, feat_height, dtype=torch.float32).view(1, feat_height, 1)
|
| 320 |
+
y_coords = y_coords.expand(depth.shape[0], feat_height, feat_width)
|
| 321 |
+
return torch.stack((x_coords, y_coords, depth), dim=-1)
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
@lru_cache(maxsize=1)
|
| 325 |
+
def create_grid_infos(grid_key):
|
| 326 |
+
config = {axis: list(values) for axis, *values in grid_key}
|
| 327 |
+
lower_bound = torch.tensor([config[axis][0] for axis in ['x', 'y', 'z']], dtype=torch.float32)
|
| 328 |
+
interval = torch.tensor([config[axis][2] for axis in ['x', 'y', 'z']], dtype=torch.float32)
|
| 329 |
+
size = torch.tensor([
|
| 330 |
+
(config[axis][1] - config[axis][0]) / config[axis][2]
|
| 331 |
+
for axis in ['x', 'y', 'z']
|
| 332 |
+
], dtype=torch.float32)
|
| 333 |
+
return lower_bound, interval, size
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
def prepare_inputs(imgs, sensor2egos, ego2globals, intrins, post_rots, post_trans, bda):
|
| 337 |
+
keyego2global = ego2globals[:, 0, ...].unsqueeze(1)
|
| 338 |
+
global2keyego = torch.inverse(keyego2global.double())
|
| 339 |
+
sensor2keyegos = global2keyego @ ego2globals.double() @ sensor2egos.double()
|
| 340 |
+
return [
|
| 341 |
+
imgs,
|
| 342 |
+
sensor2keyegos.float(),
|
| 343 |
+
ego2globals.float(),
|
| 344 |
+
intrins.float(),
|
| 345 |
+
post_rots.float(),
|
| 346 |
+
post_trans.float(),
|
| 347 |
+
bda.float(),
|
| 348 |
+
]
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def get_ego_coordinates(frustum, sensor2ego, ego2global, cam2imgs, post_rots, post_trans, bda):
|
| 352 |
+
batch_size, num_cams, _, _ = sensor2ego.shape
|
| 353 |
+
points = frustum.to(sensor2ego) - post_trans.view(batch_size, num_cams, 1, 1, 1, 3)
|
| 354 |
+
points = torch.inverse(post_rots).view(batch_size, num_cams, 1, 1, 1, 3, 3).matmul(points.unsqueeze(-1))
|
| 355 |
+
points = torch.cat((points[..., :2, :] * points[..., 2:3, :], points[..., 2:3, :]), dim=5)
|
| 356 |
+
combine = sensor2ego[:, :, :3, :3].matmul(torch.inverse(cam2imgs))
|
| 357 |
+
points = combine.view(batch_size, num_cams, 1, 1, 1, 3, 3).matmul(points).squeeze(-1)
|
| 358 |
+
points += sensor2ego[:, :, :3, 3].view(batch_size, num_cams, 1, 1, 1, 3)
|
| 359 |
+
points = bda.view(batch_size, 1, 1, 1, 1, 3, 3).matmul(points.unsqueeze(-1)).squeeze(-1)
|
| 360 |
+
return points
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def voxel_pooling_prepare_v2(coordinates, grid_lower_bound, grid_interval, grid_size):
|
| 364 |
+
if coordinates.device.type == 'cpu' and has_cpp_prepare_backend():
|
| 365 |
+
ranks_bev, ranks_depth, ranks_feat, interval_starts, interval_lengths = voxel_pooling_prepare_v2_cpp(
|
| 366 |
+
coordinates.numpy(),
|
| 367 |
+
grid_lower_bound.numpy(),
|
| 368 |
+
grid_interval.numpy(),
|
| 369 |
+
grid_size.numpy(),
|
| 370 |
+
)
|
| 371 |
+
return (
|
| 372 |
+
torch.from_numpy(ranks_bev),
|
| 373 |
+
torch.from_numpy(ranks_depth),
|
| 374 |
+
torch.from_numpy(ranks_feat),
|
| 375 |
+
torch.from_numpy(interval_starts),
|
| 376 |
+
torch.from_numpy(interval_lengths),
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
batch_size, num_cams, depth_bins, feat_height, feat_width, _ = coordinates.shape
|
| 380 |
+
num_points = batch_size * num_cams * depth_bins * feat_height * feat_width
|
| 381 |
+
|
| 382 |
+
ranks_depth = torch.arange(num_points, dtype=torch.int32, device=coordinates.device)
|
| 383 |
+
ranks_feat = torch.arange(num_points // depth_bins, dtype=torch.int32, device=coordinates.device)
|
| 384 |
+
ranks_feat = ranks_feat.reshape(batch_size, num_cams, 1, feat_height, feat_width)
|
| 385 |
+
ranks_feat = ranks_feat.expand(batch_size, num_cams, depth_bins, feat_height, feat_width).reshape(-1)
|
| 386 |
+
|
| 387 |
+
coordinates = ((coordinates - grid_lower_bound.to(coordinates)) / grid_interval.to(coordinates)).long()
|
| 388 |
+
coordinates = coordinates.view(num_points, 3)
|
| 389 |
+
batch_idx = torch.arange(batch_size, dtype=torch.long, device=coordinates.device).view(batch_size, 1)
|
| 390 |
+
batch_idx = batch_idx.expand(batch_size, num_points // batch_size).reshape(num_points, 1)
|
| 391 |
+
coordinates = torch.cat((coordinates, batch_idx), dim=1)
|
| 392 |
+
|
| 393 |
+
kept = (
|
| 394 |
+
(coordinates[:, 0] >= 0) & (coordinates[:, 0] < grid_size[0]) &
|
| 395 |
+
(coordinates[:, 1] >= 0) & (coordinates[:, 1] < grid_size[1]) &
|
| 396 |
+
(coordinates[:, 2] >= 0) & (coordinates[:, 2] < grid_size[2])
|
| 397 |
+
)
|
| 398 |
+
if kept.sum() == 0:
|
| 399 |
+
raise RuntimeError('no valid points remain inside the BEV grid')
|
| 400 |
+
|
| 401 |
+
coordinates = coordinates[kept]
|
| 402 |
+
ranks_depth = ranks_depth[kept]
|
| 403 |
+
ranks_feat = ranks_feat[kept]
|
| 404 |
+
|
| 405 |
+
ranks_bev = coordinates[:, 3] * (grid_size[2] * grid_size[1] * grid_size[0])
|
| 406 |
+
ranks_bev += coordinates[:, 2] * (grid_size[1] * grid_size[0])
|
| 407 |
+
ranks_bev += coordinates[:, 1] * grid_size[0] + coordinates[:, 0]
|
| 408 |
+
order = ranks_bev.argsort()
|
| 409 |
+
ranks_bev = ranks_bev[order]
|
| 410 |
+
ranks_depth = ranks_depth[order]
|
| 411 |
+
ranks_feat = ranks_feat[order]
|
| 412 |
+
|
| 413 |
+
kept = torch.ones(ranks_bev.shape[0], dtype=torch.bool, device=ranks_bev.device)
|
| 414 |
+
kept[1:] = ranks_bev[1:] != ranks_bev[:-1]
|
| 415 |
+
interval_starts = torch.where(kept)[0].int()
|
| 416 |
+
interval_lengths = torch.zeros_like(interval_starts)
|
| 417 |
+
interval_lengths[:-1] = interval_starts[1:] - interval_starts[:-1]
|
| 418 |
+
interval_lengths[-1] = ranks_bev.shape[0] - interval_starts[-1]
|
| 419 |
+
|
| 420 |
+
return (
|
| 421 |
+
ranks_bev.int().contiguous(),
|
| 422 |
+
ranks_depth.int().contiguous(),
|
| 423 |
+
ranks_feat.int().contiguous(),
|
| 424 |
+
interval_starts.int().contiguous(),
|
| 425 |
+
interval_lengths.int().contiguous(),
|
| 426 |
+
)
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def load_sample_from_predict_root(predict_root, target_image):
|
| 430 |
+
meta_root = os.path.join(predict_root, 'v1.0-mini')
|
| 431 |
+
sample_data, calibrated_sensor, ego_pose, sensor = load_predict_metadata(meta_root)
|
| 432 |
+
|
| 433 |
+
target_entry = next((item for item in sample_data if item.get('filename', '').endswith(target_image)), None)
|
| 434 |
+
if target_entry is None:
|
| 435 |
+
raise FileNotFoundError(f'target image not found in sample_data.json: {target_image}')
|
| 436 |
+
|
| 437 |
+
sample_token = target_entry['sample_token']
|
| 438 |
+
keyframe_entries = [
|
| 439 |
+
item for item in sample_data
|
| 440 |
+
if item.get('sample_token') == sample_token and item.get('is_key_frame')
|
| 441 |
+
]
|
| 442 |
+
|
| 443 |
+
cam_entries = {}
|
| 444 |
+
for item in keyframe_entries:
|
| 445 |
+
calibrated = calibrated_sensor[item['calibrated_sensor_token']]
|
| 446 |
+
sensor_info = sensor[calibrated['sensor_token']]
|
| 447 |
+
channel = sensor_info['channel']
|
| 448 |
+
if channel.startswith('CAM_'):
|
| 449 |
+
cam_entries[channel] = {
|
| 450 |
+
'data_path': resolve_existing_path(predict_root, item['filename']),
|
| 451 |
+
'cam_intrinsic': calibrated['camera_intrinsic'],
|
| 452 |
+
'sensor2ego_rotation': calibrated['rotation'],
|
| 453 |
+
'sensor2ego_translation': calibrated['translation'],
|
| 454 |
+
'ego2global_rotation': ego_pose[item['ego_pose_token']]['rotation'],
|
| 455 |
+
'ego2global_translation': ego_pose[item['ego_pose_token']]['translation'],
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
missing_cams = [cam for cam in DATA_CONFIG['cams'] if cam not in cam_entries]
|
| 459 |
+
if missing_cams:
|
| 460 |
+
raise ValueError(f'missing camera metadata for sample {sample_token}: {missing_cams}')
|
| 461 |
+
|
| 462 |
+
for cam_name, cam_info in cam_entries.items():
|
| 463 |
+
if not os.path.exists(cam_info['data_path']):
|
| 464 |
+
raise FileNotFoundError(f'missing image for {cam_name}: {cam_info["data_path"]}')
|
| 465 |
+
|
| 466 |
+
return sample_token, cam_entries
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
def build_sample_inputs_from_predict_root(
|
| 470 |
+
predict_root,
|
| 471 |
+
target_image,
|
| 472 |
+
backend='stub',
|
| 473 |
+
image_backend='auto',
|
| 474 |
+
preprocess_backend='auto'):
|
| 475 |
+
sample_token, cam_entries = load_sample_from_predict_root(predict_root, target_image)
|
| 476 |
+
resolved_image_backend, turbojpeg_decoder = resolve_image_backend(image_backend)
|
| 477 |
+
resolved_preprocess_backend = resolve_preprocess_backend(preprocess_backend)
|
| 478 |
+
|
| 479 |
+
imgs_nhwc = []
|
| 480 |
+
sensor2egos = []
|
| 481 |
+
ego2globals = []
|
| 482 |
+
intrins = []
|
| 483 |
+
post_rots = []
|
| 484 |
+
post_trans = []
|
| 485 |
+
|
| 486 |
+
cam_names = list(DATA_CONFIG['cams'])
|
| 487 |
+
|
| 488 |
+
if resolved_preprocess_backend == 'cpp':
|
| 489 |
+
src_height, src_width = DATA_CONFIG['src_size']
|
| 490 |
+
resize, resize_dims, crop, flip, rotate = sample_test_augmentation(src_height, src_width)
|
| 491 |
+
if flip or rotate:
|
| 492 |
+
raise RuntimeError('cpp preprocess backend currently supports the test-time no-flip/no-rotate path only')
|
| 493 |
+
img_nhwc = _image_preprocess_ext.load_and_preprocess_images(
|
| 494 |
+
[cam_entries[cam_name]['data_path'] for cam_name in cam_names],
|
| 495 |
+
int(resize_dims[0]),
|
| 496 |
+
int(resize_dims[1]),
|
| 497 |
+
int(crop[0]),
|
| 498 |
+
int(crop[1]),
|
| 499 |
+
int(crop[2] - crop[0]),
|
| 500 |
+
int(crop[3] - crop[1]),
|
| 501 |
+
IMG_MEAN.tolist(),
|
| 502 |
+
IMG_STD.tolist(),
|
| 503 |
+
bool(TO_RGB),
|
| 504 |
+
len(cam_names),
|
| 505 |
+
)
|
| 506 |
+
shared_post_rot, shared_post_tran = compute_post_transform(resize, crop, flip, rotate)
|
| 507 |
+
elif resolved_preprocess_backend == 'process':
|
| 508 |
+
process_results = load_and_preprocess_images_process_pool(
|
| 509 |
+
[cam_entries[cam_name]['data_path'] for cam_name in cam_names],
|
| 510 |
+
image_backend,
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
for cam_name in cam_names:
|
| 514 |
+
cam_info = cam_entries[cam_name]
|
| 515 |
+
if resolved_preprocess_backend == 'python':
|
| 516 |
+
image = load_camera_image(cam_info['data_path'], resolved_image_backend, turbojpeg_decoder)
|
| 517 |
+
resize, resize_dims, crop, flip, rotate = sample_test_augmentation(image.shape[0], image.shape[1])
|
| 518 |
+
image, post_rot, post_tran = transform_image(image, resize, resize_dims, crop, flip, rotate)
|
| 519 |
+
imgs_nhwc.append(normalize_image(image))
|
| 520 |
+
elif resolved_preprocess_backend == 'process':
|
| 521 |
+
result = process_results[len(imgs_nhwc)]
|
| 522 |
+
imgs_nhwc.append(result['image'])
|
| 523 |
+
post_rot = torch.from_numpy(result['post_rot']).float()
|
| 524 |
+
post_tran = torch.from_numpy(result['post_tran']).float()
|
| 525 |
+
else:
|
| 526 |
+
post_rot = shared_post_rot
|
| 527 |
+
post_tran = shared_post_tran
|
| 528 |
+
|
| 529 |
+
sensor2egos.append(build_transform_matrix(cam_info['sensor2ego_rotation'], cam_info['sensor2ego_translation']))
|
| 530 |
+
ego2globals.append(build_transform_matrix(cam_info['ego2global_rotation'], cam_info['ego2global_translation']))
|
| 531 |
+
intrins.append(torch.tensor(cam_info['cam_intrinsic'], dtype=torch.float32))
|
| 532 |
+
post_rots.append(post_rot)
|
| 533 |
+
post_trans.append(post_tran)
|
| 534 |
+
|
| 535 |
+
if resolved_preprocess_backend in ('python', 'process'):
|
| 536 |
+
img_nhwc = np.ascontiguousarray(np.stack(imgs_nhwc, axis=0).astype(np.float32, copy=False))
|
| 537 |
+
img_nchw = np.ascontiguousarray(np.transpose(img_nhwc, (0, 3, 1, 2)))
|
| 538 |
+
imgs = torch.from_numpy(img_nchw).unsqueeze(0).contiguous()
|
| 539 |
+
sensor2egos = torch.stack(sensor2egos, dim=0).unsqueeze(0).contiguous()
|
| 540 |
+
ego2globals = torch.stack(ego2globals, dim=0).unsqueeze(0).contiguous()
|
| 541 |
+
intrins = torch.stack(intrins, dim=0).unsqueeze(0).contiguous()
|
| 542 |
+
post_rots = torch.stack(post_rots, dim=0).unsqueeze(0).contiguous()
|
| 543 |
+
post_trans = torch.stack(post_trans, dim=0).unsqueeze(0).contiguous()
|
| 544 |
+
bda = torch.eye(3, dtype=torch.float32).unsqueeze(0).contiguous()
|
| 545 |
+
|
| 546 |
+
prepared = prepare_inputs(imgs, sensor2egos, ego2globals, intrins, post_rots, post_trans, bda)
|
| 547 |
+
frustum = create_frustum(tuple(GRID_CONFIG['depth']), tuple(DATA_CONFIG['input_size']), DOWNSAMPLE)
|
| 548 |
+
grid_key = tuple((axis, *GRID_CONFIG[axis]) for axis in ['x', 'y', 'z'])
|
| 549 |
+
grid_lower_bound, grid_interval, grid_size = create_grid_infos(grid_key)
|
| 550 |
+
coordinates = get_ego_coordinates(frustum, *prepared[1:7])
|
| 551 |
+
ranks_bev, ranks_depth, ranks_feat, interval_starts, interval_lengths = voxel_pooling_prepare_v2(
|
| 552 |
+
coordinates, grid_lower_bound, grid_interval, grid_size.long())
|
| 553 |
+
|
| 554 |
+
bev_shape = [1, int(grid_size[1].item()), int(grid_size[0].item()), BEV_OUT_CHANNELS]
|
| 555 |
+
|
| 556 |
+
return {
|
| 557 |
+
'sample_index': None,
|
| 558 |
+
'sample_token': sample_token,
|
| 559 |
+
'camera_paths': {key: value['data_path'] for key, value in cam_entries.items()},
|
| 560 |
+
'image_backend': resolved_image_backend,
|
| 561 |
+
'preprocess_backend': resolved_preprocess_backend,
|
| 562 |
+
'img_nchw': img_nchw,
|
| 563 |
+
'img_nhwc': img_nhwc,
|
| 564 |
+
'ranks_bev': ranks_bev.cpu().numpy().astype(np.int32),
|
| 565 |
+
'ranks_depth': ranks_depth.cpu().numpy().astype(np.int32),
|
| 566 |
+
'ranks_feat': ranks_feat.cpu().numpy().astype(np.int32),
|
| 567 |
+
'interval_starts': interval_starts.cpu().numpy().astype(np.int32),
|
| 568 |
+
'interval_lengths': interval_lengths.cpu().numpy().astype(np.int32),
|
| 569 |
+
'bev_shape': bev_shape,
|
| 570 |
+
'source_target_image': target_image,
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
class BaseSplitRunner:
|
| 575 |
+
def run_part1(self, img):
|
| 576 |
+
raise NotImplementedError()
|
| 577 |
+
|
| 578 |
+
def run_part3(self, bev_feat):
|
| 579 |
+
raise NotImplementedError()
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
class StubQNNRunner(BaseSplitRunner):
|
| 583 |
+
def __init__(self, part1_model=None, part3_model=None, verbose=False):
|
| 584 |
+
from part1 import FlashOccPart1
|
| 585 |
+
from part3 import FlashOccPart3
|
| 586 |
+
|
| 587 |
+
self.model_part1 = FlashOccPart1(part1_model, verbose=verbose)
|
| 588 |
+
self.model_part_3 = FlashOccPart3(part3_model, verbose=verbose)
|
| 589 |
+
|
| 590 |
+
def run_part1(self, img):
|
| 591 |
+
return self.model_part1(img)
|
| 592 |
+
|
| 593 |
+
def run_part3(self, bev_feat):
|
| 594 |
+
return self.model_part_3(bev_feat)
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
class OnnxRuntimeRunner(BaseSplitRunner):
|
| 598 |
+
def __init__(self, part1_model, part3_model):
|
| 599 |
+
if not part1_model or not part3_model:
|
| 600 |
+
raise ValueError('onnxruntime backend requires --part1-model and --part3-model')
|
| 601 |
+
import onnxruntime as ort
|
| 602 |
+
|
| 603 |
+
self.part1_session = ort.InferenceSession(part1_model, providers=['CPUExecutionProvider'])
|
| 604 |
+
self.part3_session = ort.InferenceSession(part3_model, providers=['CPUExecutionProvider'])
|
| 605 |
+
|
| 606 |
+
def run_part1(self, img):
|
| 607 |
+
tran_feat, depth = self.part1_session.run(None, {'img': img})
|
| 608 |
+
return tran_feat.astype(np.float32), depth.astype(np.float32)
|
| 609 |
+
|
| 610 |
+
def run_part3(self, bev_feat):
|
| 611 |
+
output_0 = self.part3_session.run(None, {'bev_feat': bev_feat})[0]
|
| 612 |
+
return output_0.astype(np.float32)
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
def build_runner(args):
|
| 616 |
+
if args.backend == 'onnxruntime':
|
| 617 |
+
return OnnxRuntimeRunner(args.part1_model, args.part3_model)
|
| 618 |
+
return StubQNNRunner(args.part1_model, args.part3_model, verbose=args.verbose)
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def summarize_prediction(logits, occ_labels, sample_inputs):
|
| 622 |
+
class_hist = np.bincount(occ_labels.reshape(-1), minlength=18)
|
| 623 |
+
return {
|
| 624 |
+
'sample_index': sample_inputs['sample_index'],
|
| 625 |
+
'sample_token': sample_inputs['sample_token'],
|
| 626 |
+
'camera_paths': sample_inputs['camera_paths'],
|
| 627 |
+
'source_target_image': sample_inputs.get('source_target_image'),
|
| 628 |
+
'img_shape': list(sample_inputs['img_nchw'].shape),
|
| 629 |
+
'tran_feat_points': int(sample_inputs['ranks_feat'].shape[0]),
|
| 630 |
+
'bev_intervals': int(sample_inputs['interval_starts'].shape[0]),
|
| 631 |
+
'bev_shape': sample_inputs['bev_shape'],
|
| 632 |
+
'output_shape': list(logits.shape),
|
| 633 |
+
'predicted_class_histogram': class_hist.tolist(),
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
def maybe_save_outputs(save_dir, summary, occ_bev, logits=None):
|
| 638 |
+
if not save_dir:
|
| 639 |
+
return
|
| 640 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 641 |
+
summary_path = os.path.join(save_dir, 'prediction_summary.json')
|
| 642 |
+
occ_bev_path = os.path.join(save_dir, 'occ_bev.png')
|
| 643 |
+
if logits is not None:
|
| 644 |
+
logits_path = os.path.join(save_dir, 'output_0.npy')
|
| 645 |
+
np.save(logits_path, logits)
|
| 646 |
+
print('saved:', logits_path)
|
| 647 |
+
with open(summary_path, 'w', encoding='utf-8') as handle:
|
| 648 |
+
json.dump(summary, handle, indent=2, ensure_ascii=False)
|
| 649 |
+
cv2.imwrite(occ_bev_path, occ_bev)
|
| 650 |
+
print('saved:', summary_path)
|
| 651 |
+
print('saved:', occ_bev_path)
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
def build_bev_pool_workspace(sample_inputs):
|
| 655 |
+
return BEVPoolV2Workspace.from_inputs(
|
| 656 |
+
ranks_feat=sample_inputs['ranks_feat'],
|
| 657 |
+
interval_starts=sample_inputs['interval_starts'],
|
| 658 |
+
ranks_bev=sample_inputs['ranks_bev'],
|
| 659 |
+
bev_shape=sample_inputs['bev_shape'],
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
def main():
|
| 664 |
+
args = parse_args()
|
| 665 |
+
stat_time = time.perf_counter()
|
| 666 |
+
sample_inputs = build_sample_inputs_from_predict_root(
|
| 667 |
+
args.predict_root,
|
| 668 |
+
args.target_image,
|
| 669 |
+
backend=args.backend,
|
| 670 |
+
image_backend=args.image_backend,
|
| 671 |
+
preprocess_backend=args.preprocess_backend,
|
| 672 |
+
)
|
| 673 |
+
print('前处理耗时:', f'{(time.perf_counter() - stat_time) * 1000}ms')
|
| 674 |
+
if args.verbose:
|
| 675 |
+
print('image backend:', sample_inputs['image_backend'])
|
| 676 |
+
print('preprocess backend:', sample_inputs['preprocess_backend'])
|
| 677 |
+
bev_workspace = build_bev_pool_workspace(sample_inputs)
|
| 678 |
+
runner = build_runner(args)
|
| 679 |
+
|
| 680 |
+
if args.verbose:
|
| 681 |
+
print('Running part1...')
|
| 682 |
+
infer_start = time.perf_counter()
|
| 683 |
+
part1_input = sample_inputs['img_nhwc'] if args.backend == 'stub' else sample_inputs['img_nchw']
|
| 684 |
+
tran_feat, depth = runner.run_part1(part1_input)
|
| 685 |
+
if args.verbose:
|
| 686 |
+
print('part1 outputs:', list(tran_feat.shape), list(depth.shape))
|
| 687 |
+
|
| 688 |
+
if args.verbose:
|
| 689 |
+
print('Running CPU bev_pool_v2...')
|
| 690 |
+
bev_time = time.perf_counter()
|
| 691 |
+
bev_feat = bev_pool_v2_cpu(
|
| 692 |
+
tran_feat=tran_feat,
|
| 693 |
+
depth=depth,
|
| 694 |
+
ranks_depth=sample_inputs['ranks_depth'],
|
| 695 |
+
ranks_feat=sample_inputs['ranks_feat'],
|
| 696 |
+
ranks_bev=sample_inputs['ranks_bev'],
|
| 697 |
+
interval_starts=sample_inputs['interval_starts'],
|
| 698 |
+
interval_lengths=sample_inputs['interval_lengths'],
|
| 699 |
+
bev_shape=sample_inputs['bev_shape'],
|
| 700 |
+
workspace=bev_workspace,
|
| 701 |
+
).reshape(-1).astype(np.float32, copy=False)
|
| 702 |
+
print('bev分析耗时:', f'{(time.perf_counter() - bev_time) * 1000}ms')
|
| 703 |
+
if args.verbose:
|
| 704 |
+
print('bev_feat shape:', list(bev_feat.shape))
|
| 705 |
+
|
| 706 |
+
if args.verbose:
|
| 707 |
+
print('Running part3...')
|
| 708 |
+
logits = runner.run_part3(bev_feat)
|
| 709 |
+
print('模型分析总耗时:', f'{(time.perf_counter() - infer_start) * 1000}ms')
|
| 710 |
+
print('*' * 50)
|
| 711 |
+
print('output shape:', logits.shape)
|
| 712 |
+
if args.dump_logits:
|
| 713 |
+
output_dir = args.save_dir if args.save_dir else os.getcwd()
|
| 714 |
+
if not os.path.exists(output_dir):
|
| 715 |
+
os.makedirs(output_dir)
|
| 716 |
+
output_path = os.path.join(output_dir, 'output_0.npy')
|
| 717 |
+
np.save(output_path, logits)
|
| 718 |
+
print('saved:', output_path)
|
| 719 |
+
print('*' * 50)
|
| 720 |
+
occ_labels = logits_to_occ_labels(logits)
|
| 721 |
+
summary = summarize_prediction(logits, occ_labels, sample_inputs)
|
| 722 |
+
print(json.dumps(summary, indent=2, ensure_ascii=False))
|
| 723 |
+
occ_bev = vis_occ(occ_labels[0]) if args.save_dir else None
|
| 724 |
+
maybe_save_outputs(args.save_dir, summary, occ_bev, None)
|
| 725 |
+
|
| 726 |
+
|
| 727 |
+
if __name__ == '__main__':
|
| 728 |
+
main()
|
targets/QCS8550/W8A16/samples/back.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/W8A16/samples/back_left.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/W8A16/samples/back_right.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/W8A16/samples/front.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/W8A16/samples/front_left.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/W8A16/samples/front_right.jpg
ADDED
|
Git LFS Details
|
targets/QCS8550/model.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"soc": "QCS8550",
|
| 3 |
+
"default_precision": "FP16",
|
| 4 |
+
"variants": {
|
| 5 |
+
"FP16": "FP16/",
|
| 6 |
+
"W8A16": "W8A16/"
|
| 7 |
+
}
|
| 8 |
+
}
|