add tflite example and fix bug

This commit is contained in:
dkk0918
2021-09-08 13:55:09 +08:00
parent c55e48b61b
commit a776417de4
47 changed files with 5076 additions and 13 deletions

View File

@@ -0,0 +1,53 @@
/**
* @file tflitemicro_person_detection.c
* @author Derekduke (dkeji627@gmail.com); QingChuanWS (bingshan45@163.com); yangqings (yangqingsheng12@outlook.com)
* @brief Person detection example based on TencentOS-Tiny and TFlite_Micro.
* @version 0.1
* @date 2021-01-05
* @copyright Copyright (c) 2021
*
*/
#include "cmsis_os.h"
#include "mcu_init.h"
#include "micro_speech.h"
uint8_t tensor_flag = 0;
#define TASK1_STK_SIZE 1024
void task1(void *arg);
osThreadDef(task1, osPriorityNormal, 1, TASK1_STK_SIZE);
#define TASK2_STK_SIZE 1024
void task2(void *arg);
osThreadDef(task2, osPriorityNormal, 1, TASK2_STK_SIZE);
void task1(void *arg)
{
while (1) {
printf("***task1\r\n");
osDelay(1000);
}
}
void task2(void *arg)
{
uint8_t* data = NULL;//you can input your own data
extern void speech_run(uint8_t*);
speech_run(data);
while (1) {
printf("***task2\r\n");
osDelay(2000);
}
}
void application_entry(void *arg)
{
extern void speech_init(void);
speech_init();
printf("***Start speech detection task! \r\n");
osThreadCreate(osThread(task1), NULL); // Create task1
osThreadCreate(osThread(task2), NULL); // Create task2
}

View File

@@ -0,0 +1,27 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// This is a standard TensorFlow Lite FlatBuffer model file that has been
// converted into a C data array, so it can be easily compiled into a binary
// for devices that don't have a file system. It was created using the command:
// xxd -i model.tflite > model.cc
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_
extern const unsigned char g_model[];
extern const int g_model_len;
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_

View File

@@ -0,0 +1,188 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "no_micro_features_data.h"
// Golden test values for the expected spectrogram from a "no" sample file
// speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav.
const int g_no_micro_f9643d42_nohash_4_width = 40;
const int g_no_micro_f9643d42_nohash_4_height = 49;
const signed char g_no_micro_f9643d42_nohash_4_data[] = {
103, 78, 64, 76, 75, 54, 53, 67, 77, 60, 56, 70,
76, 71, 68, 58, 74, 32, 23, -2, -18, 11, 13, 15,
9, 20, 5, -7, -18, -2, -10, -18, -10, -12, 9, 7,
-33, -12, -4, -18, 57, 17, 55, 62, 70, 45, 61, 37,
67, 52, 48, 47, 55, 46, 57, 47, 73, 17, 27, 20,
19, 8, 15, -6, -1, 10, -12, -29, -6, -23, -18, -3,
-1, 5, 3, -4, -12, -8, -1, -14, 65, 48, 58, 43,
48, 19, 39, 39, 57, 57, 58, 55, 67, 58, 49, 50,
70, 27, 9, 16, 37, 4, 25, 4, 11, 9, 7, -33,
-7, -12, 3, -6, -29, -7, -7, -18, -12, -18, -2, -1,
0, 31, 60, -8, 51, 59, 70, 40, 71, 57, 52, 38,
66, 48, 17, 6, 59, 8, 15, 7, 18, 4, 18, -23,
-8, -4, -3, -12, -3, -26, 1, 10, 2, -29, -29, -37,
-7, -4, 6, -33, 67, 44, 59, -4, 64, 51, 68, 55,
74, 9, 40, 15, 57, 33, 60, 18, 40, 25, 27, -20,
25, -16, 6, 17, -10, -12, -23, -43, -23, -23, -29, -37,
-4, -16, -16, -60, -20, -23, -10, -29, -12, 15, 12, -37,
27, 15, 61, 44, 50, 8, 48, 22, 49, -18, 46, 33,
42, 34, 46, -8, 4, -18, -43, -43, -10, 1, -10, -16,
-10, -77, -16, -33, 11, -26, -23, -37, 0, -8, -16, -29,
42, 40, 68, 24, 47, 46, 53, -128, 30, 2, 42, 21,
21, -4, 43, 2, 43, 5, 32, -26, 7, -37, -43, -23,
-2, -8, 2, -37, -50, -60, -1, -7, -33, -77, -6, -18,
-16, -50, -12, -33, 53, 8, 52, 18, 51, 35, 69, 26,
44, 8, 27, -128, 21, -33, 17, -14, 38, -128, -14, -18,
17, -20, -14, -37, 8, -60, -33, -33, -33, -43, -12, -29,
-12, -128, -33, -60, -26, -77, -26, -50, 57, 29, 11, 30,
53, -10, 45, 15, 18, -10, 42, 2, 31, -29, 10, -4,
42, -37, -50, -128, -4, -43, -20, -77, -14, -26, -33, -128,
-12, -43, -8, -33, -33, -60, -43, -77, -12, -60, -26, -50,
40, -23, 36, 35, 50, -2, 37, 27, 26, -77, 49, -7,
28, -43, 6, 11, 41, -37, 33, -26, -14, -12, -6, -33,
-16, -26, -20, -77, -14, -43, -8, -50, -14, -37, -26, -77,
-26, -77, -14, -29, 50, -60, 25, -26, 57, 38, 51, 1,
50, 1, 53, -18, 30, -23, 11, -128, 18, -43, 20, -26,
-10, -26, -12, -128, -50, -60, -37, -77, -20, -43, -50, -128,
-77, -128, -77, -128, -33, -77, -20, -60, 53, -10, -37, -128,
10, -128, 60, 18, -8, 13, 37, -37, 8, -128, 3, -77,
32, -29, 14, 10, -12, -77, -37, -77, -37, -60, -23, -128,
-43, -50, -16, -77, -6, -33, 0, -60, -43, -128, -16, -60,
20, -2, 51, 19, 43, 2, 63, 20, 60, -4, 42, -50,
4, -128, 2, -3, 32, -33, -26, -128, -18, -128, -33, -43,
-7, -60, -50, -77, -29, -77, -23, -128, -16, -26, -23, -60,
-37, -77, -37, -128, -1, -33, 39, 48, 60, 5, 8, -128,
44, 11, 4, 0, 13, -77, -2, -20, 33, -128, -33, -77,
-8, -128, -14, -128, -33, -18, -12, -77, -16, -128, -37, -128,
-12, -77, -60, -128, -23, -60, -23, -128, 36, -50, 46, -128,
66, 39, 18, -14, -12, -77, -20, -6, 24, -128, 28, -26,
21, -77, -6, -33, 1, -128, -43, -128, -1, -50, -37, -128,
-50, -128, -33, -128, -18, -128, -60, -8, -7, -60, -60, -128,
-6, -29, 20, -1, 73, 40, -43, -14, 33, -43, 33, -3,
15, -29, 29, -43, 20, -60, -29, -128, -20, -26, 4, -77,
-16, -60, -33, -50, -29, -128, -60, -128, -77, -128, -37, -50,
0, -77, -33, -128, 39, 8, 47, 10, 62, 16, 2, 1,
10, 7, 4, -7, 6, -128, -77, -50, 19, -77, -77, -128,
-77, -128, -50, -128, -60, -60, -33, -50, -37, -128, -128, -128,
-60, -128, -37, -60, -18, -128, -33, -77, 37, 23, 29, -128,
-128, -128, -16, -128, -16, -33, 21, -20, -8, -60, -2, -60,
11, -128, -50, -128, -50, -128, -29, -77, -16, -128, -26, -128,
-50, -77, -43, -128, -128, -128, -50, -128, -33, -128, -33, -50,
-23, -128, 24, -128, -128, -77, 4, -23, 32, -128, 1, -26,
-14, -128, 10, -77, -4, -128, 1, -50, -8, -77, -77, -77,
-23, -128, -50, -43, -33, -128, -43, -128, -128, -128, -43, -128,
-50, -128, -128, -128, 44, 15, 14, -128, 9, -128, 21, 0,
29, -7, 18, -7, -7, -128, -33, -50, 14, -60, -60, -128,
-60, -128, -37, -128, -43, -128, -20, -128, -50, -128, -43, -77,
-26, -128, -60, -50, -60, -128, -77, -128, -3, -128, 14, -77,
-26, 11, 47, -77, -7, -77, 45, -43, -12, 14, 37, -60,
22, -4, 5, -77, -14, -128, -10, -60, 22, -77, -12, -60,
-50, -128, -60, -128, -60, -128, -43, -128, -50, -128, -77, -50,
27, -37, 33, -128, 4, -29, -4, -50, -20, -128, 6, -37,
-33, -128, -50, -128, 34, 15, -43, -128, -20, -50, -3, -37,
-37, -77, -77, -128, -43, -128, -128, -128, 4, -26, -26, 27,
0, -128, -29, -60, 35, -26, 23, -128, -29, -77, 19, 14,
28, -128, -16, -7, 31, -1, 17, 11, 60, 44, 8, 11,
18, -128, -33, -60, -1, -128, -43, -128, -23, -128, -128, -128,
59, 43, 35, 61, 37, -77, -77, -50, 116, 88, 98, 69,
78, 53, 78, 40, 48, 7, 29, -18, -2, -14, 5, 12,
65, 35, 31, -12, 33, -2, -6, -1, 44, -29, -14, -60,
-4, -43, -37, -128, 29, 18, 38, 51, 8, -128, -12, -37,
115, 91, 113, 77, 89, 36, 60, 44, 49, 36, 27, 31,
63, 30, 62, 14, 55, 49, 42, 0, 45, 17, -23, 1,
30, -37, -50, -77, -8, -60, 9, -60, -12, -50, 13, 4,
23, -6, 28, 13, 107, 78, 101, 73, 89, 46, 63, 17,
34, -43, -6, 30, 67, 40, 77, 21, 53, 39, 38, 12,
-6, 5, 28, -2, 18, -43, 0, -128, -29, -77, 18, -128,
-2, -77, 39, 35, 38, 35, 50, 29, 100, 70, 94, 69,
86, 50, 45, 38, 45, 12, 58, 64, 74, 36, 77, 45,
78, 62, 8, -60, 38, 6, 21, 7, 8, -37, -1, -20,
48, -37, 8, -10, 8, 13, 45, 39, 38, 22, 49, 25,
94, 63, 87, 66, 84, -128, 29, 20, 55, 51, 80, 36,
62, 30, 81, 72, 68, 37, 51, 27, 54, 22, 16, -29,
4, 9, 57, 15, 35, -43, -77, -20, 4, 6, 37, -1,
40, 31, 47, 14, 89, 68, 96, 83, 111, 96, 115, 87,
99, 76, 105, 84, 105, 86, 113, 91, 108, 87, 110, 78,
80, 46, 22, 74, 88, 72, 103, 86, 80, 68, 48, 24,
68, 48, 55, 36, 108, 90, 90, 63, 83, 63, 87, 64,
90, 92, 113, 88, 102, 79, 109, 83, 100, 89, 109, 60,
56, 21, 75, 62, 81, 45, 63, 73, 93, 65, 94, 80,
89, 81, 73, 3, 43, 60, 102, 70, 84, 67, 99, 74,
78, 57, 79, 50, 93, 82, 98, 56, 77, 70, 91, 71,
85, 82, 86, 13, 45, -18, 48, 40, 53, 28, 85, 60,
65, 52, 86, 78, 76, 46, 73, 19, 35, 54, 75, 40,
71, 60, 82, 37, 69, 42, 62, 40, 96, 70, 85, 77,
70, 68, 103, 84, 94, 69, 81, -128, -128, -128, -43, -37,
40, 2, 48, 45, 76, 37, 65, 16, 43, 18, 58, 20,
27, 12, 71, 31, 53, 44, 88, 47, 50, 33, 39, 8,
89, 57, 88, 69, 72, 63, 100, 68, 81, -77, -10, -128,
-128, -128, -128, -128, 13, -77, 8, 27, 60, 28, 41, -128,
-37, -128, 28, -43, -18, -128, 47, -37, 45, 27, 51, -29,
15, 39, 52, 30, 49, -33, 65, 15, 76, 71, 90, 19,
46, -128, -16, -128, -128, -128, -128, -128, -128, -128, -18, -128,
-20, -128, 32, -128, 21, -33, 45, -128, -128, -128, -12, -128,
-6, -14, 43, -128, -128, -128, -128, -128, 52, -18, 69, -43,
78, 55, 42, -128, -29, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, 14, -128, -16, -128, -128, -128, 7, -128,
-128, -128, -128, -128, -128, -128, 12, -128, -128, -128, -128, -16,
59, -50, 35, -128, 42, 0, 47, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -33, -128, -23, -128,
-128, -128, -23, -128, -128, -128, -128, -128, -128, -128, -33, -128,
-128, -128, -128, -128, -128, -128, -8, -128, 36, -50, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -37, -128, -128, -60, -10, -128, -128, -128, -128, -128,
-128, -128, 21, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-12, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -77, -128, -128, -128, -29, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-29, -128, -128, -128, -128, -128, -128, -128, -128, -128, -50, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128,
};

View File

@@ -0,0 +1,23 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_
extern const int g_no_micro_f9643d42_nohash_4_width;
extern const int g_no_micro_f9643d42_nohash_4_height;
extern const signed char g_no_micro_f9643d42_nohash_4_data[];
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_

View File

@@ -0,0 +1,188 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "yes_micro_features_data.h"
// Golden test values for the expected spectrogram from a "yes" sample file
// speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav.
const int g_yes_micro_f2e59fea_nohash_1_width = 40;
const int g_yes_micro_f2e59fea_nohash_1_height = 49;
const signed char g_yes_micro_f2e59fea_nohash_1_data[] = {
116, 98, 118, 95, 106, 85, 101, 81, 67, -18, -33, -12,
-26, -128, 9, 34, 56, 45, 9, -12, 5, 30, 23, 28,
0, -18, 0, -128, -60, -50, -50, -37, -60, -60, -50, -26,
-33, -50, -33, -50, 83, 61, 81, 55, 76, 61, 73, 64,
38, -8, -37, -20, -18, -20, 48, 29, 52, 41, 55, 18,
25, 37, 44, 37, 8, 15, -6, -60, -128, -50, -37, -37,
-18, -37, -26, -29, -37, -60, -50, -60, 95, 59, 52, -4,
54, -18, 68, 43, 31, -18, -26, -33, -37, -29, 33, 7,
-3, 8, 26, 24, 36, 6, 36, 23, 14, 8, -29, -37,
-37, -37, -50, -50, -26, -8, -26, -37, -18, -37, -60, -77,
50, 48, 83, 44, 56, -128, -33, -60, 1, -26, -60, -43,
-14, -23, -18, -43, -26, -33, 13, -77, -43, -77, -33, -37,
16, -12, -37, -50, -50, -77, -20, -43, -60, -128, -60, -77,
-37, -77, -60, -128, 37, -10, 65, -7, 28, -128, 10, -77,
-37, -128, -77, -128, -77, -43, -128, -128, -77, -128, -128, -128,
-128, -128, -14, -128, -43, -50, -37, -77, -128, -128, -77, -43,
-29, -43, -20, -60, -37, -43, -50, -128, -77, -128, -18, -128,
-60, -128, -128, -128, -77, -128, -77, -128, -128, -128, -60, -37,
-20, -128, -60, -128, -128, -128, -60, -128, -77, -60, -128, -50,
-60, -128, -77, -128, -50, -60, -37, -60, -50, -77, -77, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -37, -128,
-128, -128, -128, -128, -77, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -77, -60, -128, -128, -50, -128, -50, -128,
-50, -128, -77, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -77, -128, -77, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-77, -128, -77, -128, -77, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -77, -128, -128, -128,
-128, -77, -50, -128, -128, -77, -77, -128, -128, -128, -50, -128,
85, 43, 65, 53, 69, 60, 45, 3, 46, -12, 9, -23,
32, -1, -128, -128, -128, -128, -1, 37, 38, 33, 43, 36,
58, 70, 68, 39, 6, 10, 32, 6, 8, -23, -77, -128,
-29, -128, -77, -128, 101, 87, 102, 91, 110, 88, 101, 83,
110, 95, 111, 83, 81, 84, 106, 90, 93, 82, 98, 91,
108, 95, 118, 97, 118, 97, 116, 96, 113, 90, 110, 96,
107, 85, 94, 66, 69, 36, 29, 0, 100, 60, 105, 68,
92, 93, 113, 92, 107, 85, 107, 83, 104, 91, 105, 85,
112, 88, 101, 80, 101, 79, 96, 80, 98, 80, 105, 83,
98, 81, 103, 71, 100, 79, 83, 78, 91, 47, 50, 13,
108, 81, 93, 78, 98, 76, 105, 76, 98, 40, 77, 72,
81, 62, 93, 77, 96, 80, 98, 61, 97, 69, 88, 61,
71, 56, 98, 68, 97, 72, 89, 51, 81, 61, 88, 75,
86, 56, 48, 13, 71, 22, 84, 66, 76, -7, 48, 61,
77, 62, 91, 65, 95, 74, 88, 59, 75, 58, 83, 55,
87, 55, 76, 43, 76, -3, 56, 60, 79, 57, 71, 54,
82, 33, 74, 71, 91, 45, 18, -7, 61, 56, 77, 41,
73, 42, 82, 49, 59, 63, 82, 65, 66, 38, 83, 34,
48, -8, 46, 20, 54, 33, 54, 6, 48, 16, 60, 37,
58, 22, 58, 14, 65, 53, 75, -4, 42, 16, 16, -50,
22, -128, 80, 54, 43, -50, 42, -128, -10, -77, 28, -29,
68, 43, 73, 2, 25, -60, 47, 14, 45, 7, 66, 4,
62, 37, 71, 7, 46, -10, 44, 22, 55, 53, 57, -29,
26, -10, -3, -128, 38, -128, 46, -10, 16, -128, -10, -26,
60, -7, 65, 38, 70, -60, 35, -8, 42, -29, 6, -128,
34, -128, 36, -60, 44, -12, -2, -128, -7, -60, -60, -128,
-23, -128, 31, -33, 22, -77, -37, -43, -128, -128, 3, -128,
-23, -128, 17, -77, 43, -77, -7, -128, -20, -128, 17, -43,
32, -128, -43, -128, -128, -77, 21, -128, -50, -128, -128, -128,
-128, -128, -128, -128, -37, -128, -16, -128, -50, -26, -6, -128,
-128, -128, -128, -128, -23, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -16, -128, 36, -7, 16, -128, -128, -128, -128, -128,
-77, -128, -37, -128, -50, -128, -128, -128, -128, -128, -18, -128,
11, -128, -16, -77, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -26, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -20, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -50, -128, -77, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -77, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -1, -18, 5, -128,
40, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, 4, -128, 63, 66, 75, -128,
70, 60, 34, -128, -128, -128, -128, -128, -128, -128, -128, -128,
87, 86, 95, 76, 91, 62, 72, -6, -50, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, 64, 83, 104, 70,
98, 90, 111, 89, 109, 80, 71, -128, -128, -128, -128, -128,
-20, -6, 27, 33, 86, 88, 108, 75, 108, 76, 98, 64,
75, 61, 71, 66, 85, -1, -77, -128, 46, 61, 92, 69,
100, 93, 113, 80, 108, 93, 113, 91, 110, 80, 85, 15,
-33, -128, 12, -50, 34, 50, 70, 55, 84, 72, 108, 81,
111, 88, 100, 80, 84, 73, 97, 86, 99, 65, 85, 43,
96, 78, 107, 94, 118, 98, 115, 92, 118, 94, 111, 93,
111, 86, 99, 52, 32, -16, 48, 31, 81, 74, 85, 64,
78, 64, 98, 70, 110, 92, 96, 73, 100, 72, 94, 73,
98, 76, 85, 67, 101, 83, 101, 83, 112, 89, 98, 85,
105, 78, 98, 72, 102, 80, 95, 23, 19, -8, 52, 57,
103, 91, 95, 65, 74, 8, 77, 49, 96, 76, 100, 87,
105, 81, 94, 62, 94, 78, 81, 72, 99, 82, 101, 78,
108, 65, 82, 70, 100, 63, 79, 58, 80, 59, 87, 48,
50, 57, 93, 67, 86, 80, 103, 56, 77, 31, 81, 57,
62, 41, 96, 85, 91, 71, 101, 76, 89, 78, 95, 76,
96, 79, 103, 81, 103, 48, 70, 57, 88, 66, 84, 11,
85, 67, 104, 37, 38, 67, 90, 54, 81, 62, 90, 52,
78, -60, 54, -8, 68, 40, 55, 8, 77, 52, 66, 31,
55, 13, 60, 26, 69, 42, 63, -29, 57, -128, -3, -128,
3, -128, -29, -60, 52, -43, 63, 56, 86, 75, 95, 75,
85, 63, 82, 10, 50, -128, 31, -77, 0, -77, -23, -128,
12, -77, 51, -3, 58, -14, 44, 0, 48, 4, 53, 47,
28, -128, -128, -128, -37, -128, -3, -128, 49, 61, 100, 90,
117, 88, 107, 94, 112, 64, 96, 83, -128, -128, 7, -128,
-77, -128, -23, -128, -23, -128, 16, -37, 65, -8, 48, 20,
14, -77, 57, -18, -43, -128, -128, -128, -128, -128, -128, -128,
24, 12, 74, 76, 105, 76, 99, 80, 108, 79, 103, 85,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
42, -128, -8, -128, -50, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -60, -128, -128, 5, 73, 53, 93, 70, 101, 73,
94, 57, 86, 66, -18, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -50, -128, 36, -128, -128, -128, -128, -128, -20, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, 23, 37,
75, 54, 97, 70, 83, 52, 85, 65, 7, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -43, -128, 23, -128, -43, -128,
-33, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -26, -37, 65, 33, 76, 37, 73, 50, 77, 47,
-12, -128, -128, -128, -128, -128, -128, -128, -128, -128, -7, -14,
-4, -128, -14, -128, 18, -60, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -26, -60, 71, 42, 68, 53,
81, 49, 73, 36, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -18, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, 15, -26,
44, -18, 59, 39, 57, 20, 62, 26, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, 49, -128, 30, 8, 69, 27, 62, 38,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -43, -128, 28, -37, 48, -10,
48, 11, 74, 37, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-77, -128, 11, -128, -7, -60, -77, -4, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -8, -128, -50, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128,
-128, -128, -128, -128,
};

View File

@@ -0,0 +1,23 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_
extern const int g_yes_micro_f2e59fea_nohash_1_width;
extern const int g_yes_micro_f2e59fea_nohash_1_height;
extern const signed char g_yes_micro_f2e59fea_nohash_1_data[];
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_

View File

@@ -0,0 +1,116 @@
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "model.h"
#include "no_micro_features_data.h"
#include "yes_micro_features_data.h"
#include "micro_speech.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"
namespace {
tflite::MicroErrorReporter micro_error_reporter;
tflite::MicroMutableOpResolver<4> micro_op_resolver;
const tflite::Model* model = nullptr;
tflite::MicroInterpreter* interpreter = nullptr;
TfLiteTensor* model_input = nullptr;
// In order to use optimized tensorflow lite kernels, a signed int8_t quantized
// model is preferred over the legacy unsigned model format. This means that
// throughout this project, input images must be converted from unisgned to
// signed format. The easiest and quickest way to convert from unsigned to
// signed 8-bit integers is to subtract 128 from the unsigned value to get a
// signed value.
// An area of memory to use for input, output, and intermediate arrays.
// Create an area of memory to use for input, output, and intermediate arrays.
const int tensor_arena_size = 10 * 1024;
uint8_t tensor_arena[tensor_arena_size];
} // namespace
//TF_LITE_MICRO_TESTS_BEGIN
//TF_LITE_MICRO_TEST(TestInvoke) {
extern "C" void speech_init(int8_t* input_data){
// Set up logging.
// Map the model into a usable data structure. This doesn't involve any
// copying or parsing, it's a very lightweight operation.
const tflite::Model* model = ::tflite::GetModel(g_model);
static tflite::MicroMutableOpResolver<4> micro_op_resolver;
micro_op_resolver.AddDepthwiseConv2D();
micro_op_resolver.AddFullyConnected();
micro_op_resolver.AddReshape();
micro_op_resolver.AddSoftmax();
// Build an interpreter to run the model with.
static tflite::MicroInterpreter static_interpreter(model, micro_op_resolver, tensor_arena,
tensor_arena_size,
&micro_error_reporter);
interpreter = &static_interpreter;
interpreter->AllocateTensors();
// Get information about the memory area to use for the model's input.
model_input = interpreter->input(0);
}
extern "C" void speech_run(int8_t* input_data){
// Copy a spectrogram created from a .wav audio file of someone saying "Yes",
// into the memory area used for the input.
const int8_t* yes_features_data = g_yes_micro_f2e59fea_nohash_1_data;
//const int8_t* yes_features_data = input_data; //input your own speech data
for (size_t i = 0; i < model_input->bytes; ++i) {
model_input->data.int8[i] = yes_features_data[i];
}
// Run the model on this input and make sure it succeeds.
TfLiteStatus invoke_status = interpreter->Invoke();
TfLiteTensor* output = interpreter->output(0);
const int kSilenceIndex = 0;
const int kUnknownIndex = 1;
const int kYesIndex = 2;
const int kNoIndex = 3;
// Make sure that the expected "Yes" score is higher than the other classes.
uint8_t silence_score = output->data.uint8[kSilenceIndex] + 128;
uint8_t unknown_score = output->data.uint8[kUnknownIndex] + 128;
uint8_t yes_score = output->data.int8[kYesIndex] + 128;
uint8_t no_score = output->data.int8[kNoIndex] + 128;
// Run the model on this "No" input.
invoke_status = interpreter->Invoke();
if (invoke_status != kTfLiteOk) {
TF_LITE_REPORT_ERROR(&micro_error_reporter, "Invoke failed\n");
}
// TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status);
// Get the output from the model, and make sure it's the expected size and
// type.
output = interpreter->output(0);
silence_score = output->data.int8[kSilenceIndex] + 128;
unknown_score = output->data.int8[kUnknownIndex] + 128;
yes_score = output->data.int8[kYesIndex] + 128;
no_score = output->data.int8[kNoIndex] + 128;
printf("speech test-> silence: %d unknown_score: %d yes_score: %d no_score: %d\n" , silence_score,unknown_score,yes_score,no_score);
TF_LITE_REPORT_ERROR(&micro_error_reporter, "Ran successfully\n");
}
//TF_LITE_MICRO_TESTS_END

View File

@@ -0,0 +1,32 @@
#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_SPEECH_EXPERIMENTAL_MAIN_FUNCTIONS_H_
#define TENSORFLOW_LITE_MICRO_EXAMPLES_SPEECH_EXPERIMENTAL_MAIN_FUNCTIONS_H_
// Initializes all data needed for the example. The name is important, and needs
// to be setup() for Arduino compatibility.
#include "tensorflow/lite/c/common.h"
/*
#ifdef __cplusplus
extern "C"
{
#endif
void speech_init(void);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void speech_run(uint8_t*);
#ifdef __cplusplus
}
#endif
*/
// Runs one iteration of data gathering and inference. This should be called
// repeatedly from the application code. The name needs to be loop() for Arduino
// compatibility.
//extern "C" int person_detect();
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_EXPERIMENTAL_MAIN_FUNCTIONS_H_