405 views|2 replies

422

Posts

4

Resources
The OP
 

[AI Challenge Camp 3] Deploy MNIST digit recognition on Luckfox Pico [Copy link]

This post was last edited by Beifang on 2024-6-12 22:25

Deploy MNIST digit recognition on Luckfox Pico

1 Overview

After completing the first and second tasks, you are ready to deploy the AI model on Luckfox.

#AI Challenge Camp First Stop#Pytorch Installation and MNIST Recognition - Linux and Android - Electronic Engineering World - Forum (eeworld.com.cn)

[AI Challenge Camp Second Stop] Convert MNIST to RKNN format and package the algorithm into SDK for engineering deployment - Linux and Android - Electronic Engineering World - Forum (eeworld.com.cn)

2 Update firmware

When I first got the development board, I could connect it with adb and read the file system, but after connecting the CSI camera, I could not read the video as described in the manual. According to the following wiki information,

CSI Camera | LUCKFOX WIKI

The factory version is a test image, which can only test the normal operation of the development board. To implement any specific function, you need to compile the system yourself. There are buildroot and ubuntu options. Ubuntu is larger and needs to be loaded on the SD card, while buildroot is much simpler and can be used with menuconfig definitions and then compiled by yourself. Therefore, choose to use buildroot to implement it and write it directly to the SPI memory.

According to the manual, you need to clone the source code from GitHub, configure the cross-compilation tool, and use the script to compile. Because gitee also synchronizes the source code, you can quickly get it done from gitee, avoiding the long wait on github.

Because the cross-compilation tool is only applicable to Linux systems, it is more convenient to do this step directly on Ubuntu, otherwise WSL or a virtual machine is required.

The following is the compilation process. On an old laptop, it took about 4 hours, and there were only some warnings during the whole process. It was very smooth.

The compilation result is as shown below, and the build output path is prompted.

Enter the directory and generate the following files. There is only one file that needs to be written, which is uboot.img

In fact, the cloud disk also provides an image that can be written directly. You can download and unzip it. See below, which is actually the same as the above

Press the Boot button to power on, and you can find the development board, as shown in Fuzhou Rockchip....

Then use the upgrade_tool tool to download to the Luchfox development board. The upgrade_tool also needs to be downloaded and installed. It is only suitable for Linux systems.

update successed

At this time, I searched for the connected network port and found that I could not connect to the development board using 172.32.0.93.

This took a long time, and finally I found that this was a Luchfox pico pro, and the network port was configured to another URL starting with 192.168.10.x. You need to use RNDS to connect to the virtual network port of the USB port before you can continue to connect using this URL.

Although not practical, implementing the above functionality on Windows requires the use of another tool,

I won’t repeat myself, just check the wiki above.

3. Realize video stream capture

Connect the video camera. Note that the connection of Luchfox Pico Pro is different from that of ordinary Pico. Use VLC, which can directly capture the video stream.

Select the real-time video of channel 0 of rtsp://172.32.0.93, and the display is as follows: flowers and plants

You can also use ssh to connect, username root, password luckfox, and MobaXterm in GUI mode, which is much more intuitive.

To upload files, you can also use the scp command line command.

Similarly, adb can also be used. First search for the device. If there is only one, use adb shell. This adb is the android device connection tool. If you have installed android studio, it comes with it. Otherwise, you need to download it separately and unzip it for use.

Find rkipc.ini in this directory. This means that the CSI camera is successfully connected. The original factory test version does not have it.

Use adb push to upload files

This meets the requirements for video recognition MNIST.

4 Call SDK to implement MNIST digit recognition based on video stream

4.1 As mentioned earlier, you first need to train your own AI model, then convert it into the public ONNX format, and then use professional tools to compress it and convert it into the rknn format. After this compression, the parameters are all integerized, and there is a certain loss in recognition accuracy.

This code is written in C language. The video data is read using the opencv library. It is compiled using the lib library.

void *data = RK_MPI_MB_Handle2VirAddr(stVpssFrame.stVFrame.pMbBlk);  
cv::Mat frame(height,width,CV_8UC3,data);   

The mat matrix data is read and the output is read under the inference command. This is the SDK compiled earlier.

inference_mnist_model(&rknn_app_ctx, sub_pics[i], detect_results);

In general, the above inference commands use the built-in AI data processing API to implement the corresponding high-intensity convolution calculations, output the results, and compare them with the results of the selected numbers.

This is based on the changes of the yolo8 example code. Other models are still implemented using the programming sequence developed in this way. The only difference is the model parameters used.

In this way, through the calculation of different models, the code changes are almost the same, but by separating the trained models, multiple functions can be achieved.

4.2 After compiling, the executable file is used directly, and the result file is interrupted.

This is the automatic call camera that needs to be stopped by RkLunch-stop.sh. Note the lowercase and uppercase letters.

Restart the code and the output command line of continuous recognition will be displayed.

As you can see from the output, the substandard 2 is recognized as 3
The substandard 3 is identified as 5.
This time the recognition is correct, the handwriting is relatively standard 3, and it doesn't matter if the font is a little blurry. And the recognition speed is very fast, it can reach 21fps, which is 30fps for continuous video. Basically, if you don't pay too much attention, you can recognize data in real time.

5 Summary

After this process, we can find that MNIST can realize the digital recognition function in a relatively practical way, and the speed is also quite good. It should be noted that the MNIST model generally needs to be compressed. The recognition rate is obviously not as good as when testing. The general confidence level is 50%, while it has exceeded 90% during training. In the first stage of training, it is actually 99%. The data looks very poor, but the more standardized writing can be perfectly read.

This is a practical choice that balances cost performance and power consumption.

This post is from Linux and Android

Latest reply

Are there hardware limitations due to the size and complexity of the model?   Details Published on 2024-6-14 07:20

6555

Posts

0

Resources
2
 

Are there hardware limitations due to the size and complexity of the model?

This post is from Linux and Android

Comments

Indeed, the smallest industrial model is usually around 4-5M, such as Google's mobileNet v2. Such data throughput and computational complexity are very large, so compression is required. Usually, the floating point numbers of the parameters are changed to integers, which can compress the data by 2-4 times. Other structural optimizations require more powerful optimizations.  Details Published on 2024-6-14 09:29
 
 

422

Posts

4

Resources
3
 
Jacktang posted on 2024-6-14 07:20 Will there be hardware limitations due to the size and complexity of the model?

It is indeed the case.

Usually, the smallest industrial model is around 4-5M, such as Google's mobileNet v2. This requires a large amount of data throughput and computation, so compression is required.

Usually, the floating-point number of the parameter is changed to an integer, which can compress it by 2-4 times. Other structural optimizations require more powerful optimization capabilities.

This MNIST effect is good, reaching 20fps, the accuracy is much lower, around 40%-50%, but it can still be recognized.

It's very successful.

This post is from Linux and Android
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
BlueNRG-1/2 Flash operations require mutual exclusion with BLE events

When using the Flash of BlueNRG-1/2 to store application data, you may encounter problems such as no Bluetooth signal o ...

T6963C negative display problem

480893 I'm working on T6963C recently, and I don't quite understand the manual regarding negative display under text fea ...

【Development and application based on NUCLEO-F746ZG motor】14. Parameter configuration - motor parameter configuration

This post was last edited by annysky2012 on 2021-10-20 21:59 I haven't updated for a few days. The weather has turned c ...

How to generate bin format files in MDK

In the integrated development environment of Realview MDK , by default, debug files in *.axf format and executable files ...

[Flower carving hands-on] Interesting and fun music visualization series of small projects (19) - full-body fiber optic lamp

I suddenly had the urge to do a series of topics on music visualization. This topic is a bit difficult and covers a wide ...

[Flower carving hands-on] Interesting and fun music visualization series of small projects (22) - LED infinite cube

I suddenly had the urge to do a series of topics on music visualization. This topic is a bit difficult and covers a wide ...

Ebyte E103-W01 module adapter board trial

When I first received the package from Ebyte and opened it, I was confused. There was only the adapter base plate. After ...

What exactly is the problem?

After my graphics card broke last time, I bought a second-hand graphics card (1060 3G), and I also had a graphics card t ...

Are analog electronics such as triodes still used in electronic design today?

I would like to ask all the senior experts, do we still use analog electronic designs such as triodes in electronic desi ...

[Good book reading - "Switching Power Supply Simulation and Design - Based on SPICE"] - 005 BUCK Working Mode

This post was last edited by zyb329321151 on 2024-7-17 22:39 Buck converter ( BUCK ) operating mode discussion In a b ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list