你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32CubeIDE开发之人工智能开发经验分享(二)

[复制链接]
攻城狮Melo 发布时间:2023-4-3 21:17
一、事有蹊跷
        接篇一,前面提到在使用cube.AI生成的c语言神经网络模型API调用时,输入数据数量是24,输出数据数量是4,但上文设想采集了三轴加速度传感器的x/y/z三个各数据,按Jogging(慢跑),Walking(走了)两种态势采集了两组数据.csv,那么在实际中应该是输入数据数量是3(x/y/x-value),输出数据数量是2(Jogging,Walking两种类别)。

        由于模型API是cube.AI基于训练输出的神经网络模型而生成的,想必应该是训练神经网络模型时参数设置问题,因此我们重新回顾HAR训练项目.

        进入“STM32CubeFunctionPack_SENSING1_V4.0.3\Utilities\AI_Ressources\Training Scripts\HAR”目录,运行 python .\RunMe.py -h命令,查看参数设置指令帮助,可以看到--seqLength和--stepSize参数设置都和input有关,默认数值是24,就可以笃定在API中调用时,输入数据数量是24就来自于此。
  1. PS D:\tools\arm_tool\STM32CubeIDE\STM32CubeFunctionPack_SENSING1_V4.0.3\Utilities\AI_Ressources\Training Scripts\HAR> python3 .\RunMe.py -h
  2. Using TensorFlow backend.
  3. usage: RunMe.py [-h] [--model MODEL] [--dataset DATASET] [--dataDir DATADIR]
  4.                 [--seqLength SEQLENGTH] [--stepSize STEPSIZE] [-m MERGE]
  5.                 [--preprocessing PREPROCESSING] [--trainSplit TRAINSPLIT]
  6.                 [--validSplit VALIDSPLIT] [--epochs N] [--lr LR]
  7.                 [--decay DECAY] [--batchSize N] [--verbose N]
  8.                 [--nrSamplesPostValid NRSAMPLESPOSTVALID]

  9. Human Activity Recognition (HAR) in Keras with Tensorflow as backend on WISDM
  10. and WISDM + self logged datasets

  11. optional arguments:
  12.   -h, --help            show this help message and exit
  13.   --model MODEL         choose one of the two availavle choices, IGN or GMP, (
  14.                         default = IGN )
  15.   --dataset DATASET     choose a dataset to use out of two choices, WISDM or
  16.                         AST, ( default = WISDM )
  17.   --dataDir DATADIR     path to new data collected using STM32 IoT board
  18.                         recorded at 26Hz as sampling rate, (default = )
  19.   --seqLength SEQLENGTH
  20.                         input sequence lenght (default:24)
  21.   --stepSize STEPSIZE   step size while creating segments (default:24, equal
  22.                         to seqLen)
  23.   -m MERGE, --merge MERGE
  24.                         if to merge activities (default: True)
  25.   --preprocessing PREPROCESSING
  26.                         gravity rotation filter application (default = True)
  27.   --trainSplit TRAINSPLIT
  28.                         train and test split (default = 0.6 (60 precent for
  29.                         train and 40 precent for test))
  30.   --validSplit VALIDSPLIT
  31.                         train and validation data split (default = 0.7 (70
  32.                         percent for train and 30 precent for validation))
  33.   --epochs N            number of total epochs to run (default: 20)
  34.   --lr LR               initial learning rate
  35.   --decay DECAY         decay in learning rate, (default = 1e-6)
  36.   --batchSize N         mini-batch size (default: 64)
  37.   --verbose N           verbosity of training and test functions in keras, 0,
  38.                         1, or 2. Verbosity mode. 0 = silent, 1 = progress bar,
  39.                         2 = one line per epoch (default: 1)
  40.   --nrSamplesPostValid NRSAMPLESPOSTVALID
  41.                         Number of samples to save from every class for post
  42.                         training and CubeAI conversion validation. (default =
  43.                         2)
  44. PS D:\tools\arm_tool\STM32CubeIDE\STM32CubeFunctionPack_SENSING1_V4.0.3\Utilities\AI_Ressources\Training Scripts\HAR>
复制代码

        而输出数据数量是4的原因追踪源码可以看到,来自于PrepareDataset.py(数据集预处理源文件),由于在参数--dataset默认设置是WISDM,因此分类输出即为'Jogging', 'Stationary', 'Stairs', 'Walking',即输出数据数量为4:

163907f82e4e4cccaf84449c88b1fcb4.png

         下面来深入了解HAR(Human Activity Recognition,人类行为识别)案例为何会有这样的设置。

二、HAR训练项目分析

        由于前文仅仅采集Jogging(慢跑),Walking(走了)两种态势数据,但通常Stationary(站立不动)态势更常见和默认姿态,因此本文按篇一方法再采集一组Stationary姿态日志数据。

af3f5c1d0dfe49f69188bd388b5c733b.png

         并同样拷贝到HAR/Log_data目录下,数据如下:

975e0b52a36945208f090c7b8c79876f.png

         在PrepareDataset.py文件中,read_dataset( self )和preprocess_data( self, data )是用来处理WISDM数据集的,而get_data_from_file( self, fileName, preparedDataFileName )和prepare_self_logged_data( self )函数是用来处理自行采集数据集的。

3c78db85806c4ae3ac309fecbfdf4ac7.png

         read_dataset会读取WISDM数据集的datasets/WISDM_ar_v1.1_raw.txt文件

2bbc81dd08fa4192b299d97348598c5c.png

         这些数据是已经做了转换预处理的数据集,见下图红线标注部分。

93e254ece5c54b218d605ab8a3f982f3.png

         而get_data_from_file( self, fileName, preparedDataFileName )函数读取自行采集数据集(.csv)文件时,做了转换预处理,确保和WISDM数据集一致。

27a188cfc82c4463b09eef1ea4703615.png

         同时项目还把预处理过的自行采集数据集与训练好的模型一并以csv格式输出到目录中,以源数据目录命名,例如Log_data.csv。

2297ca3ae2834a0db351151c4793a70a.png

         下来就是输入数据数量问题,由于在FP-AI-SENSING1案例项目,数据采集是按一定时间间隔连续实时采集的,采集间隔也很短(毫秒级别)

8df251f25daa43889588959c5d1421ea.png

         因此get_segment_indices和get_data_segments函数就是将采集到的连续数据处理成一个长度为seqLength的窗口的输入数据集,即每次输入数据是一段24组(一组3个数据值,x/y/z)数据,也就对应了我们前文定义输入数据缓存是static ai_float in_data[AI_HAR_IGN_IN_1_SIZE=24*3*1];,共72个float 数据。显然HAR项目做法是通过一组连续数据集作为输入比单个态势数据更能反应人类行为姿态的持续性,更贴近实际。

c7b715fbe27b430da7010987fac0f202.png

         在read_dataset函数加入打印读取的WISDM数据集语句。

b677e960540e4885bddecc211dd044c5.png

         在prepare_self_logged_data函数加入打印读取自行采集数据集语句

2a5c56979502499d8d82202650307bc5.png

         因为打印输出依据后,后续会打印数据按输入数据长度来分段的信息,暂时保持seqLength和stepSize为默认的24数值,运行python3 .\RunMe.py --dataDir=Log_data命令:
  1. PS D:\tools\arm_tool\STM32CubeIDE\STM32CubeFunctionPack_SENSING1_V4.0.3\Utilities\AI_Ressources\Training Scripts\HAR> python3 .\RunMe.py --dataDir=Log_data
  2. Using TensorFlow backend.
  3. Running HAR on WISDM dataset, with following variables
  4. merge = True
  5. modelName = IGN,
  6. segmentLength = 24
  7. stepSize = 24
  8. preprocessing = True
  9. trainTestSplit = 0.6
  10. trainValidationSplit = 0.7
  11. nEpochs = 20
  12. learningRate = 0.0005
  13. decay =1e-06
  14. batchSize = 64
  15. verbosity = 1
  16. dataDir = Log_data
  17. nrSamplesPostValid = 2
  18.          User Activity_Label     Arrival_Time         x          y             z
  19. 0          33        Jogging   49105962326000 -0.694638  12.680544   0.50395286;
  20. 1          33        Jogging   49106062271000  5.012288  11.264028   0.95342433;
  21. 2          33        Jogging   49106112167000  4.903325  10.882658  -0.08172209;
  22. 3          33        Jogging   49106222305000 -0.612916  18.496431    3.0237172;
  23. 4          33        Jogging   49106332290000 -1.184970  12.108489     7.205164;
  24. ...       ...            ...              ...       ...        ...           ...
  25. 1098199    19        Sitting  131623331483000  9.000000  -1.570000         1.69;
  26. 1098200    19        Sitting  131623371431000  9.040000  -1.460000         1.73;
  27. 1098201    19        Sitting  131623411592000  9.080000  -1.380000         1.69;
  28. 1098202    19        Sitting  131623491487000  9.000000  -1.460000         1.73;
  29. 1098203    19        Sitting  131623531465000  8.880000  -1.330000         1.61;

  30. [1098204 rows x 6 columns]
  31. Segmenting Train data
  32. Segments built : 100%|███████████████████████████████████████████████████| 27456/27456 [00:28<00:00, 954.67 segments/s]
  33. Segmenting Test data
  34. Segments built : 100%|██████████████████████████████████████████████████| 18304/18304 [00:14<00:00, 1298.22 segments/s]
  35. Segmentation finished!
  36. preparing data file from all the files in directory  Log_data
  37. parsing data from  IoT01-MemsAnn_11_Jan_23_16h_57m_17s.csv
  38. parsing data from  IoT01-MemsAnn_11_Jan_23_16h_57m_53s.csv
  39. parsing data from  IoT01-MemsAnn_26_Jan_23_15h_51m_01s.csv
  40.              x         y         z Activity_Label
  41. 0    -1.965414 -0.143890  9.367359        Walking
  42. 1    -1.629783  0.664754  9.618931        Walking
  43. 2    -1.720833  0.384629  9.492079        Walking
  44. 3    -1.681419  0.534637  9.648173        Walking
  45. 4    -1.729849  0.421650  9.557259        Walking
  46. ...        ...       ...       ...            ...
  47. 2639 -1.171046  0.033572  9.746819     Stationary
  48. 2640 -1.212873  0.007256  9.759376     Stationary
  49. 2641 -1.212011  0.019485  9.753982     Stationary
  50. 2642 -1.172311 -0.004511  9.734770     Stationary
  51. 2643 -1.175431  0.035787  9.753447     Stationary

  52. [2644 rows x 4 columns]
  53. Segmenting the AI logged Train data
  54. Segments built : 100%|████████████████████████████████████████████████████████| 67/67 [00:00<00:00, 2795.31 segments/s]
  55. Segmenting the AI logged Test data
  56. Segments built : 100%|████████████████████████████████████████████████████████| 45/45 [00:00<00:00, 2370.94 segments/s]
  57. Segmentation finished!
  58. _________________________________________________________________
  59. Layer (type)                 Output Shape              Param #
  60. =================================================================
  61. conv2d_1 (Conv2D)            (None, 9, 3, 24)          408
  62. _________________________________________________________________
  63. max_pooling2d_1 (MaxPooling2 (None, 3, 3, 24)          0
  64. _________________________________________________________________
  65. flatten_1 (Flatten)          (None, 216)               0
  66. _________________________________________________________________
  67. dense_1 (Dense)              (None, 12)                2604
  68. _________________________________________________________________
  69. dropout_1 (Dropout)          (None, 12)                0
  70. _________________________________________________________________
  71. dense_2 (Dense)              (None, 4)                 52
  72. =================================================================
  73. Total params: 3,064
  74. Trainable params: 3,064
  75. Non-trainable params: 0
  76. _________________________________________________________________
  77. Train on 19288 samples, validate on 8233 samples
  78. Epoch 1/20
  79. 2023-01-26 17:12:56.882726: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
  80. 19288/19288 [==============================] - 1s 54us/step - loss: 1.2022 - acc: 0.5290 - val_loss: 0.7089 - val_acc: 0.7409
  81. Epoch 2/20
  82. 19288/19288 [==============================] - 1s 41us/step - loss: 0.7520 - acc: 0.7017 - val_loss: 0.5342 - val_acc: 0.7985
  83. Epoch 3/20
  84. 19288/19288 [==============================] - 1s 41us/step - loss: 0.6079 - acc: 0.7571 - val_loss: 0.4573 - val_acc: 0.8153
  85. Epoch 4/20
  86. ... ...
  87. 19288/19288 [==============================] - 1s 39us/step - loss: 0.3306 - acc: 0.8899 - val_loss: 0.2669 - val_acc: 0.9113
  88. Epoch 20/20
  89. 19288/19288 [==============================] - 1s 40us/step - loss: 0.3194 - acc: 0.8913 - val_loss: 0.2646 - val_acc: 0.9168
  90. 12831/12831 [==============================] - 0s 22us/step
  91. Accuracy for each class is given below.
  92. Jogging     : 97.51 %
  93. Stationary  : 98.63 %
  94. Stairs      : 70.94 %
  95. Walking     : 81.55 %
  96. PS D:\tools\arm_tool\STM32CubeIDE\STM32CubeFunctionPack_SENSING1_V4.0.3\Utilities\AI_Ressources\Training Scripts\HAR>
复制代码

        读取到的WISDM数据集大小是1098204≈24*(27456+18304),而27456+18304是按--trainSplit参数默认值0.6:0.4比例切分的。读取到的自行采集数据大小是2644≈24*(67+45)。

933a16cdb7aa4062afb9f21d26c45cc9.png

三、工程调整

        从前面分析来看,输入数据数量还是采用默认数值24问题不大(各位粉丝可以自行调整其大小来测试及观察效果),输出数据数量由于有WISDM数据集参与,保持'Jogging', 'Stationary', 'Stairs', 'Walking'是中分类也OK。现注意到,其实输入数据是经过了预处理转换实际加速度值,而非是传感器原始输出数值。

        由于自行采集数据增加了Stationary数据文件,因此在cubeMX上采用新的训练模型文件重新生成c语言的神经网络模型。

c6bd1db4b2ce417d945ae484e94c7731.png

         然后调整输入数据及预处理函数acquire_and_process_data,采用真实数据来测试

3678b3c605654ed3adc7a2f2954df630.png

         该函数有原来的随机赋值,
  1. int acquire_and_process_data(void *in_data,int factor)
  2. {
  3.         printf("in_data:");
  4.         for (int i=0; i<AI_HAR_IGN_IN_1_SIZE; i++)
  5.         {
  6.                 switch(i%3){
  7.                 case 0:
  8.                         ((ai_float*)in_data)[i] = -175+(ai_float)(i*factor*1.2)/10.0;
  9.                         break;
  10.                 case 1:
  11.                         ((ai_float*)in_data)[i] = 50+(ai_float)(i*factor*0.6)/100.0;
  12.                         break;
  13.                 case 2:
  14.                         ((ai_float*)in_data)[i] = 975-(ai_float)(i*factor*1.8)/100.0;
  15.                         break;
  16.                 default:
  17.                         break;
  18.                 }
  19.                 printf("%.4f ",((ai_float*)in_data)[i]);
  20.         }
  21.         printf("\n");

  22.         return 0;
  23. }
复制代码

        调整为
  1. ai_float in_buf[] =
  2. {
  3.                 -1.9654135467252831,-0.14388957575400915,9.36735860765576,
  4.                 -1.6297827960727935,0.6647544204312931,9.618930851170278,
  5.                 -1.7208332169161387,0.38462856310059845,9.492079217583663,
  6.                 -1.6814190066807724,0.5346365723749872,9.648173176699613,
  7.                 -1.7298486510592452,0.42164964981080416,9.557259289818587,
  8.                 -1.7618787694384546,0.45864558999786653,9.653153776935605,
  9.                 -1.7410197123193858,0.4236369742675384,9.55486293595946,
  10.                 -1.7600076822930908,0.46214612481362705,9.594426626710453,
  11.                 -1.5761631958773263,0.3715109598910308,9.436853714636964,
  12.                 -1.5920827364351244,0.37070313540523914,9.66189484448469,
  13.                 -1.6178308849438598,0.37500917334673567,9.695719226290015,
  14.                 -1.4388296833472143,0.6108605310285585,9.464814699883437,
  15.                 -1.5651621282887258,0.5691273914891515,9.513897717476588,
  16.                 -1.4637992479412343,0.5105873209777632,9.501636895304161,
  17.                 -0.6794677157685166,0.5024637601753793,8.96404801376064,
  18.                 0.2600149177042748,0.6699546179356337,8.903349009412763,
  19.                 1.0712686735261918,1.4889662656074603,9.520348132500752,
  20.                 0.3914123345764725,1.4210706041563634,10.557387805652848,
  21.                 1.0779003359396493,1.0582703827741018,10.454469820960814,
  22.                 0.12433283758079197,-0.27273511643713033,10.328552286632643,
  23.                 -0.010219096051988997,0.2961821896002729,9.483084545625971,
  24.                 -1.6910112286007235,-0.2898761724876157,9.704755735796937,
  25.                 -2.693651827312974,-0.41126025575408387,9.825328217800239,
  26.                 -2.8416981790648177,-0.14586229740441406,9.880552703938179
  27. };

  28. int acquire_and_process_data(void *in_data,int factor)
  29. {
  30.         printf("in_data:");
  31.         for (int i=0; i<AI_HAR_IGN_IN_1_SIZE; i++)
  32.         {
  33.                 ((ai_float*)in_data)[i] =in_buf[i];
  34.                 printf("%.4f ",((ai_float*)in_data)[i]);
  35.         }
  36.         printf("\n");

  37.         return 0;
  38. }
复制代码

        重新编辑及加载到开发板,打开串口助手,输入test*,查看测试效果如下,显然和期待有很大出入:

e3b876266c32425b83e90c7602eb4a60.png

四、测试有误问题
        上述结果和HAR项目中的PrepareDataset.py分类似乎并没匹配上,那么就要分析PrepareDataset.py分类和生成后的c语言模型时如何对应的,以及用来测试的数据是否符合模型要求。

ddc6e0bf936f43d2a8ede66d8058edbb.png

        为此,再次回到HAR训练模型项目,在RunMe.py文件中追加以下语句:
  1. print("TestX:")
  2. print(TestX[0:1])
  3. print("TestY:")
  4. print(TestY[0:1])
复制代码

        以获取用来测试的真实模拟数据,再次运行python3 .\RunMe.py --dataDir=Log_data命令,最后部分输出如下:
  1. TestX:
  2. [[[[-3.64077855e-16]
  3.    [-4.69612372e-16]
  4.    [ 3.68092310e-10]]

  5.   [[ 1.02756571e+01]
  6.    [-1.14305305e+01]
  7.    [ 2.61872125e+01]]

  8.   [[-2.84181689e+00]
  9.    [-3.54747048e+00]
  10.    [-5.51206446e+00]]

  11.   [[-3.82102513e+00]
  12.    [-1.41233186e+01]
  13.    [-4.59900586e+00]]

  14.   [[ 6.68010824e+00]
  15.    [ 9.39457601e+00]
  16.    [-2.96397789e+00]]

  17.   [[-1.71771782e+01]
  18.    [ 1.19374149e+01]
  19.    [ 3.05770680e+00]]

  20.   [[-6.65782005e+00]
  21.    [ 2.39062819e+00]
  22.    [ 3.22844912e+00]]

  23.   [[ 4.59021292e+00]
  24.    [-6.27548028e+00]
  25.    [-4.92783556e+00]]

  26.   [[ 8.03018658e+00]
  27.    [-2.72208600e+00]
  28.    [-6.35796053e+00]]

  29.   [[ 7.73164454e+00]
  30.    [-6.31879160e+00]
  31.    [-5.90723810e+00]]

  32.   [[ 8.53803514e-01]
  33.    [-9.75763211e+00]
  34.    [ 1.02466115e+01]]

  35.   [[ 1.11299171e+01]
  36.    [-1.70658346e+01]
  37.    [ 2.18511283e+01]]

  38.   [[ 3.92044994e-01]
  39.    [ 5.94768181e+00]
  40.    [ 4.30131750e+00]]

  41.   [[-5.61807988e+00]
  42.    [ 1.97310400e+01]
  43.    [-2.22512540e+00]]

  44.   [[ 3.86836548e+00]
  45.    [ 1.71617325e+00]
  46.    [-5.86292387e+00]]

  47.   [[ 7.65913325e+00]
  48.    [-7.19628424e+00]
  49.    [ 2.01628025e+00]]

  50.   [[-7.52357836e+00]
  51.    [ 3.68102584e+00]
  52.    [-1.22753233e+01]]

  53.   [[-5.12351958e+00]
  54.    [ 1.23941669e+01]
  55.    [-1.77385540e+00]]

  56.   [[-4.86155823e-01]
  57.    [ 1.26333902e+01]
  58.    [ 5.93595914e+00]]

  59.   [[-1.96569165e+01]
  60.    [ 1.00467317e+01]
  61.    [ 9.47374003e+00]]

  62.   [[-4.34050581e+00]
  63.    [ 5.16311148e-01]
  64.    [-5.63004156e-01]]

  65.   [[-3.57974669e+00]
  66.    [ 4.87240857e-01]
  67.    [-9.38271247e-01]]

  68.   [[ 6.11930536e+00]
  69.    [ 5.99067573e+00]
  70.    [-7.68834262e+00]]

  71.   [[ 1.12153409e+01]
  72.    [ 2.37168199e+00]
  73.    [-7.40963357e+00]]]]
  74. TestY:
  75. [[1. 0. 0. 0.]]
  76. PS D:\tools\arm_tool\STM32CubeIDE\STM32CubeFunctionPack_SENSING1_V4.0.3\Utilities\AI_Ressources\Training Scripts\HAR>
复制代码

        显然输入24*3的一组数据,输出结果是[1. 0. 0. 0.],再将该数据用于测试 c语言模型神经网络模型API调用。
  1. ai_float in_buf[] =
  2. {
  3.                 -3.64077855e-16,-4.69612372e-16,3.68092310e-10,
  4.                 1.02756571e+01,-1.14305305e+01,2.61872125e+01,
  5.                 -2.84181689e+00,-3.54747048e+00,-5.51206446e+00,
  6.                 -3.82102513e+00,-1.41233186e+01,-4.59900586e+00,
  7.                 6.68010824e+00, 9.39457601e+00,-2.96397789e+00,
  8.                 -1.71771782e+01,1.19374149e+01,3.05770680e+00,
  9.                 -6.65782005e+00,2.39062819e+00,3.22844912e+00,
  10.                 4.59021292e+00,-6.27548028e+00,-4.92783556e+00,
  11.                 8.03018658e+00,-2.72208600e+00,-6.35796053e+00,
  12.                 7.73164454e+00,-6.31879160e+00,-5.90723810e+00,
  13.                 8.53803514e-01,-9.75763211e+00, 1.02466115e+01,
  14.                 1.11299171e+01,-1.70658346e+01, 2.18511283e+01,
  15.                 3.92044994e-01, 5.94768181e+00, 4.30131750e+00,
  16.                 -5.61807988e+00, 1.97310400e+01,-2.22512540e+00,
  17.                 3.86836548e+00, 1.71617325e+00,-5.86292387e+00,
  18.                 7.65913325e+00,-7.19628424e+00, 2.01628025e+00,
  19.                 -7.52357836e+00, 3.68102584e+00,-1.22753233e+01,
  20.                 -5.12351958e+00, 1.23941669e+01,-1.77385540e+00,
  21.                 -4.86155823e-01, 1.26333902e+01, 5.93595914e+00,
  22.                 -1.96569165e+01, 1.00467317e+01, 9.47374003e+00,
  23.                 -4.34050581e+00, 5.16311148e-01,-5.63004156e-01,
  24.                 -3.57974669e+00, 4.87240857e-01,-9.38271247e-01,
  25.                 6.11930536e+00, 5.99067573e+00,-7.68834262e+00,
  26.                 1.12153409e+01, 2.37168199e+00,-7.40963357e+00
  27. };

  28. int acquire_and_process_data(void *in_data,int factor)
  29. {
  30.         printf("in_data:");
  31.         for (int i=0; i<AI_HAR_IGN_IN_1_SIZE; i++)
  32.         {
  33.                 ((ai_float*)in_data)[i] =in_buf[i];
  34.                 printf("%.4f ",((ai_float*)in_data)[i]);
  35.         }
  36.         printf("\n");

  37.         return 0;
  38. }
复制代码

        再次编译下载程序,采用串口助手测试如下,输出数据为,【0.943687 0.000000 0.000294 0.056019】,而实际数据是[1. 0. 0. 0.],显然能对应上,只是精度问题:

9383fc855efa480ea2c7d45102b336e3.png


五、精度问题
        再次回到HAR训练项目上,如前文所述,训练结果按时间生成一个目录进行输出:

d418ce8ca8274881a581ffee9d71ad53.png

         输出了训练的acc 、loss变化曲线图和混淆矩阵图,观察可以看到,用于训练数据其主要还是来自于WISDM的数据集占据大头,从混淆矩阵也可以看出,为何前面测试时输出结果0.943687 0.000000 0.000294 0.056019】,显然训练过程中,'Jogging'姿态会有一部分判断 'Stairs', 'Walking'姿态。

c4ff79af33d644c58f8d33fbd1f33b7b.png

         在训练过程日志显示:

e494274d0f0943c79d26257f8c2bc97e.png

        再次改写RunMe.py,加入下面打印语句,查看用于训练、验证及测试的数据集量级:
  1. print("TrainX:"+str(len(TrainX)))
  2. print("TrainY:"+str(len(TrainY)))
  3. print("ValidationX:"+str(len(ValidationX)))
  4. print("ValidationY:"+str(len(ValidationY)))
  5. print("TestX:"+str(len(TestX)))
  6. print("TestY:"+str(len(TestY)))
复制代码

        再次运行python3 .\RunMe.py --dataDir=Log_data命令:

eabdae7f23204f11a3065368627ac56a.png

         通常在实际项目中,不断优化算法模型是主要原因,但相信ST公司及其合作团队应该就算法模型做了足够好,而本文测试验证为何还出现精度相差这么大,应该是以下几点:
        1)本文用于训练模型的数据集不是同一设备,同一批次,统一采集方法获得足够量数据集。

        2)本文自行采集的数量偏小,可能预WISDM采集数据方法存在差异而出现精确性问题,并加入其中,还是会影响模型训练精度的(若仅采用WISDM采集数据集)。

        3)本文仅采用了HAR训练项目建议的默认参数,实际项目中,可能需要我们根据数据集及部署环境,不断尝试不同参数设置来训练和使用神经网络模型。

        4)cube.AI将keras训练的神经网络模型转换为c语言的神经网络模型虽然损耗极小,但还是存在一定精度损失的。

2f47b778999d4bc4b7419ecbdbf99b51.png

         篇一、二,是基于FP-AI-SENSING1案例和配套的B-L475E-IOT01A开发板来使用cube.AI软件包的,那么在实际使用cube.AI时,需要与我们项目实际硬件平台,并基于该硬件平台采集的数据进行数据预处理和神经网络模型构建、训练、验证及测试,然后再通过cubeMX和cube.AI将训练好的神经网络模型转换为c语言支持的AI模型,通过嵌入式程序加载(AI模型+cube.AI)从而实现神经网络计算的前端或边缘端部署,请阅读偏三。
————————————————
版权声明:py_free-物联智能
如有侵权请联系删除
收藏 1 评论0 发布时间:2023-4-3 21:17

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版