[The 3rd Xuantie Cup RISC-V Application Innovation Competition] Licheepi 4A environment construction and function trial
[Copy link]
This post was last edited by hollyedward on 2023-12-5 11:26
The npu that the board comes with needs to be burned with the latest system to support the latest npu driver. I chose the debian system
The official Docker image for the development environment is provided. I use dcoekr for Windows on Windows. It is based on wsl2 and has a relatively simple interface configuration. It can also better manage images and containers when paired with vscode.
Use Docker to build the environment
Use docker command to pull the image in powershell
1) Get the Docker image of the HHB environment:
docker pull hhb4tools/hhb:2.4.5
2) In Settings-Docker Engine, you can configure related parameters, such as container size and image address
3) Download the docker extension in vscode
After the installation is complete, there will be an icon on the left to enter the management interface
You can see that the Docker management plug-in in vscode has many functions. All containers and images on the device can be viewed and managed here. You can start or close the container by right-clicking.
Start a container from the image.
Or run the container using the command
3) After starting the container, a green arrow will appear in front of the name, indicating that the container is running.
The advantage of using vscode to connect to docker is that you can use vscode to directly edit the files in the image. Here you can view directory files, as well as view and edit files. It is really convenient for users who are accustomed to using vscode.
You can also use shell to connect to docker. The default attach shell in the right click is sh, which has a lower interface display and functions than bash. We need to create a new terminal and use the docker command to specify the connection to bash.
Enter the container using bash
docker exec -it 96c7e3dcad93bb2bb605e6c5dd7572705397346041c244b6ab54b2036d8f5eea /bin/bash
Check that the hbb version used is the latest
This plugin can also be used to download files from the image to the host, but I haven't found a place to upload files yet. The tutorials I searched online are relatively old and they didn't work. In the end, I used the docker command to transfer files between the docker image and the host.
4) Use the command docker cp host address docker image id: the address in the image, the file isolation symbols used by Windows and Linux are opposite
Upload the downloaded files from the host to the mirror
docker cp C:\Users\imagi\Downloads\mobilenetv2-12.onnx 96c7e3dcad93:/home/example/th1520_npu/onnx_mobilenetv2_c++/
Transfer the files in the image to the host
docker cp 96c7e3dcad93:/home/example/th1520_npu/onnx_mobilenetv2_c++/ C:\Users\imagi\Downloads\
Finally, the compiled file is transferred to the development board via scp
scp -r C:\Users\imagi\Downloads\onnx_mobilenetv2_c++\ debian@192.168.137.36:~
Deploy the mobilenetv2 model on the icheePi4A platform to complete image classification
1) Enter the configured virtual environment ort
source /root/ort/bin/activate
2) The compiled file needs to be given permission to execute on the development board
//给文件夹赋权
chmod -R 777 onnx_mobilenetv2_c++/
//给文件赋权
chmod -x 777 mobilenetv2_example
3) Run the executable file
./mobilenetv2_example
4) Can successfully reason
debian@lpi4a:~/onnx_mobilenetv2_c++$ sudo su
root@lpi4a:/home/debian/onnx_mobilenetv2_c++# cd
root@lpi4a:~# ls
hhb_onnxruntime_th1520-2.6.0-cp311-cp311-linux_riscv64.whl ort
onnxruntime-1.14.1-cp311-cp311-linux_riscv64.whl prebuilt_whl
root@lpi4a:~# source /root/o
onnxruntime-1.14.1-cp311-cp311-linux_riscv64.whl ort/
root@lpi4a:~# source /root/ort/bin/activate
(ort) root@lpi4a:~# cd /home/debian/onnx_mobilenetv2_c++
(ort) root@lpi4a:/home/debian/onnx_mobilenetv2_c++# ls
hhb_out input_img.bin_output0_1_1000.txt main.cpp mobilenetv2_example shl.hhb.bm
input_img.bin input_img.tensor mobilenetv2-12.onnx persian_cat.jpg synset.txt
(ort) root@lpi4a:/home/debian/onnx_mobilenetv2_c++# ./mobilenetv2_example
********** preprocess image **********
********** run mobilenetv2 **********
INFO: Mapping phase 'Convert to CnnModel' - Started...
INFO: Mapping phase 'Convert to CnnModel' - Finished after 106.277ms
INFO: Hw optimizer max_threads = 1
INFO: fast_optim = 1000
INFO: Mapping phase 'Process Graph Topology' - Started...
INFO: Mapping phase 'Process Graph Topology' - Finished after 7981.096ms
INFO: Mapping phase 'Search for optimal solution' - Started...
INFO: Mapping phase 'Search for optimal solution' - Finished after 46375.076ms
INFO: Mapping phase 'Apply Graph Solution' - Started...
INFO: Mapping phase 'Apply Graph Solution' - Finished after 1244.890ms
INFO: Mapping phase 'Processing Coefficients' - Started...
INFO: Mapping phase 'Processing Coefficients' - Finished after 1220.243ms
INFO: Mapping phase 'Process Graph Hierarchy' - Started...
INFO: Mapping phase 'Process Graph Hierarchy' - Finished after 342.447ms
INFO: Mapping phase 'Late DSC Remover' - Started...
INFO: Mapping phase 'Late DSC Remover' - Finished after 5.915ms
INFO: Mapping phase 'Init all layers' - Started...
INFO: Mapping phase 'Init all layers' - Finished after 114.970ms
INFO: Mapping phase 'Assigning passes to cores' - Started...
INFO: Mapping phase 'Assigning passes to cores' - Finished after 30.937ms
INFO: Mapping phase 'Processing Memory Requirements' - Started...
INFO: Mapping phase 'Processing Memory Requirements' - Finished after 299.067ms
INFO: Mapping phase 'Execution Reorder' - Started...
INFO: Mapping phase 'Execution Reorder' - Finished after 24.217ms
INFO: Mapping phase 'Calculating Synchronization data' - Started...
INFO: Mapping phase 'Calculating Synchronization data' - Finished after 882.452ms
INFO: Mapping phase 'Lower to IR' - Started...
INFO: Mapping phase 'Lower to IR' - Finished after 597.547ms
INFO: Mapping phase 'Generate Binary Stream' - Started...
INFO: BUFF 1 : 3192832 : Coefficients
INFO: BUFF 2 : 150528 : Network Input
INFO: BUFF 3 : 1000 : Network Output
INFO: BUFF 4 : 2236416 : Temporary
INFO: BUFF 5 : 132352 : Command Stream
INFO: TOTAL : 5713128 bytes
INFO: segment_id 0 - NNA
INFO: input buffer 2 [1 3 224 224 ] Q8s0.018333z-13 1
INFO: output buffer 3 [1 1000 ] Q8s0.094434z-43 1
INFO: cmdstream buffer 5
INFO: coeff buffer 1
INFO: temporary buffer 4
INFO: Mapping phase 'Generate Binary Stream' - Finished after 193.585ms
INFO: NNA clock:792000 [kHz]
INFO: Heap :ocm (0x18)
INFO: Heap :anonymous (0x2)
INFO: Heap :dmabuf (0x2)
INFO: Heap :unified (0x5)
FATAL: Importing 150528 bytes of CPU memory has failed (wrong memory alignment)
Run graph execution time: 14.72540ms, FPS=67.91
=== tensor info ===
shape: 1 3 224 224
data pointer: 0x1f73220
=== tensor info ===
shape: 1 1000
data pointer: 0x3fe9f39000
The max_value of output: 16.053827
The min_value of output: -8.026914
The mean_value of output: -0.001889
The std_value of output: 9.203342
============ top5: ===========
283: 16.053827
281: 14.165141
287: 11.709850
285: 11.615416
282: 11.332113
free(): invalid pointer
Aborted
********** postprocess result **********
********** probability top5: **********
n02123394 Persian cat
n02123045 tabby, tabby cat
n02127052 lynx, catamount
n02124075 Egyptian cat
n02123159 tiger cat
|