-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Included additional models compatible with the STM32MP257F-DK2 board. - Added support for per-tensor quantization. - Integrated support for ONNX model quantization and evaluation. - Included support for STEdgeAI (STM32Cube.AI v9.1.0 and subsequent versions). - Expanded use case support to include Pose Estimation and Semantic Segmentation. - Standardized logging information for a unified experience. Signed-off-by: khaoula boutiche <khaoula.boutiche@st.com>
- Loading branch information
Showing
668 changed files
with
58,761 additions
and
21,867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
868 changes: 868 additions & 0 deletions
868
X-LINUX-AI_application_code/image_classification/Application/image_classification.py
Large diffs are not rendered by default.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...I_application_code/image_classification/Application/launch_python_image_classification.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
weston_user=$(ps aux | grep '/usr/bin/weston '|grep -v 'grep'|awk '{print $1}') | ||
DEPLOY_PATH=$1 | ||
MODEL_NAME=$2 | ||
LABELS=$3 | ||
COMPATIBLE=$(cat /proc/device-tree/compatible) | ||
if [[ "$COMPATIBLE" == *"stm32mp2"* ]]; then | ||
cmd="python3 $DEPLOY_PATH/Application/image_classification.py -m $DEPLOY_PATH/$MODEL_NAME -l $DEPLOY_PATH/Resources/$LABELS --framerate 30 --frame_width 640 --frame_height 480" | ||
else | ||
cmd="python3 $DEPLOY_PATH/Application/image_classification.py -m $DEPLOY_PATH/$MODEL_NAME -l $DEPLOY_PATH/Resources/$LABELS --framerate 15 --frame_width 320 --frame_height 240" | ||
fi | ||
|
||
if [ "$weston_user" != "root" ]; then | ||
echo "user : "$weston_user | ||
script -qc "su -l $weston_user -c '$cmd'" | ||
else | ||
$cmd | ||
fi |
98 changes: 98 additions & 0 deletions
98
X-LINUX-AI_application_code/image_classification/Application/mobilenet_v2_pp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/python3 | ||
# | ||
# Copyright (c) 2024 STMicroelectronics. | ||
# All rights reserved. | ||
# | ||
# This software is licensed under terms that can be found in the LICENSE file | ||
# in the root directory of this software component. | ||
# If no LICENSE file comes with this software, it is provided AS-IS. | ||
|
||
from stai_mpu import stai_mpu_network | ||
import numpy as np | ||
|
||
class NeuralNetwork: | ||
""" | ||
Class that handles Neural Network inference | ||
""" | ||
def __init__(self, model_file, label_file, input_mean, input_std): | ||
""" | ||
:param model_path: model to be executed | ||
:param label_file: name of file containing labels | ||
:param input_mean: input_mean | ||
:param input_std: input standard deviation | ||
""" | ||
|
||
def load_labels(filename): | ||
my_labels = [] | ||
input_file = open(filename, 'r') | ||
for l in input_file: | ||
my_labels.append(l.strip()) | ||
return my_labels | ||
|
||
self._model_file = model_file | ||
print("NN model used : ", self._model_file) | ||
self._label_file = label_file | ||
self._input_mean = input_mean | ||
self._input_std = input_std | ||
self._floating_model = False | ||
|
||
# Initialization of network class | ||
self.stai_mpu_model = stai_mpu_network(model_path=self._model_file) | ||
|
||
# Read input tensor information | ||
self.num_inputs = self.stai_mpu_model.get_num_inputs() | ||
self.input_tensor_infos = self.stai_mpu_model.get_input_infos() | ||
|
||
# Read output tensor information | ||
self.num_outputs = self.stai_mpu_model.get_num_outputs() | ||
self.output_tensor_infos = self.stai_mpu_model.get_output_infos() | ||
|
||
self._labels = load_labels(self._label_file) | ||
|
||
def get_labels(self): | ||
""" | ||
:return: list of NN model labels loaded | ||
""" | ||
return self._labels | ||
|
||
def get_img_size(self): | ||
""" | ||
:return: size of NN input image size | ||
""" | ||
# NxHxWxC, H:1, W:2, C:3 | ||
input_tensor_shape = self.input_tensor_infos[0].get_shape() | ||
input_width = input_tensor_shape[1] | ||
input_height = input_tensor_shape[2] | ||
input_channel = input_tensor_shape[0] | ||
print("input_width",input_width) | ||
print("input_height",input_height) | ||
print("input_channel",input_channel) | ||
return (input_width,input_height,input_channel) | ||
|
||
def launch_inference(self, img): | ||
""" | ||
This method launches inference using the invoke call | ||
:param img: the image to be inferred | ||
""" | ||
# add N dim | ||
input_data = np.expand_dims(img, axis=0) | ||
|
||
if self.input_tensor_infos[0].get_dtype() == np.float32: | ||
input_data = (np.float32(input_data) - self._input_mean) / self._input_std | ||
|
||
self.stai_mpu_model.set_input(0, input_data) | ||
self.stai_mpu_model.run() | ||
|
||
def get_results(self): | ||
""" | ||
This method can print and return the top_k results of the inference | ||
""" | ||
output_data = self.stai_mpu_model.get_output(index=0) | ||
results = np.squeeze(output_data) | ||
|
||
top_k = results.argsort()[-5:][::-1] | ||
|
||
if self.output_tensor_infos[0].get_dtype() == np.uint8 : | ||
return (results[top_k[0]]/255, top_k[0]) | ||
else: | ||
return (results[top_k[0]], top_k[0]) |
80 changes: 80 additions & 0 deletions
80
X-LINUX-AI_application_code/image_classification/LICENSE.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
SLA0044 Rev5/February 2018 | ||
|
||
Software license agreement | ||
|
||
ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT | ||
|
||
BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE | ||
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS | ||
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES | ||
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON | ||
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES | ||
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. | ||
|
||
Under STMicroelectronics’ intellectual property rights, the redistribution, | ||
reproduction and use in source and binary forms of the software or any part | ||
thereof, with or without modification, are permitted provided that the following | ||
conditions are met: | ||
|
||
1. Redistribution of source code (modified or not) must retain any copyright | ||
notice, this list of conditions and the disclaimer set forth below as items 10 | ||
and 11. | ||
|
||
2. Redistributions in binary form, except as embedded into microcontroller or | ||
microprocessor device manufactured by or for STMicroelectronics or a software | ||
update for such device, must reproduce any copyright notice provided with the | ||
binary code, this list of conditions, and the disclaimer set forth below as | ||
items 10 and 11, in documentation and/or other materials provided with the | ||
distribution. | ||
|
||
3. Neither the name of STMicroelectronics nor the names of other contributors to | ||
this software may be used to endorse or promote products derived from this | ||
software or part thereof without specific written permission. | ||
|
||
4. This software or any part thereof, including modifications and/or derivative | ||
works of this software, must be used and execute solely and exclusively on or in | ||
combination with a microcontroller or microprocessor device manufactured by or | ||
for STMicroelectronics. | ||
|
||
5. No use, reproduction or redistribution of this software partially or totally | ||
may be done in any manner that would subject this software to any Open Source | ||
Terms. “Open Source Terms” shall mean any open source license which requires as | ||
part of distribution of software that the source code of such software is | ||
distributed therewith or otherwise made available, or open source license that | ||
substantially complies with the Open Source definition specified at | ||
www.opensource.org and any other comparable open source license such as for | ||
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache | ||
Software License, BSD license or MIT license. | ||
|
||
6. STMicroelectronics has no obligation to provide any maintenance, support or | ||
updates for the software. | ||
|
||
7. The software is and will remain the exclusive property of STMicroelectronics | ||
and its licensors. The recipient will not take any action that jeopardizes | ||
STMicroelectronics and its licensors' proprietary rights or acquire any rights | ||
in the software, except the limited rights specified hereunder. | ||
|
||
8. The recipient shall comply with all applicable laws and regulations affecting | ||
the use of the software or any part thereof including any applicable export | ||
control law or regulation. | ||
|
||
9. Redistribution and use of this software or any part thereof other than as | ||
permitted under this license is void and will automatically terminate your | ||
rights under this license. | ||
|
||
10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE | ||
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL | ||
STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER | ||
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY | ||
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# __Image classification Getting Started package__ | ||
|
||
The respective README of each board can be found in the `<STM32_Serie_Name>` folder. The boards currently supported are the following ones: | ||
|
||
- [STM32MP1X](./STM32MP1/README.md) | ||
- [STM32MP2X](./STM32MP2/README.md) |
45 changes: 45 additions & 0 deletions
45
X-LINUX-AI_application_code/image_classification/Resources/Default.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
window { | ||
background-color: #000000; | ||
} | ||
|
||
window#overlay_window { | ||
background-color: transparent; | ||
} | ||
|
||
widget { | ||
background-color: transparent; | ||
} | ||
|
||
box#gui_main_stbox { | ||
background-color: #000000; | ||
color: #FFFFFF; | ||
} | ||
|
||
box#gui_overlay_stbox { | ||
background-color: #000000; | ||
color: #FFFFFF; | ||
} | ||
|
||
box#gui_main_video { | ||
background-color: #000000; | ||
} | ||
|
||
box#gui_overlay_video { | ||
background-color: transparent; | ||
} | ||
|
||
box#gui_main_exit { | ||
background-color: #000000; | ||
} | ||
|
||
box#gui_overlay_exit { | ||
background-color: transparent; | ||
} | ||
|
||
box#gui_main { | ||
background-color: #000000; | ||
} | ||
|
||
drawing_area#overlay_draw { | ||
background-color: transparent; | ||
} |
Binary file added
BIN
+4.03 KB
X-LINUX-AI_application_code/image_classification/Resources/IC_st_icon_120px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.46 KB
X-LINUX-AI_application_code/image_classification/Resources/IC_st_icon_160px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.56 KB
X-LINUX-AI_application_code/image_classification/Resources/IC_st_icon_52px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.55 KB
X-LINUX-AI_application_code/image_classification/Resources/IC_st_icon_80px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.63 KB
...ication_code/image_classification/Resources/IC_st_icon_next_inference_120px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.34 KB
...ication_code/image_classification/Resources/IC_st_icon_next_inference_160px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.76 KB
...lication_code/image_classification/Resources/IC_st_icon_next_inference_52px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.95 KB
...lication_code/image_classification/Resources/IC_st_icon_next_inference_80px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+259 Bytes
X-LINUX-AI_application_code/image_classification/Resources/exit_25x25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+346 Bytes
X-LINUX-AI_application_code/image_classification/Resources/exit_50x50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.