ST AEKD-AICAR1 Скачать руководство пользователя страница 33

Appendix C 

Python script code for the data acquisition and parsing

import serial as sr
import matplotlib.pyplot as plt
import numpy as np
import time
from csv import writer

def append_list_as_row(list_of_elem):
    # Open file in append mode
    with open(file_name, 'a+') as write_obj:
        # Create a writer object from csv module
        csv_writer = writer(write_obj, delimiter=',',lineterminator='\n')
        # Add contents of list as last row in the csv file
        csv_writer.writerow(list_of_elem)
        
def create_file_with_header(list_of_elem):
    # Open file in append mode
    with open(file_name, 'wb') as write_obj:
        # Create a writer object from csv module
        csv_writer = writer(write_obj)
        # Add contents of list as last row in the csv file
        csv_writer.writerow(list_of_elem)

s = sr.Serial('COM31', 38400);

#Write header
named_tuple = time.localtime() # get struct_time
time_string = time.strftime("%m_%d_%Y_%H_%M_%S", named_tuple)
file_name = 'data_logger_' + time_ '.csv'

print('File Created: ' + file_name)
row_contents = ['Time','Acc_x','Acc_y','Acc_z']
create_file_with_header(row_contents)

while 1:
    string_line=s.readline()      #ascii
    string_line = string_line.strip('\n')
    line_as_list = string_line.split(b',')
    time_stamp = float(line_as_list[0])
    acc_x = float(line_as_list[1])
    acc_y = float(line_as_list[2])
    acc_z = float(line_as_list[3])
    row_contents = [time_stamp,acc_x,acc_y,acc_z]
    append_list_as_row(row_contents)

UM3053

Python script code for the data acquisition and parsing

UM3053

 - 

Rev 1

page 33/39

Содержание AEKD-AICAR1

Страница 1: ...ented and trained using the TensorFlow 2 4 0 framework Keras in the Google Colab environment The AI SPC5Studio plug in has been used to convert the resulting trained neural network into an optimized C...

Страница 2: ...ty The bias is the measure of assumption made by the form of the output This architecture is typical for deep learning processes like data classification and pattern recognition neural networks 1 2 Lo...

Страница 3: ...rk able to keep the information received is the long short term memory LSTM recurrent network Unlike traditional artificial neural networks LSTM has feedback connections It can process not only single...

Страница 4: ...ms related to the classification problem A significant amount of computing power is required to implement sufficiently robust and efficient models For initial tests we can rely on a standard machine A...

Страница 5: ...r large multidimensional arrays and matrices along with a large collection of high level mathematical functions to operate on these arrays import numpy as np Tensorflow Open source software library fo...

Страница 6: ...speech recognition system It consists of a neural convolution kernel as an input layer able to elaborate a convolution function with the input vector over a temporal dimension The input vector is a ti...

Страница 7: ...rs define the AI car sensing node network model These parameters are related to the LSTM RNN topology chosen 2 4 2 Model training The AI car sensing node network training has been performed by acquiri...

Страница 8: ...nables the acquisition mode In this mode the application sends each acceleration sample read from the sensor to a serial port with a baud rate set to 38400 The serial data stream can be read through a...

Страница 9: ...hree columns contain the acceleration values measured on the X Y and Z axis respectively without the gravity offset To prepare the file for the network training you have to Compute the acceleration va...

Страница 10: ...eady to use dataset Diff_profile csv has been created to train the network for the car state classification 2 4 2 2 Neural network training with Google Colab Import the training dataset contained in t...

Страница 11: ...ts_diff_Az i cnt 1 Note The cnt variable contains the number of available window waveforms according to the dataset acquired during each specific car status 2 4 3 Model fitting and compilation Firstl...

Страница 12: ...it but faster than the training phase A confusion matrix performs the model accuracy evaluation This is a technique to summarize the algorithm classification performance As the datasets have differen...

Страница 13: ...three have been confused with bumpy Figure 11 Confusion matrix The LSTM RNN accuracy for the AI car sensing node is about 93 The miss classification for the skid state impact the calculated accuracy v...

Страница 14: ...ient ANSI C library to be compiled installed and executed on SPC58 microcontrollers You can easily import pretrained neural networks in the SPC5 STUDIO AI from the most widely used deep learning frame...

Страница 15: ...2 Insert http ai spc5studio com in the Work with field Figure 13 Install new software Step 3 Click on Select all and Next Step 4 Install SPC5 STUDIO AI UM3053 SPC5 STUDIO AI plugin UM3053 Rev 1 page 1...

Страница 16: ...n based on the SPC58ECxx platform Figure 14 Creating a new SPC5 STUDIO application Step 2 Import the following components AutodevKit Init Package SPC58ECxx Init Package Component RLA Step 3 Select SPC...

Страница 17: ...ect SPC5 AI Component RLA Figure 17 Selecting SPC5 AI Component RLA 3 1 2 How to import the pretrained LSTM neural network The following procedure shows how to import the pretrained LSTM neural networ...

Страница 18: ...option Step 4 Configure the parameters for the LSTM AI car sensing node Figure 20 Configuring the parameters Step 4a Enable the network initialization data Step 4b Put a valid neural network name Ste...

Страница 19: ...M neural network To analyze the pretrained LSTM neural network for the AI car sensing node follow the procedure below Step 1 Select Analyze in the Outline tab Figure 21 Selecting Analyze UM3053 SPC5 S...

Страница 20: ...components spc5_ai_component_rla cfg model_name model_car_sts model_hash 10794f1c230799b2a1cda67171827db2 input input_0 150 items 600 B ai_float FLOAT32 50 1 3 inputs total 600 B output dense_1_nl 4...

Страница 21: ...eprocessor on how to configure properly the dimension and allocation of the neural network data structure Table 1 List of defines C language define Description AI_SENSING_NODE_NETWORK_MODEL_NAME A C s...

Страница 22: ...the ai_sensing_node_network_destroy function should be called to release the possible allocated resources ai_sensing_node_network_init ai_bool ai_sensing_init ai_handle network const ai_network_params...

Страница 23: ...AICAR1 uses the AEK MCU C4MLIT1 evaluation board to process discrete acceleration variations acquired from the three axis IMU system in order to run a pretrained neural network Moreover the board dri...

Страница 24: ...follow the procedure below Step 1 Go on SPC58ECxx Platform Component RLA in the project explorer and add a new AEK CON SENSOR1 Component RLA from the list Step 2 Press on the allocation button to mak...

Страница 25: ...el_data PIXFMT_RGB_565 aek_ili9341_drawString AEK_LCD_DEV0 102 160 PARKING color font24pt 4 3 2 High level software This layer includes IMU middleware AI sensing node network middleware LCD display mi...

Страница 26: ...AICAR1 application has three operating working modes Acquisition Real time calculation default Offline calculation 4 3 3 1 Acquisition This working mode is used to perform an LSTM neural network train...

Страница 27: ...s Table 2 Test conditions and results Test condition Number of tests Number of failures Failure percentage Normal road 10 0 0 Bumpy road 10 0 0 Skid normal road 10 2 detected as bumpy road 20 Skid bum...

Страница 28: ...CON SENSOR1 AEK LCD DT028V1 and STEVAL MKI206V1 You can find their detailed schematic diagrams at the related web pages AEK MCU C4MLIT1 schematic diagrams AEK CON SENSOR1 schematic diagrams AEK LCD DT...

Страница 29: ...K CON SENSOR1 AEK LCD DT028V1 and STEVAL MKI206V1 You can find their detailed schematic diagrams at the related web pages AEK MCU C4MLIT1 bill of materials AEK CON SENSOR1 bill of materials AEK LCD DT...

Страница 30: ...the authority of an FCC license holder or must secure an experimental authorization under part 5 of this chapter 3 1 2 Notice for Innovation Science and Economic Development Canada ISED For evaluatio...

Страница 31: ...ame_size x a i i frame_size db_x append x db_y append Y_LABELS label db pd read_csv Diff_profile csv sep print db keys states db Status value_counts scaler MinMaxScaler ts_status db Status ts_diff_Ax...

Страница 32: ...egorical_crossentropy metrics accuracy model fit x_train y_train epochs 1000 model summary import matplotlib pyplot as plt import seaborn as sns matplotlib inline Y_pred model predict x_test y_pred np...

Страница 33: ...csv module csv_writer writer write_obj Add contents of list as last row in the csv file csv_writer writerow list_of_elem s sr Serial COM31 38400 Write header named_tuple time localtime get struct_tim...

Страница 34: ...Revision history Table 3 Document revision history Date Revision Changes 20 Sep 2022 1 Initial release UM3053 UM3053 Rev 1 page 34 39...

Страница 35: ...using the standard importing procedure 16 3 1 2 How to import the pretrained LSTM neural network 17 3 1 3 How to analyze the pretrained LSTM neural network 19 3 2 SPC5 STUDIO AI API 21 4 AI car sensin...

Страница 36: ...Revision history 34 List of tables 37 List of figures 38 UM3053 Contents UM3053 Rev 1 page 36 39...

Страница 37: ...List of tables Table 1 List of defines 21 Table 2 Test conditions and results 27 Table 3 Document revision history 34 UM3053 List of tables UM3053 Rev 1 page 37 39...

Страница 38: ...plete model generation 12 Figure 11 Confusion matrix 13 Figure 12 Installing the plugin 14 Figure 13 Install new software 15 Figure 14 Creating a new SPC5 STUDIO application 16 Figure 15 Selecting the...

Страница 39: ...s and ST assumes no liability for application assistance or the design of purchasers products No license express or implied to any intellectual property right is granted by ST herein Resale of ST prod...

Отзывы: