Registered User mNo edit summary |
Registered User (Merge articles) |
||
(12 intermediate revisions by 3 users not shown) | |||
Line 5: | Line 5: | ||
<noinclude></noinclude> | <noinclude></noinclude> | ||
==Developer package : build AI application from the X-LINUX-AI add-on SDK== | ==Developer package: build AI application from the X-LINUX-AI add-on SDK== | ||
In order to {{Highlight|easily develop and build an AI application}} without using the Yocto build system, X-LINUX-AI comes with a {{Highlight|SDK add-on}} extending the OpenSTLinux SDK with {{Highlight|AI functionality}}. To install and use the X-LINUX-AI SDK Add-on please refer to the following steps. | In order to {{Highlight|easily develop and build an AI application}} without using the Yocto build system, X-LINUX-AI comes with a {{Highlight|SDK add-on}} extending the OpenSTLinux SDK with {{Highlight|AI functionality}}. To install and use the X-LINUX-AI SDK Add-on please refer to the following steps. | ||
==Prerequisites== | ==Prerequisites== | ||
=== Install the OpenSTLinux SDK === | === Install the OpenSTLinux SDK === | ||
First of all, you must download and install the '''OpenSTLinux SDK''', which contains all the basis needed for the '''X-LINUX-AI add-on'''. To do this, follow instructions given in [[STM32MPU_Developer_Package#Installing_the_SDK | | First of all, you must download and install the '''OpenSTLinux SDK''', which contains all the basis needed for the '''X-LINUX-AI add-on'''. | ||
To do this, follow instructions given in [[STM32MPU_Developer_Package#Installing_the_SDK | STM32MPU Developer Package: Installing the SDK]] chapter. Once this has been done, you should have a directory containing the OpenSTLinux SDK. | |||
{{info| Once this is done, if you have follow [[Example_of_directory_structure_for_Packages | the | {{info| Once this is done, if you have follow [[Example_of_directory_structure_for_Packages | the example of directory structure]] the path to the '''OpenSTLinux SDK''' should be the following: | ||
:: ''' | :: '''<working directory absolute path>/Developer-Package/SDK'''}} | ||
== X-LINUX-AI SDK add-on installation == | == X-LINUX-AI SDK add-on installation == | ||
=== Download the X-LINUX-AI SDK add-on === | === Download the X-LINUX-AI SDK add-on === | ||
To add the '''Artificial Intelligence''' part into the OpenSTLinux SDK, you must download and install the '''X-LINUX-AI SDK add-on'''. | To add the '''Artificial Intelligence''' part into the OpenSTLinux SDK, you must download and install the '''X-LINUX-AI SDK add-on'''. | ||
The add-on is delivered through a tarball file that can be downloaded here: | The add-on is delivered through a tarball file that can be downloaded here: [https://www.st.com/en/product/x-linux-ai X-LINUX-AI SDK add-on]. | ||
{{warning| The '''X-LINUX-AI SDK add-on''' version and the '''STM32MPU board''' must be the same as the '''OpenSTLinux SDK'''. If either the version are not aligned or the board is different, it might not work correctly.}} | |||
{{ | === Install the X-LINUX-AI SDK add-on === | ||
'''Host PC package prerequisites''' | |||
To be able to properly install the X-LINUX-AI SDK add-on on your host computer it is necessary to install the extra | |||
package patchelf using the following command (in addition of packages from [[PC_prerequisites]]): | |||
{{PC$}}sudo apt-get install patchelf | |||
<div class="mw-collapsible mw-collapsed"> | |||
'''Install add-on for {{MicroprocessorDevice | device=1}}''' | |||
<div class="mw-collapsible-content"> | |||
Once the X-LINUX-AI SDK add-on is downloaded, '''uncompress''' the add-on: | |||
{{info| The name of the tarball depends on the chosen version. In the example below the last uploaded version is used.}} | |||
{{PC$}}cd ~/Downloads/ | |||
{{PC$}}tar xzf {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP1 | package=AI SDK package | request=name}} | |||
Then, '''copy''' the .sh script to your '''OpenSTLinux SDK directory''': | |||
{{PC$}}cp {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP1 | package=AI SDK installation script | request=path}}/{{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP1 | package=AI SDK installation script | request=name}} <working directory absolute path>/Developer-Package/SDK | |||
{{warning| It is mandatory run the script '''inside the OpenSTLinux SDK directory.'''}} | |||
Finally, run the script contained in the tarball: | |||
{{PC$}}cd <working directory absolute path>/Developer-Package/SDK | |||
{{PC$}}./{{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP1 | package=AI SDK installation script | request=name}} | |||
Optionally, once the script is executed, you can delete it. | |||
{{PC$}}rm *.sh | |||
</div></div> | |||
= | <div class="mw-collapsible mw-collapsed"> | ||
'''Install add-on for {{MicroprocessorDevice | device=25}}''' | |||
<div class="mw-collapsible-content"> | |||
Once the X-LINUX-AI SDK add-on is downloaded, '''uncompress''' the add-on: | Once the X-LINUX-AI SDK add-on is downloaded, '''uncompress''' the add-on: | ||
{{info| The name of the tarball depends on the chosen version. In the example below the last uploaded version is used.}} | {{info| The name of the tarball depends on the chosen version. In the example below the last uploaded version is used.}} | ||
{{PC$}} cd ~/Downloads/ | {{PC$}}cd ~/Downloads/ | ||
{{PC$}} tar xzf {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | package=AI SDK package | request=name}} | {{PC$}}tar xzf {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP2 | package=AI SDK package | request=name}} | ||
Then, '''copy''' the .sh script to your '''OpenSTLinux SDK directory''': | Then, '''copy''' the .sh script to your '''OpenSTLinux SDK directory''': | ||
{{PC$}} cp {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | package=AI SDK installation script | request=path}}/{{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | package=AI SDK installation script | request=name}} | {{PC$}}cp {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP2 | package=AI SDK installation script | request=path}}/{{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP2 | package=AI SDK installation script | request=name}} <working directory absolute path>/Developer-Package/SDK | ||
{{warning| It is mandatory run the script '''inside the OpenSTLinux SDK directory.'''}} | {{warning| It is mandatory run the script '''inside the OpenSTLinux SDK directory.'''}} | ||
Finally, run the script contained in the tarball: | Finally, run the script contained in the tarball: | ||
{{PC$}} cd | {{PC$}}cd <working directory absolute path>/Developer-Package/SDK | ||
{{PC$}} ./{{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | package=AI SDK installation script | request=name}} | {{PC$}}./{{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP2 | package=AI SDK installation script | request=name}} | ||
Optionally, once the script is executed, you can delete it. | Optionally, once the script is executed, you can delete it. | ||
{{PC$}} rm *.sh | {{PC$}}rm *.sh | ||
</div></div> | |||
=== Start the SDK === | === Start the SDK === | ||
{{info| The SDK environment setup script must be run once on each new working terminal on which you cross-compile.}} | {{info| The SDK environment setup script must be run once on each new working terminal on which you cross-compile.}} | ||
The add-on is now installed into the OpenSTLinux SDK. You can '''start''' the SDK. Go to your '''OpenSTLinux SDK directory''' and '''source''' the environment: | The add-on is now installed into the OpenSTLinux SDK. You can '''start''' the SDK. Go to your '''OpenSTLinux SDK directory''' and '''source''' the environment: | ||
{{PC$}} cd | {{PC$}}cd <working directory absolute path>/Developer-Package/SDK | ||
{{PC$}} source {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | package=AI SDK setup script | request=name}} | |||
* On '''{{Board | type=MP2}}''': | |||
{{PC$}}source {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP2 | package=AI SDK setup script | request=name}} | |||
{{PC$}}export SYSROOT="<working directory absolute path>/Developer-Package/SDK/sysroots/cortexa35-ostl-linux" | |||
* On '''{{Board | type=MP1}}''': | |||
{{PC$}}source {{X-LINUXRelease/Package | version={{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | device=MP1 | package=AI SDK setup script | request=name}} | |||
{{PC$}}export SYSROOT="<working directory absolute path>/Developer-Package/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi" | |||
Check that the SDK is properly installed: | Check that the SDK is properly installed: | ||
{{PC$}} x-linux-ai -v | {{PC$}}x-linux-ai -v | ||
X-LINUX-AI version: {{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | X-LINUX-AI version: {{X-LINUXRelease/Revision | revision=latest | name=AI | type=release}} | ||
{{info| With the x-linux-ai binary it is possible to check the X-LINUX-AI version and the supported frameworks/applications. Use x-linux-ai --help for more information.}} | {{info| With the x-linux-ai binary it is possible to check the X-LINUX-AI version and the supported frameworks/applications. Use x-linux-ai --help for more information.}} | ||
Line 55: | Line 89: | ||
Download the github repository: | Download the github repository: | ||
{{PC$}} git clone https://github.com/ | {{PC$}}git clone https://github.com/STMicroelectronics/meta-st-x-linux-ai | ||
{{warning| | |||
{{warning| Be careful to select a '''tag''' (for example v5.1.0) in the meta-x-linux-ai GitHub which is aligned with the '''X-LINUX-AI SDK add-on''' version used.}} | |||
Go to the image classification directory: | Go to the image classification directory: | ||
{{PC$}} cd meta-st-x-linux-ai/recipes-samples/image-classification/ | {{PC$}}cd meta-st-x-linux-ai/recipes-samples/image-classification/files/stai-mpu | ||
<div class="mw-collapsible mw-collapsed"> | |||
[Optional] Modify the application before compiling it. Add for example the following piece of code at the beginning of the main function: | |||
<div class="mw-collapsible-content"> | |||
Open the source code using ''vi'' or other code editor: | |||
{{PC$}}vi stai_mpu_image_classification.cc | |||
Add a print function: | |||
<pre> | |||
g_print("Application modified using OSTL SDK + X-LINUX-AI add-on \n"); | |||
</pre> | |||
</div> | |||
</div> | |||
Then, use the '''make''' command to build the application: | Then, use the '''make''' command to build the application: | ||
{{PC$}} make | {{PC$}}make | ||
A new file is displayed, named '''stai_mpu_image_classification'''. This is a binary file, which has been generated using the '''make''' command. It is compiled for the architecture of the board corresponding to the chosen SDK. It must now be transferred to the board. | |||
=== Use the application === | === Use the application === | ||
{{warning| To use the application, it is '''mandatory''' to have an | {{warning| To use the application, it is '''mandatory''' to have an STM32MPU board with '''OpenSTLinux and X-LINUX-AI packages''' installed. If it is not the case, refer to the [[X-LINUX-AI_OpenSTLinux_Expansion_Package| X-LINUX-AI installation guide]].}} | ||
Once the | Once the board is correctly set up and the X-LINUX-AI packages are installed with the right version, it is possible to send the application to the board. | ||
{{info| The '''X-LINUX-AI packages versions''' must be the '''same''' as the ones in the '''X-LINUX-AI SDK add-on'''.}} | {{info| The '''X-LINUX-AI packages versions''' must be the '''same''' as the ones in the '''X-LINUX-AI SDK add-on'''.}} | ||
To do it, use the following command using your own IP address: | To do it, use the following command using your own IP address: | ||
{{PC$}} scp -r -p | {{PC$}}scp -r -p stai_mpu_image_classification root@<ip_address>:/usr/local/x-linux-ai/image-classification/ | ||
Then, use the '''ssh protocol''' to connect to the board: | Then, use the '''ssh protocol''' to connect to the board: | ||
{{PC$}} ssh root@<ip_address> | {{PC$}}ssh root@<ip_address> | ||
On the '''board''', go to the right directory and '''use the image classification script''' to launch the application: | On the '''board''', go to the right directory and '''use the image classification script''' to launch the application: | ||
{{Board$}} cd /usr/local/ | {{Board$}}cd /usr/local/x-linux-ai/image-classification/ | ||
{{Board$}} ./launch_bin_image_classification.sh | {{Board$}}./launch_bin_image_classification.sh | ||
This script is using the ''' | |||
This script is using the '''stai_mpu_image_classification''' application that has been compiled before. | |||
<div class="mw-collapsible mw-collapsed"> | |||
[Optional] If in the previous part you have added the print in the main function, it should be visible in | |||
the logs of the application: | |||
<div class="mw-collapsible-content"> | |||
<pre> | |||
root@stm32mp2:/usr/local/x-linux-ai/image-classification# ./launch_bin_image_cla | |||
ssification.sh | |||
stai wrapper used : | |||
machine used = stm32mp257f-ev1st | |||
user : weston | |||
Application modified using OSTL SDK + X-LINUX-AI add-on | |||
model file set to: /usr/local/x-linux-ai/image-classification/models/mobilenet/mobilenet_v2_1.0_224_int8_per_tensor.nb | |||
label file set to: /usr/local/x-linux-ai/image-classification/models/mobilenet/labels_imagenet_2012.txt | |||
camera framerate set to: 30 | |||
camera frame width set to: 760 | |||
camera frame height set to: 568 | |||
dual DCMIPP camera pipeline mode enabled | |||
2 cpu core(s) available | |||
Loading dynamically: /usr/lib/libstai_mpu_ovx.so.5 | |||
m_num_inputs 1 | |||
m_num_outputs 1 | |||
m_input_height 224 | |||
m_input_width 224 | |||
m_input_channels 3 | |||
m_sizeInBytes 150528 | |||
check if a CSI or USB camera is connected | |||
/home/weston | |||
dcmipp found | |||
display resolution is : 1024 x 600 | |||
Display config <= 600p | |||
video source used : /dev/video2 | |||
camera pipeline configuration : video/x-raw, format=RGB16, width=760, height=568, framerate=30/1,framerate=30/1 | |||
nn source used : /dev/video1 | |||
nn pipeline configuration : video/x-raw, format=RGB, width=224, height=224, framerate=30/1 | |||
</pre> | |||
</div> | |||
</div> | |||
Latest revision as of 18:43, 22 October 2024
1. Developer package: build AI application from the X-LINUX-AI add-on SDK[edit | edit source]
In order to easily develop and build an AI application without using the Yocto build system, X-LINUX-AI comes with a SDK add-on extending the OpenSTLinux SDK with AI functionality. To install and use the X-LINUX-AI SDK Add-on please refer to the following steps.
2. Prerequisites[edit | edit source]
2.1. Install the OpenSTLinux SDK[edit | edit source]
First of all, you must download and install the OpenSTLinux SDK, which contains all the basis needed for the X-LINUX-AI add-on. To do this, follow instructions given in STM32MPU Developer Package: Installing the SDK chapter. Once this has been done, you should have a directory containing the OpenSTLinux SDK.
3. X-LINUX-AI SDK add-on installation[edit | edit source]
3.1. Download the X-LINUX-AI SDK add-on[edit | edit source]
To add the Artificial Intelligence part into the OpenSTLinux SDK, you must download and install the X-LINUX-AI SDK add-on. The add-on is delivered through a tarball file that can be downloaded here: X-LINUX-AI SDK add-on.
3.2. Install the X-LINUX-AI SDK add-on[edit | edit source]
Host PC package prerequisites
To be able to properly install the X-LINUX-AI SDK add-on on your host computer it is necessary to install the extra package patchelf using the following command (in addition of packages from PC_prerequisites):
sudo apt-get install patchelf
Install add-on for STM32MP1 series
3.3. Start the SDK[edit | edit source]
The add-on is now installed into the OpenSTLinux SDK. You can start the SDK. Go to your OpenSTLinux SDK directory and source the environment:
SDKcd <working directory absolute path>/Developer-Package/
SDK/sysroots/cortexa35-ostl-linux"source environment-setup-cortexa35-ostl-linux export SYSROOT="<working directory absolute path>/Developer-Package/
SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi"source environment-setup-cortexa35-ostl-linux export SYSROOT="<working directory absolute path>/Developer-Package/
Check that the SDK is properly installed:
AI version: STM32MP25-betax-linux-ai -v X-LINUX-
4. Use the SDK[edit | edit source]
4.1. Build an application with the SDK[edit | edit source]
Once the SDK is correctly set up, the applications can be built easily. In this example, it is the image classification application that is built.
Download the github repository:
https://github.com/STMicroelectronics/meta-st-x-linux-aigit clone
Go to the image classification directory:
cd meta-st-x-linux-ai/recipes-samples/image-classification/files/stai-mpu
[Optional] Modify the application before compiling it. Add for example the following piece of code at the beginning of the main function:
Then, use the make command to build the application:
make
A new file is displayed, named stai_mpu_image_classification. This is a binary file, which has been generated using the make command. It is compiled for the architecture of the board corresponding to the chosen SDK. It must now be transferred to the board.
4.2. Use the application[edit | edit source]
Once the board is correctly set up and the X-LINUX-AI packages are installed with the right version, it is possible to send the application to the board.
To do it, use the following command using your own IP address:
scp -r -p stai_mpu_image_classification root@<ip_address>:/usr/local/x-linux-ai/image-classification/
Then, use the ssh protocol to connect to the board:
ssh root@<ip_address>
On the board, go to the right directory and use the image classification script to launch the application:
cd /usr/local/x-linux-ai/image-classification/
./launch_bin_image_classification.sh
This script is using the stai_mpu_image_classification application that has been compiled before.
[Optional] If in the previous part you have added the print in the main function, it should be visible in the logs of the application: