Ported micro feature generation for speech to micro framework
PiperOrigin-RevId: 234230415
This commit is contained in:
parent
2e700a1cfd
commit
22a1957825
@ -11,34 +11,34 @@ load(
|
|||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "model_settings",
|
name = "simple_model_settings",
|
||||||
srcs = [
|
srcs = [
|
||||||
"model_settings.cc",
|
"simple_features/simple_model_settings.cc",
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"model_settings.h",
|
"simple_features/simple_model_settings.h",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "tiny_conv_model_data",
|
name = "tiny_conv_simple_features_model_data",
|
||||||
srcs = [
|
srcs = [
|
||||||
"tiny_conv_model_data.cc",
|
"simple_features/tiny_conv_simple_features_model_data.cc",
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"tiny_conv_model_data.h",
|
"simple_features/tiny_conv_simple_features_model_data.h",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "features_test_data",
|
name = "simple_features_test_data",
|
||||||
srcs = [
|
srcs = [
|
||||||
"no_features_data.cc",
|
"simple_features/no_simple_features_data.cc",
|
||||||
"yes_features_data.cc",
|
"simple_features/yes_simple_features_data.cc",
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"no_features_data.h",
|
"simple_features/no_simple_features_data.h",
|
||||||
"yes_features_data.h",
|
"simple_features/yes_simple_features_data.h",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,10 +48,10 @@ tflite_micro_cc_test(
|
|||||||
"micro_speech_test.cc",
|
"micro_speech_test.cc",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":features_test_data",
|
|
||||||
":tiny_conv_model_data",
|
|
||||||
"//tensorflow/lite:schema_fbs_version",
|
"//tensorflow/lite:schema_fbs_version",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_features_test_data",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:tiny_conv_micro_features_model_data",
|
||||||
"//tensorflow/lite/experimental/micro/kernels:all_ops_resolver",
|
"//tensorflow/lite/experimental/micro/kernels:all_ops_resolver",
|
||||||
"//tensorflow/lite/experimental/micro/kernels:micro_ops",
|
"//tensorflow/lite/experimental/micro/kernels:micro_ops",
|
||||||
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
@ -60,45 +60,66 @@ tflite_micro_cc_test(
|
|||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "preprocessor_test_data",
|
name = "audio_sample_test_data",
|
||||||
srcs = [
|
srcs = [
|
||||||
"no_30ms_sample_data.cc",
|
"no_30ms_sample_data.cc",
|
||||||
"no_power_spectrum_data.cc",
|
|
||||||
"yes_30ms_sample_data.cc",
|
"yes_30ms_sample_data.cc",
|
||||||
"yes_power_spectrum_data.cc",
|
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"no_30ms_sample_data.h",
|
"no_30ms_sample_data.h",
|
||||||
"no_power_spectrum_data.h",
|
|
||||||
"yes_30ms_sample_data.h",
|
"yes_30ms_sample_data.h",
|
||||||
"yes_power_spectrum_data.h",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "preprocessor_reference",
|
name = "audio_large_sample_test_data",
|
||||||
srcs = [
|
srcs = [
|
||||||
"preprocessor.cc",
|
"no_1000ms_sample_data.cc",
|
||||||
|
"yes_1000ms_sample_data.cc",
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"preprocessor.h",
|
"no_1000ms_sample_data.h",
|
||||||
|
"yes_1000ms_sample_data.h",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "simple_features_generator_test_data",
|
||||||
|
srcs = [
|
||||||
|
"simple_features/no_power_spectrum_data.cc",
|
||||||
|
"simple_features/yes_power_spectrum_data.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"simple_features/no_power_spectrum_data.h",
|
||||||
|
"simple_features/yes_power_spectrum_data.h",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "simple_features_generator_reference",
|
||||||
|
srcs = [
|
||||||
|
"simple_features/simple_features_generator.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"simple_features/simple_features_generator.h",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":model_settings",
|
":simple_model_settings",
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
tflite_micro_cc_test(
|
tflite_micro_cc_test(
|
||||||
name = "preprocessor_reference_test",
|
name = "simple_features_generator_reference_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
"preprocessor_test.cc",
|
"simple_features/simple_features_generator_test.cc",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":model_settings",
|
":audio_sample_test_data",
|
||||||
":preprocessor_reference",
|
":simple_features_generator_reference",
|
||||||
":preprocessor_test_data",
|
":simple_features_generator_test_data",
|
||||||
|
":simple_model_settings",
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
@ -106,29 +127,30 @@ tflite_micro_cc_test(
|
|||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "preprocessor_fixed",
|
name = "simple_features_generator_fixed",
|
||||||
srcs = [
|
srcs = [
|
||||||
"fixed_point/preprocessor.cc",
|
"simple_features/fixed_point/simple_features_generator.cc",
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"preprocessor.h",
|
"simple_features/simple_features_generator.h",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":model_settings",
|
":simple_model_settings",
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
tflite_micro_cc_test(
|
tflite_micro_cc_test(
|
||||||
name = "preprocessor_fixed_test",
|
name = "simple_features_generator_fixed_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
"preprocessor_test.cc",
|
"simple_features/simple_features_generator_test.cc",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":model_settings",
|
":audio_sample_test_data",
|
||||||
":preprocessor_fixed",
|
":simple_features_generator_fixed",
|
||||||
":preprocessor_test_data",
|
":simple_features_generator_test_data",
|
||||||
|
":simple_model_settings",
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
@ -144,9 +166,25 @@ cc_library(
|
|||||||
"audio_provider.h",
|
"audio_provider.h",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":model_settings",
|
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "audio_provider_mock",
|
||||||
|
srcs = [
|
||||||
|
"audio_provider_mock.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"audio_provider.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":audio_large_sample_test_data",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -157,9 +195,24 @@ tflite_micro_cc_test(
|
|||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":audio_provider",
|
":audio_provider",
|
||||||
":model_settings",
|
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "audio_provider_mock_test",
|
||||||
|
srcs = [
|
||||||
|
"audio_provider_mock_test.cc",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":audio_large_sample_test_data",
|
||||||
|
":audio_provider_mock",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -174,10 +227,10 @@ cc_library(
|
|||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":audio_provider",
|
":audio_provider",
|
||||||
":model_settings",
|
|
||||||
":preprocessor_reference",
|
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_features_generator",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -189,9 +242,41 @@ tflite_micro_cc_test(
|
|||||||
deps = [
|
deps = [
|
||||||
":audio_provider",
|
":audio_provider",
|
||||||
":feature_provider",
|
":feature_provider",
|
||||||
":model_settings",
|
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "feature_provider_mock",
|
||||||
|
srcs = [
|
||||||
|
"feature_provider.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"feature_provider.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":audio_provider_mock",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_features_generator",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "feature_provider_mock_test",
|
||||||
|
srcs = [
|
||||||
|
"feature_provider_mock_test.cc",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":feature_provider_mock",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_features_test_data",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -205,9 +290,9 @@ cc_library(
|
|||||||
"recognize_commands.h",
|
"recognize_commands.h",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":model_settings",
|
|
||||||
"//tensorflow/lite/c:c_api_internal",
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -235,11 +320,29 @@ cc_binary(
|
|||||||
deps = [
|
deps = [
|
||||||
":audio_provider",
|
":audio_provider",
|
||||||
":feature_provider",
|
":feature_provider",
|
||||||
":model_settings",
|
|
||||||
":recognize_commands",
|
":recognize_commands",
|
||||||
":tiny_conv_model_data",
|
|
||||||
"//tensorflow/lite:schema_fbs_version",
|
"//tensorflow/lite:schema_fbs_version",
|
||||||
"//tensorflow/lite/experimental/micro:micro_framework",
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:tiny_conv_micro_features_model_data",
|
||||||
|
"//tensorflow/lite/experimental/micro/kernels:all_ops_resolver",
|
||||||
|
"//tensorflow/lite/schema:schema_fbs",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_binary(
|
||||||
|
name = "micro_speech_mock",
|
||||||
|
srcs = [
|
||||||
|
"main.cc",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":audio_provider_mock",
|
||||||
|
":feature_provider",
|
||||||
|
":recognize_commands",
|
||||||
|
"//tensorflow/lite:schema_fbs_version",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:micro_model_settings",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech/micro_features:tiny_conv_micro_features_model_data",
|
||||||
"//tensorflow/lite/experimental/micro/kernels:all_ops_resolver",
|
"//tensorflow/lite/experimental/micro/kernels:all_ops_resolver",
|
||||||
"//tensorflow/lite/schema:schema_fbs",
|
"//tensorflow/lite/schema:schema_fbs",
|
||||||
],
|
],
|
||||||
|
@ -17,6 +17,7 @@ ifneq ($(filter CMSIS,$(ALL_TAGS)),)
|
|||||||
CMSIS_PREPROCESSOR_HDRS := \
|
CMSIS_PREPROCESSOR_HDRS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/CMSIS/hanning.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/CMSIS/hanning.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/CMSIS/sin_1k.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/CMSIS/sin_1k.h \
|
||||||
|
third_party/CMSIS_ext/README.md \
|
||||||
third_party/CMSIS_ext/arm_cmplx_mag_squared_q10p6.h
|
third_party/CMSIS_ext/arm_cmplx_mag_squared_q10p6.h
|
||||||
|
|
||||||
PREPROCESSOR_TEST_SRCS += $(CMSIS_PREPROCESSOR_SRCS)
|
PREPROCESSOR_TEST_SRCS += $(CMSIS_PREPROCESSOR_SRCS)
|
||||||
@ -43,6 +44,7 @@ ifneq ($(filter CMSIS,$(ALL_TAGS)),)
|
|||||||
$(MAKEFILE_DIR)/downloads/cmsis/CMSIS/DSP/Source/StatisticsFunctions/arm_max_q7.c
|
$(MAKEFILE_DIR)/downloads/cmsis/CMSIS/DSP/Source/StatisticsFunctions/arm_max_q7.c
|
||||||
|
|
||||||
THIRD_PARTY_CC_HDRS += \
|
THIRD_PARTY_CC_HDRS += \
|
||||||
|
third_party/cmsis/LICENSE.txt \
|
||||||
third_party/cmsis/CMSIS/Core/Include/cmsis_compiler.h \
|
third_party/cmsis/CMSIS/Core/Include/cmsis_compiler.h \
|
||||||
third_party/cmsis/CMSIS/Core/Include/cmsis_gcc.h \
|
third_party/cmsis/CMSIS/Core/Include/cmsis_gcc.h \
|
||||||
third_party/cmsis/CMSIS/Core/Include/cmsis_version.h \
|
third_party/cmsis/CMSIS/Core/Include/cmsis_version.h \
|
||||||
|
@ -1,106 +1,349 @@
|
|||||||
|
|
||||||
|
INCLUDES += \
|
||||||
|
-I$(MAKEFILE_DIR)/downloads/kissfft
|
||||||
|
|
||||||
|
PROJECT_INCLUDES += \
|
||||||
|
third_party/kissfft
|
||||||
|
|
||||||
|
KISSFFT_LIB_SRCS := \
|
||||||
|
$(MAKEFILE_DIR)/downloads/kissfft/kiss_fft.c \
|
||||||
|
$(MAKEFILE_DIR)/downloads/kissfft/tools/kiss_fftr.c
|
||||||
|
|
||||||
|
KISSFFT_LIB_HDRS := \
|
||||||
|
$(MAKEFILE_DIR)/downloads/kissfft/COPYING \
|
||||||
|
$(MAKEFILE_DIR)/downloads/kissfft/kiss_fft.h \
|
||||||
|
$(MAKEFILE_DIR)/downloads/kissfft/_kiss_fft_guts.h \
|
||||||
|
$(MAKEFILE_DIR)/downloads/kissfft/tools/kiss_fftr.h
|
||||||
|
|
||||||
MICRO_SPEECH_TEST_SRCS := \
|
MICRO_SPEECH_TEST_SRCS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_features_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_features_data.cc
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc
|
||||||
|
|
||||||
MICRO_SPEECH_TEST_HDRS := \
|
MICRO_SPEECH_TEST_HDRS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_features_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_features_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \
|
||||||
|
|
||||||
PREPROCESSOR_TEST_SRCS := \
|
SIMPLE_FEATURES_GENERATOR_TEST_SRCS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor_test.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator_test.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_power_spectrum_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/no_power_spectrum_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_power_spectrum_data.cc
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.cc
|
||||||
|
|
||||||
PREPROCESSOR_TEST_HDRS := \
|
SIMPLE_FEATURES_GENERATOR_TEST_HDRS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_model_settings.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/no_30ms_sample_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/yes_30ms_sample_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h
|
||||||
|
|
||||||
|
MICRO_FEATURES_LIB_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_util.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend_util.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_lut.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_util.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_util.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_util.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_util.cc \
|
||||||
|
$(KISSFFT_LIB_SRCS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_LIB_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/bits.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_lut.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_util.h \
|
||||||
|
$(KISSFFT_LIB_HDRS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_FFT_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.cc \
|
||||||
|
$(KISSFFT_LIB_SRCS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_FFT_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h \
|
||||||
|
$(KISSFFT_LIB_HDRS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_FILTERBANK_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_util.cc
|
||||||
|
|
||||||
|
MICRO_FEATURES_FILTERBANK_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h
|
||||||
|
|
||||||
|
MICRO_FEATURES_FRONTEND_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend_test.cc \
|
||||||
|
$(MICRO_FEATURES_LIB_SRCS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_FRONTEND_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend_util.h \
|
||||||
|
$(MICRO_FEATURES_LIB_HDRS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_LOG_SCALE_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_lut.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_util.cc
|
||||||
|
|
||||||
|
MICRO_FEATURES_LOG_SCALE_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_lut.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/bits.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h
|
||||||
|
|
||||||
|
MICRO_FEATURES_NOISE_REDUCTION_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_util.cc
|
||||||
|
|
||||||
|
MICRO_FEATURES_NOISE_REDUCTION_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h
|
||||||
|
|
||||||
|
MICRO_FEATURES_PCAN_GAIN_CONTROL_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_util.cc
|
||||||
|
|
||||||
|
MICRO_FEATURES_PCAN_GAIN_CONTROL_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h
|
||||||
|
|
||||||
|
MICRO_FEATURES_WINDOW_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_util.cc
|
||||||
|
|
||||||
|
MICRO_FEATURES_WINDOW_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_util.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h
|
||||||
|
|
||||||
|
MICRO_FEATURES_GENERATOR_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_features_generator.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.cc \
|
||||||
|
$(MICRO_FEATURES_LIB_SRCS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_GENERATOR_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_features_generator.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h \
|
||||||
|
$(MICRO_FEATURES_LIB_HDRS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_GENERATOR_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_features_generator_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_feature_data_slice.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_feature_data_slice.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.cc \
|
||||||
|
$(MICRO_FEATURES_GENERATOR_SRCS)
|
||||||
|
|
||||||
|
MICRO_FEATURES_GENERATOR_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_feature_data_slice.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_power_spectrum_data.h \
|
$(MICRO_FEATURES_GENERATOR_HDRS)
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_power_spectrum_data.h
|
|
||||||
|
|
||||||
AUDIO_PROVIDER_TEST_SRCS := \
|
AUDIO_PROVIDER_TEST_SRCS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider_test.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider_test.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.cc
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.cc
|
||||||
|
|
||||||
AUDIO_PROVIDER_TEST_HDRS := \
|
AUDIO_PROVIDER_TEST_HDRS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
||||||
|
|
||||||
|
AUDIO_PROVIDER_MOCK_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider_mock_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider_mock.cc
|
||||||
|
|
||||||
|
AUDIO_PROVIDER_MOCK_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
||||||
|
|
||||||
FEATURE_PROVIDER_TEST_SRCS := \
|
FEATURE_PROVIDER_TEST_SRCS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider_test.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider_test.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.cc \
|
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.cc
|
$(MICRO_FEATURES_GENERATOR_SRCS)
|
||||||
|
|
||||||
FEATURE_PROVIDER_TEST_HDRS := \
|
FEATURE_PROVIDER_TEST_HDRS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h \
|
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h
|
$(MICRO_FEATURES_GENERATOR_HDRS)
|
||||||
|
|
||||||
|
FEATURE_PROVIDER_MOCK_TEST_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider_test.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider_mock.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc \
|
||||||
|
$(MICRO_FEATURES_GENERATOR_SRCS)
|
||||||
|
|
||||||
|
FEATURE_PROVIDER_MOCK_TEST_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \
|
||||||
|
$(MICRO_FEATURES_GENERATOR_HDRS)
|
||||||
|
|
||||||
RECOGNIZE_COMMANDS_TEST_SRCS := \
|
RECOGNIZE_COMMANDS_TEST_SRCS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands_test.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands_test.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.cc
|
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.cc
|
||||||
|
|
||||||
RECOGNIZE_COMMANDS_TEST_HDRS := \
|
RECOGNIZE_COMMANDS_TEST_HDRS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.h
|
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.h
|
||||||
|
|
||||||
MICRO_SPEECH_SRCS := \
|
MICRO_SPEECH_SRCS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/main.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/main.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.cc \
|
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_features_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_features_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.cc \
|
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.cc \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.cc
|
$(MICRO_FEATURES_GENERATOR_SRCS)
|
||||||
|
|
||||||
MICRO_SPEECH_HDRS := \
|
MICRO_SPEECH_HDRS := \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h \
|
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/no_features_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/yes_features_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.h \
|
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.h \
|
||||||
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.h
|
$(MICRO_FEATURES_GENERATOR_HDRS)
|
||||||
|
|
||||||
|
MICRO_SPEECH_MOCK_SRCS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/main.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider_mock.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.cc \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.cc \
|
||||||
|
$(MICRO_FEATURES_GENERATOR_SRCS)
|
||||||
|
|
||||||
|
MICRO_SPEECH_MOCK_HDRS := \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_features_generator.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.h \
|
||||||
|
tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.h \
|
||||||
|
$(MICRO_FEATURES_GENERATOR_HDRS)
|
||||||
|
|
||||||
# Find any platform-specific rules for this example.
|
# Find any platform-specific rules for this example.
|
||||||
include $(wildcard tensorflow/lite/experimental/micro/examples/micro_speech/*/Makefile.inc)
|
include $(wildcard tensorflow/lite/experimental/micro/examples/micro_speech/*/Makefile.inc)
|
||||||
|
|
||||||
|
$(eval $(call microlite_test,micro_features_fft_test,\
|
||||||
|
$(MICRO_FEATURES_FFT_TEST_SRCS),$(MICRO_FEATURES_FFT_TEST_HDRS)))
|
||||||
|
|
||||||
|
$(eval $(call microlite_test,micro_features_filterbank_test,\
|
||||||
|
$(MICRO_FEATURES_FILTERBANK_TEST_SRCS),$(MICRO_FEATURES_FILTERBANK_TEST_HDRS)))
|
||||||
|
|
||||||
|
$(eval $(call microlite_test,micro_features_frontend_test,\
|
||||||
|
$(MICRO_FEATURES_FRONTEND_TEST_SRCS),$(MICRO_FEATURES_FRONTEND_TEST_HDRS)))
|
||||||
|
|
||||||
|
$(eval $(call microlite_test,micro_features_log_scale_test,\
|
||||||
|
$(MICRO_FEATURES_LOG_SCALE_TEST_SRCS),$(MICRO_FEATURES_LOG_SCALE_TEST_HDRS)))
|
||||||
|
|
||||||
|
$(eval $(call microlite_test,micro_features_noise_reduction_test,\
|
||||||
|
$(MICRO_FEATURES_NOISE_REDUCTION_TEST_SRCS),$(MICRO_FEATURES_NOISE_REDUCTION_TEST_HDRS)))
|
||||||
|
|
||||||
|
$(eval $(call microlite_test,micro_features_pcan_gain_control_test,\
|
||||||
|
$(MICRO_FEATURES_PCAN_GAIN_CONTROL_TEST_SRCS),$(MICRO_FEATURES_PCAN_GAIN_CONTROL_TEST_HDRS)))
|
||||||
|
|
||||||
|
$(eval $(call microlite_test,micro_features_window_test,\
|
||||||
|
$(MICRO_FEATURES_WINDOW_TEST_SRCS),$(MICRO_FEATURES_WINDOW_TEST_HDRS)))
|
||||||
|
|
||||||
|
# Test the code for feature generation.
|
||||||
|
$(eval $(call microlite_test,micro_features_generator_test,\
|
||||||
|
$(MICRO_FEATURES_GENERATOR_TEST_SRCS), $(MICRO_FEATURES_GENERATOR_TEST_HDRS)))
|
||||||
|
|
||||||
# Tests loading and running a speech model.
|
# Tests loading and running a speech model.
|
||||||
$(eval $(call microlite_test,micro_speech_test,\
|
$(eval $(call microlite_test,micro_speech_test,\
|
||||||
$(MICRO_SPEECH_TEST_SRCS),$(MICRO_SPEECH_TEST_HDRS)))
|
$(MICRO_SPEECH_TEST_SRCS),$(MICRO_SPEECH_TEST_HDRS)))
|
||||||
|
|
||||||
# Test the code for feature generation.
|
# Test the code for feature generation.
|
||||||
$(eval $(call microlite_test,preprocessor_test,\
|
$(eval $(call microlite_test,simple_features_generator_test,\
|
||||||
$(PREPROCESSOR_TEST_SRCS), $(PREPROCESSOR_TEST_HDRS)))
|
$(SIMPLE_FEATURES_GENERATOR_TEST_SRCS), $(SIMPLE_FEATURES_GENERATOR_TEST_HDRS)))
|
||||||
|
|
||||||
# Tests the audio provider module.
|
# Tests the audio provider module.
|
||||||
$(eval $(call microlite_test,audio_provider_test,\
|
$(eval $(call microlite_test,audio_provider_test,\
|
||||||
$(AUDIO_PROVIDER_TEST_SRCS),$(AUDIO_PROVIDER_TEST_HDRS)))
|
$(AUDIO_PROVIDER_TEST_SRCS),$(AUDIO_PROVIDER_TEST_HDRS)))
|
||||||
|
|
||||||
|
# Tests the audio provider mock module.
|
||||||
|
$(eval $(call microlite_test,audio_provider_mock_test,\
|
||||||
|
$(AUDIO_PROVIDER_MOCK_TEST_SRCS),$(AUDIO_PROVIDER_MOCK_TEST_HDRS)))
|
||||||
|
|
||||||
# Tests the feature provider module.
|
# Tests the feature provider module.
|
||||||
$(eval $(call microlite_test,feature_provider_test,\
|
$(eval $(call microlite_test,feature_provider_test,\
|
||||||
$(FEATURE_PROVIDER_TEST_SRCS),$(FEATURE_PROVIDER_TEST_HDRS)))
|
$(FEATURE_PROVIDER_TEST_SRCS),$(FEATURE_PROVIDER_TEST_HDRS)))
|
||||||
|
|
||||||
# Tests the feature provider module.
|
# Tests the feature provider module using the mock audio provider.
|
||||||
|
$(eval $(call microlite_test,feature_provider_mock_test,\
|
||||||
|
$(FEATURE_PROVIDER_MOCK_TEST_SRCS),$(FEATURE_PROVIDER_MOCK_TEST_HDRS)))
|
||||||
|
|
||||||
|
# Tests the command recognizer module.
|
||||||
$(eval $(call microlite_test,recognize_commands_test,\
|
$(eval $(call microlite_test,recognize_commands_test,\
|
||||||
$(RECOGNIZE_COMMANDS_TEST_SRCS),$(RECOGNIZE_COMMANDS_TEST_HDRS)))
|
$(RECOGNIZE_COMMANDS_TEST_SRCS),$(RECOGNIZE_COMMANDS_TEST_HDRS)))
|
||||||
|
|
||||||
# Builds a standalone speech command recognizer binary.
|
# Builds a standalone speech command recognizer binary.
|
||||||
$(eval $(call microlite_test,micro_speech,\
|
$(eval $(call microlite_test,micro_speech,\
|
||||||
$(MICRO_SPEECH_SRCS),$(MICRO_SPEECH_HDRS)))
|
$(MICRO_SPEECH_SRCS),$(MICRO_SPEECH_HDRS)))
|
||||||
|
|
||||||
|
# Builds a standalone speech command recognizer binary using fake audio input.
|
||||||
|
$(eval $(call microlite_test,micro_speech_mock,\
|
||||||
|
$(MICRO_SPEECH_MOCK_SRCS),$(MICRO_SPEECH_MOCK_HDRS)))
|
||||||
|
@ -83,7 +83,8 @@ If you see a compiling error on older machines, try leaving out the `--copt` arg
|
|||||||
```
|
```
|
||||||
bazel run tensorflow/examples/speech_commands:freeze -- \
|
bazel run tensorflow/examples/speech_commands:freeze -- \
|
||||||
--model_architecture=tiny_conv --window_stride=20 --preprocess=average \
|
--model_architecture=tiny_conv --window_stride=20 --preprocess=average \
|
||||||
--wanted_words="yes,no" --quantize=1 --output_file=/tmp/tiny_conv.pb
|
--wanted_words="yes,no" --quantize=1 --output_file=/tmp/tiny_conv.pb \
|
||||||
|
--start_checkpoint=/tmp/speech_commands_train/tiny_conv.ckpt-18000
|
||||||
```
|
```
|
||||||
|
|
||||||
The next step is to create a TensorFlow Lite file from the frozen graph:
|
The next step is to create a TensorFlow Lite file from the frozen graph:
|
||||||
@ -99,5 +100,5 @@ bazel run tensorflow/lite/toco:toco -- \
|
|||||||
Finally, convert the file into a C source file that can be compiled into an embedded system:
|
Finally, convert the file into a C source file that can be compiled into an embedded system:
|
||||||
|
|
||||||
```
|
```
|
||||||
xxd -i /tmp/tiny_conv.tflite > /tmp/tiny_conv_model_data.cc
|
xxd -i /tmp/tiny_conv.tflite > /tmp/tiny_conv_simple_features_model_data.cc
|
||||||
```
|
```
|
||||||
|
@ -5,7 +5,7 @@ ifeq ($(TARGET), apollo3evb)
|
|||||||
$(AP3_MICRO_DIR)/../preprocessor.cc \
|
$(AP3_MICRO_DIR)/../preprocessor.cc \
|
||||||
$(AP3_MICRO_DIR)/pushbutton_main.c \
|
$(AP3_MICRO_DIR)/pushbutton_main.c \
|
||||||
$(AP3_MICRO_DIR)/pushbutton_test.cc \
|
$(AP3_MICRO_DIR)/pushbutton_test.cc \
|
||||||
$(AP3_MICRO_DIR)/../tiny_conv_model_data.cc \
|
$(AP3_MICRO_DIR)/../simple_features/tiny_conv_simple_features_model_data.cc \
|
||||||
$(APOLLO3_SDK)/devices/am_devices_led.c
|
$(APOLLO3_SDK)/devices/am_devices_led.c
|
||||||
ALL_SRCS += $(PUSHBUTTON_MICRO_SPEECH_TEST_SRCS)
|
ALL_SRCS += $(PUSHBUTTON_MICRO_SPEECH_TEST_SRCS)
|
||||||
PUSHBUTTON_MICRO_SPEECH_TEST_OBJS := $(addprefix $(OBJDIR), \
|
PUSHBUTTON_MICRO_SPEECH_TEST_OBJS := $(addprefix $(OBJDIR), \
|
||||||
@ -24,8 +24,8 @@ ifeq ($(TARGET), apollo3evb)
|
|||||||
PUSHBUTTON_CMSIS_SPEECH_TEST_SRCS := \
|
PUSHBUTTON_CMSIS_SPEECH_TEST_SRCS := \
|
||||||
$(AP3_MICRO_DIR)/pushbutton_main.c \
|
$(AP3_MICRO_DIR)/pushbutton_main.c \
|
||||||
$(AP3_MICRO_DIR)/pushbutton_test.cc \
|
$(AP3_MICRO_DIR)/pushbutton_test.cc \
|
||||||
$(AP3_MICRO_DIR)/../tiny_conv_model_data.cc \
|
$(AP3_MICRO_DIR)/../simple_features/tiny_conv_simple_features_model_data.cc \
|
||||||
$(CMSIS_DIR)/preprocessor.cc \
|
$(CMSIS_DIR)/simple_features_generator.cc \
|
||||||
$(CMSIS_EXT_DIR)/arm_cmplx_mag_squared_q10p6.c \
|
$(CMSIS_EXT_DIR)/arm_cmplx_mag_squared_q10p6.c \
|
||||||
$(CMSIS_DIR)/hanning.c \
|
$(CMSIS_DIR)/hanning.c \
|
||||||
$(APOLLO3_SDK)/devices/am_devices_led.c \
|
$(APOLLO3_SDK)/devices/am_devices_led.c \
|
||||||
|
@ -17,8 +17,8 @@ limitations under the License.
|
|||||||
* micro_speech_test.cc */
|
* micro_speech_test.cc */
|
||||||
|
|
||||||
#include "tensorflow/lite/c/c_api_internal.h"
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/tiny_conv_simple_features_model_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h"
|
#include "tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_interpreter.h"
|
#include "tensorflow/lite/experimental/micro/micro_interpreter.h"
|
||||||
@ -32,20 +32,36 @@ uint8_t g_unknown_score = 0;
|
|||||||
uint8_t g_yes_score = 0;
|
uint8_t g_yes_score = 0;
|
||||||
uint8_t g_no_score = 0;
|
uint8_t g_no_score = 0;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
TfLiteStatus GenerateSimpleFeatures_1sec(tflite::ErrorReporter* error_reporter,
|
||||||
|
const int16_t* input,
|
||||||
|
uint8_t* output) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 49; i++) {
|
||||||
|
GenerateSimpleFeatures(error_reporter, input + i * 320, 480, 43,
|
||||||
|
output + i * 43);
|
||||||
|
}
|
||||||
|
return kTfLiteOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
TF_LITE_MICRO_TESTS_BEGIN
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(TestPreprocessor) {
|
TF_LITE_MICRO_TEST(TestSimpleFeaturesGenerator) {
|
||||||
tflite::MicroErrorReporter micro_error_reporter;
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
uint8_t preprocessed_data[43 * 49];
|
uint8_t preprocessed_data[43 * 49];
|
||||||
TfLiteStatus preprocess_1sec_status =
|
TfLiteStatus generate_1sec_status = GenerateSimpleFeatures_1sec(
|
||||||
Preprocess_1sec(error_reporter, captured_data, preprocessed_data);
|
error_reporter, captured_data, preprocessed_data);
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, preprocess_1sec_status);
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, generate_1sec_status);
|
||||||
|
|
||||||
// Map the model into a usable data structure. This doesn't involve any
|
// Map the model into a usable data structure. This doesn't involve any
|
||||||
// copying or parsing, it's a very lightweight operation.
|
// copying or parsing, it's a very lightweight operation.
|
||||||
const tflite::Model* model = ::tflite::GetModel(g_tiny_conv_model_data);
|
const tflite::Model* model =
|
||||||
|
::tflite::GetModel(g_tiny_conv_simple_features_model_data);
|
||||||
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
||||||
error_reporter->Report(
|
error_reporter->Report(
|
||||||
"Model provided is schema version %d not equal "
|
"Model provided is schema version %d not equal "
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int16_t g_dummy_audio_data[kMaxAudioSampleSize];
|
int16_t g_dummy_audio_data[kMaxAudioSampleSize];
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
int16_t g_dummy_audio_data[kMaxAudioSampleSize];
|
||||||
|
int32_t g_latest_audio_timestamp = 0;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TfLiteStatus GetAudioSamples(tflite::ErrorReporter* error_reporter,
|
||||||
|
int start_ms, int duration_ms,
|
||||||
|
int* audio_samples_size, int16_t** audio_samples) {
|
||||||
|
const int yes_start = (0 * kAudioSampleFrequency) / 1000;
|
||||||
|
const int yes_end = (1000 * kAudioSampleFrequency) / 1000;
|
||||||
|
const int no_start = (4000 * kAudioSampleFrequency) / 1000;
|
||||||
|
const int no_end = (5000 * kAudioSampleFrequency) / 1000;
|
||||||
|
const int wraparound = (8000 * kAudioSampleFrequency) / 1000;
|
||||||
|
const int start_sample = (start_ms * kAudioSampleFrequency) / 1000;
|
||||||
|
for (int i = 0; i < kMaxAudioSampleSize; ++i) {
|
||||||
|
const int sample_index = (start_sample + i) % wraparound;
|
||||||
|
int16_t sample;
|
||||||
|
if ((sample_index >= yes_start) && (sample_index < yes_end)) {
|
||||||
|
sample = g_yes_1000ms_sample_data[sample_index - yes_start];
|
||||||
|
} else if ((sample_index >= no_start) && (sample_index < no_end)) {
|
||||||
|
sample = g_no_1000ms_sample_data[sample_index - no_start];
|
||||||
|
} else {
|
||||||
|
sample = 0;
|
||||||
|
}
|
||||||
|
g_dummy_audio_data[i] = sample;
|
||||||
|
}
|
||||||
|
*audio_samples_size = kMaxAudioSampleSize;
|
||||||
|
*audio_samples = g_dummy_audio_data;
|
||||||
|
return kTfLiteOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t LatestAudioTimestamp() {
|
||||||
|
g_latest_audio_timestamp += 100;
|
||||||
|
return g_latest_audio_timestamp;
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_1000ms_sample_data.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_1000ms_sample_data.h"
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(TestAudioProviderMock) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
int audio_samples_size = 0;
|
||||||
|
int16_t* audio_samples = nullptr;
|
||||||
|
TfLiteStatus get_status =
|
||||||
|
GetAudioSamples(error_reporter, 0, kFeatureSliceDurationMs,
|
||||||
|
&audio_samples_size, &audio_samples);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status);
|
||||||
|
TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize);
|
||||||
|
TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr);
|
||||||
|
for (int i = 0; i < audio_samples_size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(g_yes_1000ms_sample_data[i], audio_samples[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
get_status = GetAudioSamples(error_reporter, 500, kFeatureSliceDurationMs,
|
||||||
|
&audio_samples_size, &audio_samples);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status);
|
||||||
|
TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize);
|
||||||
|
TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr);
|
||||||
|
for (int i = 0; i < audio_samples_size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(g_yes_1000ms_sample_data[i + 8000],
|
||||||
|
audio_samples[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
get_status = GetAudioSamples(error_reporter, 1500, kFeatureSliceDurationMs,
|
||||||
|
&audio_samples_size, &audio_samples);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status);
|
||||||
|
TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize);
|
||||||
|
TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr);
|
||||||
|
for (int i = 0; i < audio_samples_size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(0, audio_samples[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
get_status = GetAudioSamples(error_reporter, 12250, kFeatureSliceDurationMs,
|
||||||
|
&audio_samples_size, &audio_samples);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status);
|
||||||
|
TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize);
|
||||||
|
TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr);
|
||||||
|
for (int i = 0; i < audio_samples_size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(g_no_1000ms_sample_data[i + 4000],
|
||||||
|
audio_samples[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -18,7 +18,7 @@ limitations under the License.
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "tensorflow/lite/c/c_api_internal.h"
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
#include "AUDIO_DISCO_F746NG.h"
|
#include "AUDIO_DISCO_F746NG.h"
|
||||||
#include "SDRAM_DISCO_F746NG.h"
|
#include "SDRAM_DISCO_F746NG.h"
|
||||||
|
@ -16,8 +16,8 @@ limitations under the License.
|
|||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h"
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_features_generator.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
FeatureProvider::FeatureProvider(int feature_size, uint8_t* feature_data)
|
FeatureProvider::FeatureProvider(int feature_size, uint8_t* feature_data)
|
||||||
: feature_size_(feature_size),
|
: feature_size_(feature_size),
|
||||||
@ -48,6 +48,10 @@ TfLiteStatus FeatureProvider::PopulateFeatureData(
|
|||||||
int slices_needed = current_step - last_step;
|
int slices_needed = current_step - last_step;
|
||||||
// If this is the first call, make sure we don't use any cached information.
|
// If this is the first call, make sure we don't use any cached information.
|
||||||
if (is_first_run_) {
|
if (is_first_run_) {
|
||||||
|
TfLiteStatus init_status = InitializeMicroFeatures(error_reporter);
|
||||||
|
if (init_status != kTfLiteOk) {
|
||||||
|
return init_status;
|
||||||
|
}
|
||||||
is_first_run_ = false;
|
is_first_run_ = false;
|
||||||
slices_needed = kFeatureSliceCount;
|
slices_needed = kFeatureSliceCount;
|
||||||
}
|
}
|
||||||
@ -99,11 +103,12 @@ TfLiteStatus FeatureProvider::PopulateFeatureData(
|
|||||||
return kTfLiteError;
|
return kTfLiteError;
|
||||||
}
|
}
|
||||||
uint8_t* new_slice_data = feature_data_ + (new_slice * kFeatureSliceSize);
|
uint8_t* new_slice_data = feature_data_ + (new_slice * kFeatureSliceSize);
|
||||||
TfLiteStatus preprocess_status =
|
size_t num_samples_read;
|
||||||
Preprocess(error_reporter, audio_samples, audio_samples_size,
|
TfLiteStatus generate_status = GenerateMicroFeatures(
|
||||||
kFeatureSliceSize, new_slice_data);
|
error_reporter, audio_samples, audio_samples_size, kFeatureSliceSize,
|
||||||
if (preprocess_status != kTfLiteOk) {
|
new_slice_data, &num_samples_read);
|
||||||
return preprocess_status;
|
if (generate_status != kTfLiteOk) {
|
||||||
|
return generate_status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
/* 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 "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(TestFeatureProviderMockYes) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
uint8_t feature_data[kFeatureElementCount];
|
||||||
|
FeatureProvider feature_provider(kFeatureElementCount, feature_data);
|
||||||
|
|
||||||
|
int how_many_new_slices = 0;
|
||||||
|
TfLiteStatus populate_status = feature_provider.PopulateFeatureData(
|
||||||
|
error_reporter, /* last_time_in_ms= */ 0, /* time_in_ms= */ 970,
|
||||||
|
&how_many_new_slices);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, populate_status);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kFeatureSliceCount, how_many_new_slices);
|
||||||
|
|
||||||
|
for (int i = 0; i < kFeatureElementCount; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(g_yes_micro_f2e59fea_nohash_1_data[i],
|
||||||
|
feature_data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(TestFeatureProviderMockNo) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
uint8_t feature_data[kFeatureElementCount];
|
||||||
|
FeatureProvider feature_provider(kFeatureElementCount, feature_data);
|
||||||
|
|
||||||
|
int how_many_new_slices = 0;
|
||||||
|
TfLiteStatus populate_status = feature_provider.PopulateFeatureData(
|
||||||
|
error_reporter, /* last_time_in_ms= */ 4000, /* time_in_ms= */ 4970,
|
||||||
|
&how_many_new_slices);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, populate_status);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kFeatureSliceCount, how_many_new_slices);
|
||||||
|
|
||||||
|
for (int i = 0; i < kFeatureElementCount; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(g_no_micro_f9643d42_nohash_4_data[i],
|
||||||
|
feature_data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h"
|
||||||
#include "tensorflow/lite/c/c_api_internal.h"
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/audio_provider.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/feature_provider.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/recognize_commands.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.h"
|
|
||||||
#include "tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h"
|
#include "tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_interpreter.h"
|
#include "tensorflow/lite/experimental/micro/micro_interpreter.h"
|
||||||
@ -31,7 +31,8 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// Map the model into a usable data structure. This doesn't involve any
|
// Map the model into a usable data structure. This doesn't involve any
|
||||||
// copying or parsing, it's a very lightweight operation.
|
// copying or parsing, it's a very lightweight operation.
|
||||||
const tflite::Model* model = ::tflite::GetModel(g_tiny_conv_model_data);
|
const tflite::Model* model =
|
||||||
|
::tflite::GetModel(g_tiny_conv_micro_features_model_data);
|
||||||
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
||||||
error_reporter->Report(
|
error_reporter->Report(
|
||||||
"Model provided is schema version %d not equal "
|
"Model provided is schema version %d not equal "
|
||||||
@ -123,7 +124,8 @@ int main(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (is_new_command) {
|
if (is_new_command) {
|
||||||
error_reporter->Report("Heard %s (%d)", found_command, score);
|
error_reporter->Report("Heard %s (%d) @%dms", found_command, score,
|
||||||
|
current_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,300 @@
|
|||||||
|
# Library for generating feature vectors from audio data
|
||||||
|
|
||||||
|
package(
|
||||||
|
default_visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
licenses(["notice"]) # Apache 2.0
|
||||||
|
|
||||||
|
load(
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test.bzl",
|
||||||
|
"tflite_micro_cc_test",
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "micro_model_settings",
|
||||||
|
srcs = [
|
||||||
|
"micro_model_settings.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"micro_model_settings.h",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "tiny_conv_micro_features_model_data",
|
||||||
|
srcs = [
|
||||||
|
"tiny_conv_micro_features_model_data.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"tiny_conv_micro_features_model_data.h",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "micro_features_test_data",
|
||||||
|
srcs = [
|
||||||
|
"no_micro_features_data.cc",
|
||||||
|
"yes_micro_features_data.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"no_micro_features_data.h",
|
||||||
|
"yes_micro_features_data.h",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "bits",
|
||||||
|
hdrs = ["bits.h"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "static_alloc",
|
||||||
|
hdrs = ["static_alloc.h"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "fft",
|
||||||
|
srcs = [
|
||||||
|
"fft.cc",
|
||||||
|
"fft_util.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"fft.h",
|
||||||
|
"fft_util.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":micro_model_settings",
|
||||||
|
":static_alloc",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"@kissfft//:kiss_fftr_16",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "filterbank",
|
||||||
|
srcs = [
|
||||||
|
"filterbank.cc",
|
||||||
|
"filterbank_util.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"filterbank.h",
|
||||||
|
"filterbank_util.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":bits",
|
||||||
|
":fft",
|
||||||
|
":micro_model_settings",
|
||||||
|
":static_alloc",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "frontend",
|
||||||
|
srcs = [
|
||||||
|
"frontend.cc",
|
||||||
|
"frontend_util.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"frontend.h",
|
||||||
|
"frontend_util.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":bits",
|
||||||
|
":fft",
|
||||||
|
":filterbank",
|
||||||
|
":log_scale",
|
||||||
|
":micro_model_settings",
|
||||||
|
":noise_reduction",
|
||||||
|
":pcan_gain_control",
|
||||||
|
":window",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "log_scale",
|
||||||
|
srcs = [
|
||||||
|
"log_lut.cc",
|
||||||
|
"log_scale.cc",
|
||||||
|
"log_scale_util.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"log_lut.h",
|
||||||
|
"log_scale.h",
|
||||||
|
"log_scale_util.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":bits",
|
||||||
|
":micro_model_settings",
|
||||||
|
":static_alloc",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "noise_reduction",
|
||||||
|
srcs = [
|
||||||
|
"noise_reduction.cc",
|
||||||
|
"noise_reduction_util.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"noise_reduction.h",
|
||||||
|
"noise_reduction_util.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":micro_model_settings",
|
||||||
|
":static_alloc",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "pcan_gain_control",
|
||||||
|
srcs = [
|
||||||
|
"pcan_gain_control.cc",
|
||||||
|
"pcan_gain_control_util.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"pcan_gain_control.h",
|
||||||
|
"pcan_gain_control_util.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":bits",
|
||||||
|
":micro_model_settings",
|
||||||
|
":static_alloc",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "window",
|
||||||
|
srcs = [
|
||||||
|
"window.cc",
|
||||||
|
"window_util.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"window.h",
|
||||||
|
"window_util.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":micro_model_settings",
|
||||||
|
":static_alloc",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "micro_features_generator",
|
||||||
|
srcs = [
|
||||||
|
"micro_features_generator.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"micro_features_generator.h",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":frontend",
|
||||||
|
":micro_model_settings",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "micro_features_generator_test_data",
|
||||||
|
srcs = [
|
||||||
|
"no_feature_data_slice.cc",
|
||||||
|
"yes_feature_data_slice.cc",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"no_feature_data_slice.h",
|
||||||
|
"yes_feature_data_slice.h",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "fft_test",
|
||||||
|
srcs = ["fft_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":fft",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "filterbank_test",
|
||||||
|
srcs = ["filterbank_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":filterbank",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "frontend_test",
|
||||||
|
srcs = ["frontend_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":frontend",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "log_scale_test",
|
||||||
|
srcs = ["log_scale_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":log_scale",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "noise_reduction_test",
|
||||||
|
srcs = ["noise_reduction_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":noise_reduction",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "pcan_gain_control_test",
|
||||||
|
srcs = ["pcan_gain_control_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":pcan_gain_control",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "window_test",
|
||||||
|
srcs = ["window_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":window",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
tflite_micro_cc_test(
|
||||||
|
name = "micro_features_generator_test",
|
||||||
|
srcs = [
|
||||||
|
"micro_features_generator_test.cc",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":micro_features_generator",
|
||||||
|
":micro_features_generator_test_data",
|
||||||
|
":micro_model_settings",
|
||||||
|
"//tensorflow/lite/c:c_api_internal",
|
||||||
|
"//tensorflow/lite/experimental/micro:micro_framework",
|
||||||
|
"//tensorflow/lite/experimental/micro/examples/micro_speech:audio_sample_test_data",
|
||||||
|
"//tensorflow/lite/experimental/micro/testing:micro_test",
|
||||||
|
],
|
||||||
|
)
|
@ -0,0 +1,94 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_BITS_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_BITS_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
static inline int CountLeadingZeros32Slow(uint64_t n) {
|
||||||
|
int zeroes = 28;
|
||||||
|
if (n >> 16) zeroes -= 16, n >>= 16;
|
||||||
|
if (n >> 8) zeroes -= 8, n >>= 8;
|
||||||
|
if (n >> 4) zeroes -= 4, n >>= 4;
|
||||||
|
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int CountLeadingZeros32(uint32_t n) {
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
unsigned long result = 0; // NOLINT(runtime/int)
|
||||||
|
if (_BitScanReverse(&result, n)) {
|
||||||
|
return 31 - result;
|
||||||
|
}
|
||||||
|
return 32;
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
|
||||||
|
// Handle 0 as a special case because __builtin_clz(0) is undefined.
|
||||||
|
if (n == 0) {
|
||||||
|
return 32;
|
||||||
|
}
|
||||||
|
return __builtin_clz(n);
|
||||||
|
#else
|
||||||
|
return CountLeadingZeros32Slow(n);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int MostSignificantBit32(uint32_t n) {
|
||||||
|
return 32 - CountLeadingZeros32(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int CountLeadingZeros64Slow(uint64_t n) {
|
||||||
|
int zeroes = 60;
|
||||||
|
if (n >> 32) zeroes -= 32, n >>= 32;
|
||||||
|
if (n >> 16) zeroes -= 16, n >>= 16;
|
||||||
|
if (n >> 8) zeroes -= 8, n >>= 8;
|
||||||
|
if (n >> 4) zeroes -= 4, n >>= 4;
|
||||||
|
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int CountLeadingZeros64(uint64_t n) {
|
||||||
|
#if defined(_MSC_VER) && defined(_M_X64)
|
||||||
|
// MSVC does not have __buitin_clzll. Use _BitScanReverse64.
|
||||||
|
unsigned long result = 0; // NOLINT(runtime/int)
|
||||||
|
if (_BitScanReverse64(&result, n)) {
|
||||||
|
return 63 - result;
|
||||||
|
}
|
||||||
|
return 64;
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
// MSVC does not have __buitin_clzll. Compose two calls to _BitScanReverse
|
||||||
|
unsigned long result = 0; // NOLINT(runtime/int)
|
||||||
|
if ((n >> 32) && _BitScanReverse(&result, n >> 32)) {
|
||||||
|
return 31 - result;
|
||||||
|
}
|
||||||
|
if (_BitScanReverse(&result, n)) {
|
||||||
|
return 63 - result;
|
||||||
|
}
|
||||||
|
return 64;
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
|
||||||
|
// Handle 0 as a special case because __builtin_clzll(0) is undefined.
|
||||||
|
if (n == 0) {
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
return __builtin_clzll(n);
|
||||||
|
#else
|
||||||
|
return CountLeadingZeros64Slow(n);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int MostSignificantBit64(uint64_t n) {
|
||||||
|
return 64 - CountLeadingZeros64(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_BITS_H_
|
@ -0,0 +1,54 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define FIXED_POINT 16
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
// Internal test dependency placeholder1
|
||||||
|
// Internal test dependency placeholder2
|
||||||
|
#include "tools/kiss_fftr.h"
|
||||||
|
// Internal test dependency placeholder3
|
||||||
|
|
||||||
|
void FftCompute(struct FftState* state, const int16_t* input,
|
||||||
|
int input_scale_shift) {
|
||||||
|
const size_t input_size = state->input_size;
|
||||||
|
const size_t fft_size = state->fft_size;
|
||||||
|
|
||||||
|
int16_t* fft_input = state->input;
|
||||||
|
// First, scale the input by the given shift.
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < input_size; ++i) {
|
||||||
|
*fft_input++ = (*input++) << input_scale_shift;
|
||||||
|
}
|
||||||
|
// Zero out whatever else remains in the top part of the input.
|
||||||
|
for (; i < fft_size; ++i) {
|
||||||
|
*fft_input++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the FFT.
|
||||||
|
kiss_fftr(reinterpret_cast<const kiss_fftr_cfg>(state->scratch), state->input,
|
||||||
|
reinterpret_cast<kiss_fft_cpx*>(state->output));
|
||||||
|
}
|
||||||
|
|
||||||
|
void FftInit(struct FftState* state) {
|
||||||
|
// All the initialization is done in FftPopulateState()
|
||||||
|
}
|
||||||
|
|
||||||
|
void FftReset(struct FftState* state) {
|
||||||
|
memset(state->input, 0, state->fft_size * sizeof(*state->input));
|
||||||
|
memset(state->output, 0, (state->fft_size / 2 + 1) * sizeof(*state->output));
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FFT_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FFT_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
|
struct complex_int16_t {
|
||||||
|
int16_t real;
|
||||||
|
int16_t imag;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FftState {
|
||||||
|
int16_t input[kMaxAudioSampleSize];
|
||||||
|
struct complex_int16_t output[kMaxAudioSampleSize + 2];
|
||||||
|
size_t fft_size;
|
||||||
|
size_t input_size;
|
||||||
|
// This magic number was derived from KissFFT's estimate of how much space it
|
||||||
|
// will need to process the particular lengths and datatypes we need to for
|
||||||
|
// these model settings. This size will need to be recalculated for different
|
||||||
|
// models, but you will see a runtime error if it's not large enough.
|
||||||
|
char scratch[2848];
|
||||||
|
size_t scratch_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
void FftCompute(struct FftState* state, const int16_t* input,
|
||||||
|
int input_scale_shift);
|
||||||
|
|
||||||
|
void FftInit(struct FftState* state);
|
||||||
|
|
||||||
|
void FftReset(struct FftState* state);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FFT_H_
|
@ -0,0 +1,55 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int16_t kFakeWindow[] = {
|
||||||
|
0, 1151, 0, -5944, 0, 13311, 0, -21448, 0, 28327, 0, -32256, 0, 32255,
|
||||||
|
0, -28328, 0, 21447, 0, -13312, 0, 5943, 0, -1152, 0};
|
||||||
|
const int kScaleShift = 0;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FftTest_CheckOutputValues) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
struct FftState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FftPopulateState(
|
||||||
|
error_reporter, &state, sizeof(kFakeWindow) / sizeof(kFakeWindow[0])));
|
||||||
|
|
||||||
|
FftInit(&state);
|
||||||
|
FftCompute(&state, kFakeWindow, kScaleShift);
|
||||||
|
|
||||||
|
const struct complex_int16_t expected[] = {
|
||||||
|
{0, 0}, {-10, 9}, {-20, 0}, {-9, -10}, {0, 25}, {-119, 119},
|
||||||
|
{-887, 0}, {3000, 3000}, {0, -6401}, {-3000, 3000}, {886, 0}, {118, 119},
|
||||||
|
{0, 25}, {9, -10}, {19, 0}, {9, 9}, {0, 0}};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.fft_size / 2 + 1,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= state.fft_size / 2; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_NEAR(state.output[i].real, expected[i].real, 2);
|
||||||
|
TF_LITE_MICRO_EXPECT_NEAR(state.output[i].imag, expected[i].imag, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -0,0 +1,54 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.h"
|
||||||
|
|
||||||
|
#define FIXED_POINT 16
|
||||||
|
#include "kiss_fft.h"
|
||||||
|
#include "tools/kiss_fftr.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h"
|
||||||
|
|
||||||
|
int FftPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
struct FftState* state, size_t input_size) {
|
||||||
|
state->input_size = input_size;
|
||||||
|
state->fft_size = 1;
|
||||||
|
while (state->fft_size < state->input_size) {
|
||||||
|
state->fft_size <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(state->input,
|
||||||
|
(state->fft_size * sizeof(*state->input)));
|
||||||
|
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->output, ((state->fft_size / 2 + 1) * sizeof(*state->output) * 2));
|
||||||
|
|
||||||
|
// Ask kissfft how much memory it wants.
|
||||||
|
size_t scratch_size = 0;
|
||||||
|
kiss_fftr_cfg kfft_cfg =
|
||||||
|
kiss_fftr_alloc(state->fft_size, 0, nullptr, &scratch_size);
|
||||||
|
if (kfft_cfg != nullptr) {
|
||||||
|
error_reporter->Report("Kiss memory sizing failed.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(state->scratch, scratch_size);
|
||||||
|
state->scratch_size = scratch_size;
|
||||||
|
// Let kissfft configure the scratch space we just allocated
|
||||||
|
kfft_cfg = kiss_fftr_alloc(state->fft_size, 0, state->scratch, &scratch_size);
|
||||||
|
if (reinterpret_cast<char*>(kfft_cfg) != state->scratch) {
|
||||||
|
error_reporter->Report("Kiss memory preallocation strategy failed.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FFT_UTIL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FFT_UTIL_H_
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
// Prepares and FFT for the given input size.
|
||||||
|
int FftPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
struct FftState* state, size_t input_size);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FFT_UTIL_H_
|
@ -0,0 +1,135 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/bits.h"
|
||||||
|
|
||||||
|
void FilterbankConvertFftComplexToEnergy(struct FilterbankState* state,
|
||||||
|
struct complex_int16_t* fft_output,
|
||||||
|
int32_t* energy) {
|
||||||
|
const int end_index = state->end_index;
|
||||||
|
int i;
|
||||||
|
energy += state->start_index;
|
||||||
|
fft_output += state->start_index;
|
||||||
|
for (i = state->start_index; i < end_index; ++i) {
|
||||||
|
const int32_t real = fft_output->real;
|
||||||
|
const int32_t imag = fft_output->imag;
|
||||||
|
fft_output++;
|
||||||
|
const uint32_t mag_squared = (real * real) + (imag * imag);
|
||||||
|
*energy++ = mag_squared;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FilterbankAccumulateChannels(struct FilterbankState* state,
|
||||||
|
const int32_t* energy) {
|
||||||
|
uint64_t* work = state->work;
|
||||||
|
uint64_t weight_accumulator = 0;
|
||||||
|
uint64_t unweight_accumulator = 0;
|
||||||
|
|
||||||
|
const int16_t* channel_frequency_starts = state->channel_frequency_starts;
|
||||||
|
const int16_t* channel_weight_starts = state->channel_weight_starts;
|
||||||
|
const int16_t* channel_widths = state->channel_widths;
|
||||||
|
|
||||||
|
int num_channels_plus_1 = state->num_channels + 1;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < num_channels_plus_1; ++i) {
|
||||||
|
const int32_t* magnitudes = energy + *channel_frequency_starts++;
|
||||||
|
const int16_t* weights = state->weights + *channel_weight_starts;
|
||||||
|
const int16_t* unweights = state->unweights + *channel_weight_starts++;
|
||||||
|
const int width = *channel_widths++;
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < width; ++j) {
|
||||||
|
weight_accumulator += *weights++ * (static_cast<uint64_t>(*magnitudes));
|
||||||
|
unweight_accumulator +=
|
||||||
|
*unweights++ * (static_cast<uint64_t>(*magnitudes));
|
||||||
|
++magnitudes;
|
||||||
|
}
|
||||||
|
*work++ = weight_accumulator;
|
||||||
|
weight_accumulator = unweight_accumulator;
|
||||||
|
unweight_accumulator = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint16_t Sqrt32(uint32_t num) {
|
||||||
|
if (num == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
uint32_t res = 0;
|
||||||
|
int max_bit_number = 32 - MostSignificantBit32(num);
|
||||||
|
max_bit_number |= 1;
|
||||||
|
uint32_t bit = 1U << (31 - max_bit_number);
|
||||||
|
int iterations = (31 - max_bit_number) / 2 + 1;
|
||||||
|
while (iterations--) {
|
||||||
|
if (num >= res + bit) {
|
||||||
|
num -= res + bit;
|
||||||
|
res = (res >> 1U) + bit;
|
||||||
|
} else {
|
||||||
|
res >>= 1U;
|
||||||
|
}
|
||||||
|
bit >>= 2U;
|
||||||
|
}
|
||||||
|
// Do rounding - if we have the bits.
|
||||||
|
if (num > res && res != 0xFFFF) {
|
||||||
|
++res;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t Sqrt64(uint64_t num) {
|
||||||
|
// Take a shortcut and just use 32 bit operations if the upper word is all
|
||||||
|
// clear. This will cause a slight off by one issue for numbers close to 2^32,
|
||||||
|
// but it probably isn't going to matter (and gives us a big performance win).
|
||||||
|
if ((num >> 32) == 0) {
|
||||||
|
return Sqrt32(static_cast<uint32_t>(num));
|
||||||
|
}
|
||||||
|
uint64_t res = 0;
|
||||||
|
int max_bit_number = 64 - MostSignificantBit64(num);
|
||||||
|
max_bit_number |= 1;
|
||||||
|
uint64_t bit = 1ULL << (63 - max_bit_number);
|
||||||
|
int iterations = (63 - max_bit_number) / 2 + 1;
|
||||||
|
while (iterations--) {
|
||||||
|
if (num >= res + bit) {
|
||||||
|
num -= res + bit;
|
||||||
|
res = (res >> 1U) + bit;
|
||||||
|
} else {
|
||||||
|
res >>= 1U;
|
||||||
|
}
|
||||||
|
bit >>= 2U;
|
||||||
|
}
|
||||||
|
// Do rounding - if we have the bits.
|
||||||
|
if (num > res && res != 0xFFFFFFFFLL) {
|
||||||
|
++res;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t* FilterbankSqrt(struct FilterbankState* state, int scale_down_shift) {
|
||||||
|
const int num_channels = state->num_channels;
|
||||||
|
const int64_t* work = reinterpret_cast<int64_t*>(state->work + 1);
|
||||||
|
// Reuse the work buffer since we're fine clobbering it at this point to hold
|
||||||
|
// the output.
|
||||||
|
uint32_t* output = reinterpret_cast<uint32_t*>(state->work);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < num_channels; ++i) {
|
||||||
|
*output++ = Sqrt64(*work++) >> scale_down_shift;
|
||||||
|
}
|
||||||
|
return reinterpret_cast<uint32_t*>(state->work);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FilterbankReset(struct FilterbankState* state) {
|
||||||
|
memset(state->work, 0, (state->num_channels + 1) * sizeof(*state->work));
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FILTERBANK_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FILTERBANK_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
|
#define kFilterbankBits 12
|
||||||
|
|
||||||
|
struct FilterbankState {
|
||||||
|
int num_channels;
|
||||||
|
int start_index;
|
||||||
|
int end_index;
|
||||||
|
int16_t channel_frequency_starts[kFeatureSliceSize + 1];
|
||||||
|
int16_t channel_weight_starts[kFeatureSliceSize + 1];
|
||||||
|
int16_t channel_widths[kFeatureSliceSize + 1];
|
||||||
|
int16_t weights[316];
|
||||||
|
int16_t unweights[316];
|
||||||
|
uint64_t work[kFeatureSliceSize + 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Converts the relevant complex values of an FFT output into energy (the
|
||||||
|
// square magnitude).
|
||||||
|
void FilterbankConvertFftComplexToEnergy(struct FilterbankState* state,
|
||||||
|
struct complex_int16_t* fft_output,
|
||||||
|
int32_t* energy);
|
||||||
|
|
||||||
|
// Computes the mel-scale filterbank on the given energy array. Output is cached
|
||||||
|
// internally - to fetch it, you need to call FilterbankSqrt.
|
||||||
|
void FilterbankAccumulateChannels(struct FilterbankState* state,
|
||||||
|
const int32_t* energy);
|
||||||
|
|
||||||
|
// Applies an integer square root to the 64 bit intermediate values of the
|
||||||
|
// filterbank, and returns a pointer to them. Memory will be invalidated the
|
||||||
|
// next time FilterbankAccumulateChannels is called.
|
||||||
|
uint32_t* FilterbankSqrt(struct FilterbankState* state, int scale_down_shift);
|
||||||
|
|
||||||
|
void FilterbankReset(struct FilterbankState* state);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FILTERBANK_H_
|
@ -0,0 +1,228 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_util.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int kSampleRate = 1000;
|
||||||
|
const int kSpectrumSize = 17;
|
||||||
|
const int kStartIndex = 1;
|
||||||
|
const int kEndIndex = 15;
|
||||||
|
const int32_t kEnergy[] = {-1, 181, 400, 181, 625, 28322,
|
||||||
|
786769, 18000000, 40972801, 18000000, 784996, 28085,
|
||||||
|
625, 181, 361, -1, -1};
|
||||||
|
const uint64_t kWork[] = {1835887, 61162970173, 258694800000};
|
||||||
|
const int kScaleShift = 0;
|
||||||
|
|
||||||
|
// Test filterbank generation using scaled-down defaults.
|
||||||
|
class FilterbankTestConfig {
|
||||||
|
public:
|
||||||
|
FilterbankTestConfig() {
|
||||||
|
config_.num_channels = 2;
|
||||||
|
config_.lower_band_limit = 8.0;
|
||||||
|
config_.upper_band_limit = 450.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FilterbankConfig config_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckStartIndex) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.start_index, kStartIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckEndIndex) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.end_index, kEndIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckChannelFrequencyStarts) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
const int16_t expected[] = {0, 4, 8};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.channel_frequency_starts[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckChannelWeightStarts) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
const int16_t expected[] = {0, 8, 16};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.channel_weight_starts[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckChannelWidths) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
const int16_t expected[] = {8, 8, 8};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.channel_widths[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckWeights) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
const int16_t expected[] = {0, 3277, 2217, 1200, 222, 0, 0, 0,
|
||||||
|
0, 3376, 2468, 1591, 744, 0, 0, 0,
|
||||||
|
0, 4020, 3226, 2456, 1708, 983, 277, 0};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.channel_weight_starts[state.num_channels] +
|
||||||
|
state.channel_widths[state.num_channels],
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.weights[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckUnweights) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
const int16_t expected[] = {0, 819, 1879, 2896, 3874, 0, 0, 0,
|
||||||
|
0, 720, 1628, 2505, 3352, 0, 0, 0,
|
||||||
|
0, 76, 870, 1640, 2388, 3113, 3819, 0};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.channel_weight_starts[state.num_channels] +
|
||||||
|
state.channel_widths[state.num_channels],
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.unweights[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckConvertFftComplexToEnergy) {
|
||||||
|
struct FilterbankState state;
|
||||||
|
state.start_index = kStartIndex;
|
||||||
|
state.end_index = kEndIndex;
|
||||||
|
|
||||||
|
struct complex_int16_t fake_fft[] = {
|
||||||
|
{0, 0}, {-10, 9}, {-20, 0}, {-9, -10}, {0, 25}, {-119, 119},
|
||||||
|
{-887, 0}, {3000, 3000}, {0, -6401}, {-3000, 3000}, {886, 0}, {118, 119},
|
||||||
|
{0, 25}, {9, -10}, {19, 0}, {9, 9}, {0, 0}};
|
||||||
|
int32_t* energy = reinterpret_cast<int32_t*>(fake_fft);
|
||||||
|
FilterbankConvertFftComplexToEnergy(&state, fake_fft, energy);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = state.start_index; i < state.end_index; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(energy[i], kEnergy[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckAccumulateChannels) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
|
||||||
|
FilterbankAccumulateChannels(&state, kEnergy);
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1,
|
||||||
|
sizeof(kWork) / sizeof(kWork[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i <= state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.work[i], kWork[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FilterbankTest_CheckSqrt) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FilterbankTestConfig config;
|
||||||
|
struct FilterbankState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FilterbankPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kSampleRate, kSpectrumSize));
|
||||||
|
std::memcpy(state.work, kWork, sizeof(kWork));
|
||||||
|
|
||||||
|
uint32_t* scaled_filterbank = FilterbankSqrt(&state, kScaleShift);
|
||||||
|
|
||||||
|
const uint32_t expected[] = {247311, 508620};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(scaled_filterbank[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -0,0 +1,212 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_util.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h"
|
||||||
|
|
||||||
|
#define kFilterbankIndexAlignment 4
|
||||||
|
#define kFilterbankChannelBlockSize 4
|
||||||
|
|
||||||
|
void FilterbankFillConfigWithDefaults(struct FilterbankConfig* config) {
|
||||||
|
config->num_channels = 32;
|
||||||
|
config->lower_band_limit = 125.0f;
|
||||||
|
config->upper_band_limit = 7500.0f;
|
||||||
|
config->output_scale_shift = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float FreqToMel(float freq) {
|
||||||
|
return 1127.0 * log(1.0 + (freq / 700.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CalculateCenterFrequencies(const int num_channels,
|
||||||
|
const float lower_frequency_limit,
|
||||||
|
const float upper_frequency_limit,
|
||||||
|
float* center_frequencies) {
|
||||||
|
assert(lower_frequency_limit >= 0.0f);
|
||||||
|
assert(upper_frequency_limit > lower_frequency_limit);
|
||||||
|
|
||||||
|
const float mel_low = FreqToMel(lower_frequency_limit);
|
||||||
|
const float mel_hi = FreqToMel(upper_frequency_limit);
|
||||||
|
const float mel_span = mel_hi - mel_low;
|
||||||
|
const float mel_spacing = mel_span / (static_cast<float>(num_channels));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < num_channels; ++i) {
|
||||||
|
center_frequencies[i] = mel_low + (mel_spacing * (i + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void QuantizeFilterbankWeights(const float float_weight, int16_t* weight,
|
||||||
|
int16_t* unweight) {
|
||||||
|
*weight = floor(float_weight * (1 << kFilterbankBits) + 0.5);
|
||||||
|
*unweight = floor((1.0 - float_weight) * (1 << kFilterbankBits) + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FilterbankPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct FilterbankConfig* config,
|
||||||
|
struct FilterbankState* state, int sample_rate,
|
||||||
|
int spectrum_size) {
|
||||||
|
state->num_channels = config->num_channels;
|
||||||
|
const int num_channels_plus_1 = config->num_channels + 1;
|
||||||
|
|
||||||
|
// How should we align things to index counts given the byte alignment?
|
||||||
|
const int index_alignment =
|
||||||
|
(kFilterbankIndexAlignment < sizeof(int16_t)
|
||||||
|
? 1
|
||||||
|
: kFilterbankIndexAlignment / sizeof(int16_t));
|
||||||
|
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->channel_frequency_starts,
|
||||||
|
(num_channels_plus_1 * sizeof(*state->channel_frequency_starts)));
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->channel_weight_starts,
|
||||||
|
(num_channels_plus_1 * sizeof(*state->channel_weight_starts)));
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->channel_widths,
|
||||||
|
(num_channels_plus_1 * sizeof(*state->channel_widths)));
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(state->work,
|
||||||
|
(num_channels_plus_1 * sizeof(*state->work)));
|
||||||
|
|
||||||
|
float center_mel_freqs[kFeatureSliceSize + 1];
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
center_mel_freqs, (num_channels_plus_1 * sizeof(*center_mel_freqs)));
|
||||||
|
|
||||||
|
int16_t actual_channel_starts[kFeatureSliceSize + 1];
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
actual_channel_starts,
|
||||||
|
(num_channels_plus_1 * sizeof(*actual_channel_starts)));
|
||||||
|
|
||||||
|
int16_t actual_channel_widths[kFeatureSliceSize + 1];
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
actual_channel_widths,
|
||||||
|
(num_channels_plus_1 * sizeof(*actual_channel_widths)));
|
||||||
|
|
||||||
|
CalculateCenterFrequencies(num_channels_plus_1, config->lower_band_limit,
|
||||||
|
config->upper_band_limit, center_mel_freqs);
|
||||||
|
|
||||||
|
// Always exclude DC.
|
||||||
|
const float hz_per_sbin =
|
||||||
|
0.5 * sample_rate / (static_cast<float>(spectrum_size) - 1);
|
||||||
|
state->start_index = 1.5 + config->lower_band_limit / hz_per_sbin;
|
||||||
|
state->end_index = 0; // Initialized to zero here, but actually set below.
|
||||||
|
|
||||||
|
// For each channel, we need to figure out what frequencies belong to it, and
|
||||||
|
// how much padding we need to add so that we can efficiently multiply the
|
||||||
|
// weights and unweights for accumulation. To simplify the multiplication
|
||||||
|
// logic, all channels will have some multiplication to do (even if there are
|
||||||
|
// no frequencies that accumulate to that channel) - they will be directed to
|
||||||
|
// a set of zero weights.
|
||||||
|
int chan_freq_index_start = state->start_index;
|
||||||
|
int weight_index_start = 0;
|
||||||
|
int needs_zeros = 0;
|
||||||
|
|
||||||
|
int chan;
|
||||||
|
for (chan = 0; chan < num_channels_plus_1; ++chan) {
|
||||||
|
// Keep jumping frequencies until we overshoot the bound on this channel.
|
||||||
|
int freq_index = chan_freq_index_start;
|
||||||
|
while (FreqToMel((freq_index)*hz_per_sbin) <= center_mel_freqs[chan]) {
|
||||||
|
++freq_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int width = freq_index - chan_freq_index_start;
|
||||||
|
actual_channel_starts[chan] = chan_freq_index_start;
|
||||||
|
actual_channel_widths[chan] = width;
|
||||||
|
|
||||||
|
if (width == 0) {
|
||||||
|
// This channel doesn't actually get anything from the frequencies, it's
|
||||||
|
// always zero. We need then to insert some 'zero' weights into the
|
||||||
|
// output, and just redirect this channel to do a single multiplication at
|
||||||
|
// this point. For simplicity, the zeros are placed at the beginning of
|
||||||
|
// the weights arrays, so we have to go and update all the other
|
||||||
|
// weight_starts to reflect this shift (but only once).
|
||||||
|
state->channel_frequency_starts[chan] = 0;
|
||||||
|
state->channel_weight_starts[chan] = 0;
|
||||||
|
state->channel_widths[chan] = kFilterbankChannelBlockSize;
|
||||||
|
if (!needs_zeros) {
|
||||||
|
needs_zeros = 1;
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < chan; ++j) {
|
||||||
|
state->channel_weight_starts[j] += kFilterbankChannelBlockSize;
|
||||||
|
}
|
||||||
|
weight_index_start += kFilterbankChannelBlockSize;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// How far back do we need to go to ensure that we have the proper
|
||||||
|
// alignment?
|
||||||
|
const int aligned_start =
|
||||||
|
(chan_freq_index_start / index_alignment) * index_alignment;
|
||||||
|
const int aligned_width = (chan_freq_index_start - aligned_start + width);
|
||||||
|
const int padded_width =
|
||||||
|
(((aligned_width - 1) / kFilterbankChannelBlockSize) + 1) *
|
||||||
|
kFilterbankChannelBlockSize;
|
||||||
|
|
||||||
|
state->channel_frequency_starts[chan] = aligned_start;
|
||||||
|
state->channel_weight_starts[chan] = weight_index_start;
|
||||||
|
state->channel_widths[chan] = padded_width;
|
||||||
|
weight_index_start += padded_width;
|
||||||
|
}
|
||||||
|
chan_freq_index_start = freq_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate the two arrays to store the weights - weight_index_start contains
|
||||||
|
// the index of what would be the next set of weights that we would need to
|
||||||
|
// add, so that's how many weights we need to allocate.
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->weights, (weight_index_start * sizeof(*state->weights)));
|
||||||
|
for (int i = 0; i < weight_index_start; ++i) {
|
||||||
|
state->weights[i] = 0;
|
||||||
|
}
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->unweights, (weight_index_start * sizeof(*state->unweights)));
|
||||||
|
for (int i = 0; i < weight_index_start; ++i) {
|
||||||
|
state->unweights[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next pass, compute all the weights. Since everything has been memset to
|
||||||
|
// zero, we only need to fill in the weights that correspond to some frequency
|
||||||
|
// for a channel.
|
||||||
|
const float mel_low = FreqToMel(config->lower_band_limit);
|
||||||
|
for (chan = 0; chan < num_channels_plus_1; ++chan) {
|
||||||
|
int frequency = actual_channel_starts[chan];
|
||||||
|
const int num_frequencies = actual_channel_widths[chan];
|
||||||
|
const int frequency_offset =
|
||||||
|
frequency - state->channel_frequency_starts[chan];
|
||||||
|
const int weight_start = state->channel_weight_starts[chan];
|
||||||
|
const float denom_val = (chan == 0) ? mel_low : center_mel_freqs[chan - 1];
|
||||||
|
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < num_frequencies; ++j, ++frequency) {
|
||||||
|
const float weight =
|
||||||
|
(center_mel_freqs[chan] - FreqToMel(frequency * hz_per_sbin)) /
|
||||||
|
(center_mel_freqs[chan] - denom_val);
|
||||||
|
|
||||||
|
// Make the float into an integer for the weights (and unweights).
|
||||||
|
const int weight_index = weight_start + frequency_offset + j;
|
||||||
|
QuantizeFilterbankWeights(weight, state->weights + weight_index,
|
||||||
|
state->unweights + weight_index);
|
||||||
|
}
|
||||||
|
if (frequency > state->end_index) {
|
||||||
|
state->end_index = frequency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->end_index >= spectrum_size) {
|
||||||
|
error_reporter->Report("Filterbank end_index is above spectrum size.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FILTERBANK_UTIL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FILTERBANK_UTIL_H_
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
struct FilterbankConfig {
|
||||||
|
// number of frequency channel buckets for filterbank
|
||||||
|
int num_channels;
|
||||||
|
// maximum frequency to include
|
||||||
|
float upper_band_limit;
|
||||||
|
// minimum frequency to include
|
||||||
|
float lower_band_limit;
|
||||||
|
// unused
|
||||||
|
int output_scale_shift;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fills the frontendConfig with "sane" defaults.
|
||||||
|
void FilterbankFillConfigWithDefaults(struct FilterbankConfig* config);
|
||||||
|
|
||||||
|
// Allocates any buffers.
|
||||||
|
int FilterbankPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct FilterbankConfig* config,
|
||||||
|
struct FilterbankState* state, int sample_rate,
|
||||||
|
int spectrum_size);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FILTERBANK_UTIL_H_
|
@ -0,0 +1,70 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/bits.h"
|
||||||
|
|
||||||
|
struct FrontendOutput FrontendProcessSamples(struct FrontendState* state,
|
||||||
|
const int16_t* samples,
|
||||||
|
size_t num_samples,
|
||||||
|
size_t* num_samples_read) {
|
||||||
|
struct FrontendOutput output;
|
||||||
|
output.values = nullptr;
|
||||||
|
output.size = 0;
|
||||||
|
|
||||||
|
// Try to apply the window - if it fails, return and wait for more data.
|
||||||
|
if (!WindowProcessSamples(&state->window, samples, num_samples,
|
||||||
|
num_samples_read)) {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the FFT to the window's output (and scale it so that the fixed point
|
||||||
|
// FFT can have as much resolution as possible).
|
||||||
|
int input_shift =
|
||||||
|
15 - MostSignificantBit32(state->window.max_abs_output_value);
|
||||||
|
FftCompute(&state->fft, state->window.output, input_shift);
|
||||||
|
|
||||||
|
// We can re-ruse the fft's output buffer to hold the energy.
|
||||||
|
int32_t* energy = reinterpret_cast<int32_t*>(state->fft.output);
|
||||||
|
FilterbankConvertFftComplexToEnergy(&state->filterbank, state->fft.output,
|
||||||
|
energy);
|
||||||
|
FilterbankAccumulateChannels(&state->filterbank, energy);
|
||||||
|
uint32_t* scaled_filterbank = FilterbankSqrt(&state->filterbank, input_shift);
|
||||||
|
|
||||||
|
// Apply noise reduction.
|
||||||
|
NoiseReductionApply(&state->noise_reduction, scaled_filterbank);
|
||||||
|
|
||||||
|
if (state->pcan_gain_control.enable_pcan) {
|
||||||
|
PcanGainControlApply(&state->pcan_gain_control, scaled_filterbank);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the log and scale.
|
||||||
|
int correction_bits =
|
||||||
|
MostSignificantBit32(state->fft.fft_size) - 1 - (kFilterbankBits / 2);
|
||||||
|
uint16_t* logged_filterbank =
|
||||||
|
LogScaleApply(&state->log_scale, scaled_filterbank,
|
||||||
|
state->filterbank.num_channels, correction_bits);
|
||||||
|
|
||||||
|
output.size = state->filterbank.num_channels;
|
||||||
|
output.values = logged_filterbank;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrontendReset(struct FrontendState* state) {
|
||||||
|
WindowReset(&state->window);
|
||||||
|
FftReset(&state->fft);
|
||||||
|
FilterbankReset(&state->filterbank);
|
||||||
|
NoiseReductionReset(&state->noise_reduction);
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FRONTEND_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FRONTEND_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.h"
|
||||||
|
|
||||||
|
struct FrontendState {
|
||||||
|
struct WindowState window;
|
||||||
|
struct FftState fft;
|
||||||
|
struct FilterbankState filterbank;
|
||||||
|
struct NoiseReductionState noise_reduction;
|
||||||
|
struct PcanGainControlState pcan_gain_control;
|
||||||
|
struct LogScaleState log_scale;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FrontendOutput {
|
||||||
|
const uint16_t* values;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Main entry point to processing frontend samples. Updates num_samples_read to
|
||||||
|
// contain the number of samples that have been consumed from the input array.
|
||||||
|
// Returns a struct containing the generated output. If not enough samples were
|
||||||
|
// added to generate a feature vector, the returned size will be 0 and the
|
||||||
|
// values pointer will be NULL. Note that the output pointer will be invalidated
|
||||||
|
// as soon as FrontendProcessSamples is called again, so copy the contents
|
||||||
|
// elsewhere if you need to use them later.
|
||||||
|
struct FrontendOutput FrontendProcessSamples(struct FrontendState* state,
|
||||||
|
const int16_t* samples,
|
||||||
|
size_t num_samples,
|
||||||
|
size_t* num_samples_read);
|
||||||
|
|
||||||
|
void FrontendReset(struct FrontendState* state);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FRONTEND_H_
|
@ -0,0 +1,134 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend_util.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int kSampleRate = 1000;
|
||||||
|
const int kWindowSamples = 25;
|
||||||
|
const int kStepSamples = 10;
|
||||||
|
const int16_t kFakeAudioData[] = {
|
||||||
|
0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768,
|
||||||
|
0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768,
|
||||||
|
0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768};
|
||||||
|
|
||||||
|
// Test end-to-end frontend behaviors.
|
||||||
|
class FrontendTestConfig {
|
||||||
|
public:
|
||||||
|
FrontendTestConfig() {
|
||||||
|
config_.window.size_ms = 25;
|
||||||
|
config_.window.step_size_ms = 10;
|
||||||
|
config_.noise_reduction.smoothing_bits = 10;
|
||||||
|
config_.filterbank.num_channels = 2;
|
||||||
|
config_.filterbank.lower_band_limit = 8.0;
|
||||||
|
config_.filterbank.upper_band_limit = 450.0;
|
||||||
|
config_.noise_reduction.smoothing_bits = 10;
|
||||||
|
config_.noise_reduction.even_smoothing = 0.025;
|
||||||
|
config_.noise_reduction.odd_smoothing = 0.06;
|
||||||
|
config_.noise_reduction.min_signal_remaining = 0.05;
|
||||||
|
config_.pcan_gain_control.enable_pcan = true;
|
||||||
|
config_.pcan_gain_control.strength = 0.95;
|
||||||
|
config_.pcan_gain_control.offset = 80.0;
|
||||||
|
config_.pcan_gain_control.gain_bits = 21;
|
||||||
|
config_.log_scale.enable_log = true;
|
||||||
|
config_.log_scale.scale_shift = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FrontendConfig config_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FrontendTest_CheckOutputValues) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FrontendTestConfig config;
|
||||||
|
struct FrontendState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FrontendPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
struct FrontendOutput output = FrontendProcessSamples(
|
||||||
|
&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read);
|
||||||
|
|
||||||
|
const uint16_t expected[] = {479, 425};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output.size, sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < output.size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output.values[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FrontendTest_CheckConsecutiveWindow) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FrontendTestConfig config;
|
||||||
|
struct FrontendState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FrontendPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
FrontendProcessSamples(&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]),
|
||||||
|
&num_samples_read);
|
||||||
|
struct FrontendOutput output = FrontendProcessSamples(
|
||||||
|
&state, kFakeAudioData + kWindowSamples,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples,
|
||||||
|
&num_samples_read);
|
||||||
|
|
||||||
|
const int16_t expected[] = {436, 378};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output.size, sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < output.size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output.values[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(FrontendTest_CheckNotEnoughSamples) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
FrontendTestConfig config;
|
||||||
|
struct FrontendState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(FrontendPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
FrontendProcessSamples(&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]),
|
||||||
|
&num_samples_read);
|
||||||
|
FrontendProcessSamples(
|
||||||
|
&state, kFakeAudioData + kWindowSamples,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples,
|
||||||
|
&num_samples_read);
|
||||||
|
struct FrontendOutput output = FrontendProcessSamples(
|
||||||
|
&state, kFakeAudioData + kWindowSamples + kStepSamples,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples -
|
||||||
|
kStepSamples,
|
||||||
|
&num_samples_read);
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output.size, 0);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output.values, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -0,0 +1,80 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend_util.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/bits.h"
|
||||||
|
|
||||||
|
void FrontendFillConfigWithDefaults(struct FrontendConfig* config) {
|
||||||
|
WindowFillConfigWithDefaults(&config->window);
|
||||||
|
FilterbankFillConfigWithDefaults(&config->filterbank);
|
||||||
|
NoiseReductionFillConfigWithDefaults(&config->noise_reduction);
|
||||||
|
PcanGainControlFillConfigWithDefaults(&config->pcan_gain_control);
|
||||||
|
LogScaleFillConfigWithDefaults(&config->log_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FrontendPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct FrontendConfig* config,
|
||||||
|
struct FrontendState* state, int sample_rate) {
|
||||||
|
memset(state, 0, sizeof(*state));
|
||||||
|
|
||||||
|
if (!WindowPopulateState(error_reporter, &config->window, &state->window,
|
||||||
|
sample_rate)) {
|
||||||
|
error_reporter->Report("Failed to populate window state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!FftPopulateState(error_reporter, &state->fft, state->window.size)) {
|
||||||
|
error_reporter->Report("Failed to populate fft state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
FftInit(&state->fft);
|
||||||
|
|
||||||
|
if (!FilterbankPopulateState(error_reporter, &config->filterbank,
|
||||||
|
&state->filterbank, sample_rate,
|
||||||
|
state->fft.fft_size / 2 + 1)) {
|
||||||
|
error_reporter->Report("Failed to populate filterbank state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NoiseReductionPopulateState(error_reporter, &config->noise_reduction,
|
||||||
|
&state->noise_reduction,
|
||||||
|
state->filterbank.num_channels)) {
|
||||||
|
error_reporter->Report("Failed to populate noise reduction state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int input_correction_bits =
|
||||||
|
MostSignificantBit32(state->fft.fft_size) - 1 - (kFilterbankBits / 2);
|
||||||
|
if (!PcanGainControlPopulateState(
|
||||||
|
error_reporter, &config->pcan_gain_control, &state->pcan_gain_control,
|
||||||
|
state->noise_reduction.estimate, state->filterbank.num_channels,
|
||||||
|
state->noise_reduction.smoothing_bits, input_correction_bits)) {
|
||||||
|
error_reporter->Report("Failed to populate pcan gain control state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!LogScalePopulateState(error_reporter, &config->log_scale,
|
||||||
|
&state->log_scale)) {
|
||||||
|
error_reporter->Report("Failed to populate log scale state");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FrontendReset(state);
|
||||||
|
|
||||||
|
// All good, return a true value.
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FRONTEND_UTIL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FRONTEND_UTIL_H_
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/filterbank_util.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_util.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_util.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_util.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_util.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
struct FrontendConfig {
|
||||||
|
struct WindowConfig window;
|
||||||
|
struct FilterbankConfig filterbank;
|
||||||
|
struct NoiseReductionConfig noise_reduction;
|
||||||
|
struct PcanGainControlConfig pcan_gain_control;
|
||||||
|
struct LogScaleConfig log_scale;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fills the frontendConfig with "sane" defaults.
|
||||||
|
void FrontendFillConfigWithDefaults(struct FrontendConfig* config);
|
||||||
|
|
||||||
|
// Prepares any buffers.
|
||||||
|
int FrontendPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct FrontendConfig* config,
|
||||||
|
struct FrontendState* state, int sample_rate);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_FRONTEND_UTIL_H_
|
@ -0,0 +1,30 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_lut.h"
|
||||||
|
const uint16_t kLogLut[]
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
__attribute__((aligned(4)))
|
||||||
|
#endif // _MSV_VER
|
||||||
|
= {0, 224, 442, 654, 861, 1063, 1259, 1450, 1636, 1817, 1992, 2163,
|
||||||
|
2329, 2490, 2646, 2797, 2944, 3087, 3224, 3358, 3487, 3611, 3732, 3848,
|
||||||
|
3960, 4068, 4172, 4272, 4368, 4460, 4549, 4633, 4714, 4791, 4864, 4934,
|
||||||
|
5001, 5063, 5123, 5178, 5231, 5280, 5326, 5368, 5408, 5444, 5477, 5507,
|
||||||
|
5533, 5557, 5578, 5595, 5610, 5622, 5631, 5637, 5640, 5641, 5638, 5633,
|
||||||
|
5626, 5615, 5602, 5586, 5568, 5547, 5524, 5498, 5470, 5439, 5406, 5370,
|
||||||
|
5332, 5291, 5249, 5203, 5156, 5106, 5054, 5000, 4944, 4885, 4825, 4762,
|
||||||
|
4697, 4630, 4561, 4490, 4416, 4341, 4264, 4184, 4103, 4020, 3935, 3848,
|
||||||
|
3759, 3668, 3575, 3481, 3384, 3286, 3186, 3084, 2981, 2875, 2768, 2659,
|
||||||
|
2549, 2437, 2323, 2207, 2090, 1971, 1851, 1729, 1605, 1480, 1353, 1224,
|
||||||
|
1094, 963, 830, 695, 559, 421, 282, 142, 0, 0};
|
@ -0,0 +1,32 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_LUT_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_LUT_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Number of segments in the log lookup table. The table will be kLogSegments+1
|
||||||
|
// in length (with some padding).
|
||||||
|
#define kLogSegments 128
|
||||||
|
#define kLogSegmentsLog2 7
|
||||||
|
|
||||||
|
// Scale used by lookup table.
|
||||||
|
#define kLogScale 65536
|
||||||
|
#define kLogScaleLog2 16
|
||||||
|
#define kLogCoeff 45426
|
||||||
|
|
||||||
|
extern const uint16_t kLogLut[];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_LUT_H_
|
@ -0,0 +1,84 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/bits.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_lut.h"
|
||||||
|
|
||||||
|
#define kuint16max 0x0000FFFF
|
||||||
|
|
||||||
|
// The following functions implement integer logarithms of various sizes. The
|
||||||
|
// approximation is calculated according to method described in
|
||||||
|
// www.inti.gob.ar/electronicaeinformatica/instrumentacion/utic/
|
||||||
|
// publicaciones/SPL2007/Log10-spl07.pdf
|
||||||
|
// It first calculates log2 of the input and then converts it to natural
|
||||||
|
// logarithm.
|
||||||
|
|
||||||
|
static uint32_t Log2FractionPart(const uint32_t x, const uint32_t log2x) {
|
||||||
|
// Part 1
|
||||||
|
int32_t frac = x - (1LL << log2x);
|
||||||
|
if (log2x < kLogScaleLog2) {
|
||||||
|
frac <<= kLogScaleLog2 - log2x;
|
||||||
|
} else {
|
||||||
|
frac >>= log2x - kLogScaleLog2;
|
||||||
|
}
|
||||||
|
// Part 2
|
||||||
|
const uint32_t base_seg = frac >> (kLogScaleLog2 - kLogSegmentsLog2);
|
||||||
|
const uint32_t seg_unit =
|
||||||
|
((static_cast<uint32_t>(1)) << kLogScaleLog2) >> kLogSegmentsLog2;
|
||||||
|
|
||||||
|
const int32_t c0 = kLogLut[base_seg];
|
||||||
|
const int32_t c1 = kLogLut[base_seg + 1];
|
||||||
|
const int32_t seg_base = seg_unit * base_seg;
|
||||||
|
const int32_t rel_pos = ((c1 - c0) * (frac - seg_base)) >> kLogScaleLog2;
|
||||||
|
return frac + c0 + rel_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t Log(const uint32_t x, const uint32_t scale_shift) {
|
||||||
|
const uint32_t integer = MostSignificantBit32(x) - 1;
|
||||||
|
const uint32_t fraction = Log2FractionPart(x, integer);
|
||||||
|
const uint32_t log2 = (integer << kLogScaleLog2) + fraction;
|
||||||
|
const uint32_t round = kLogScale / 2;
|
||||||
|
const uint32_t loge =
|
||||||
|
((static_cast<uint64_t>(kLogCoeff)) * log2 + round) >> kLogScaleLog2;
|
||||||
|
// Finally scale to our output scale
|
||||||
|
const uint32_t loge_scaled = ((loge << scale_shift) + round) >> kLogScaleLog2;
|
||||||
|
return loge_scaled;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t* LogScaleApply(struct LogScaleState* state, uint32_t* signal,
|
||||||
|
int signal_size, int correction_bits) {
|
||||||
|
const int scale_shift = state->scale_shift;
|
||||||
|
uint16_t* output = reinterpret_cast<uint16_t*>(signal);
|
||||||
|
uint16_t* ret = output;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < signal_size; ++i) {
|
||||||
|
uint32_t value = *signal++;
|
||||||
|
if (state->enable_log) {
|
||||||
|
if (correction_bits < 0) {
|
||||||
|
value >>= -correction_bits;
|
||||||
|
} else {
|
||||||
|
value <<= correction_bits;
|
||||||
|
}
|
||||||
|
if (value > 1) {
|
||||||
|
value = Log(value, scale_shift);
|
||||||
|
} else {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*output++ = (value < kuint16max) ? value : kuint16max;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_SCALE_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_SCALE_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
struct LogScaleState {
|
||||||
|
int enable_log;
|
||||||
|
int scale_shift;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Applies a fixed point logarithm to the signal and converts it to 16 bit. Note
|
||||||
|
// that the signal array will be modified.
|
||||||
|
uint16_t* LogScaleApply(struct LogScaleState* state, uint32_t* signal,
|
||||||
|
int signal_size, int correction_bits);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_SCALE_H_
|
@ -0,0 +1,63 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_util.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int kScaleShift = 6;
|
||||||
|
const int kCorrectionBits = -1;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(LogScaleTest_CheckOutputValues) {
|
||||||
|
struct LogScaleState state;
|
||||||
|
state.enable_log = true;
|
||||||
|
state.scale_shift = kScaleShift;
|
||||||
|
|
||||||
|
uint32_t fake_signal[] = {3578, 1533};
|
||||||
|
uint16_t* output = LogScaleApply(&state, fake_signal,
|
||||||
|
sizeof(fake_signal) / sizeof(fake_signal[0]),
|
||||||
|
kCorrectionBits);
|
||||||
|
|
||||||
|
const uint16_t expected[] = {479, 425};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(LogScaleTest_CheckOutputValuesNoLog) {
|
||||||
|
struct LogScaleState state;
|
||||||
|
state.enable_log = false;
|
||||||
|
state.scale_shift = kScaleShift;
|
||||||
|
|
||||||
|
uint32_t fake_signal[] = {85964, 45998};
|
||||||
|
uint16_t* output = LogScaleApply(&state, fake_signal,
|
||||||
|
sizeof(fake_signal) / sizeof(fake_signal[0]),
|
||||||
|
kCorrectionBits);
|
||||||
|
|
||||||
|
const uint16_t expected[] = {65535, 45998};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(output[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale_util.h"
|
||||||
|
|
||||||
|
void LogScaleFillConfigWithDefaults(struct LogScaleConfig* config) {
|
||||||
|
config->enable_log = 1;
|
||||||
|
config->scale_shift = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LogScalePopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct LogScaleConfig* config,
|
||||||
|
struct LogScaleState* state) {
|
||||||
|
state->enable_log = config->enable_log;
|
||||||
|
state->scale_shift = config->scale_shift;
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_SCALE_UTIL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_SCALE_UTIL_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_scale.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
struct LogScaleConfig {
|
||||||
|
// set to false (0) to disable this module
|
||||||
|
int enable_log;
|
||||||
|
// scale results by 2^(scale_shift)
|
||||||
|
int scale_shift;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Populates the LogScaleConfig with "sane" default values.
|
||||||
|
void LogScaleFillConfigWithDefaults(struct LogScaleConfig* config);
|
||||||
|
|
||||||
|
// Allocates any buffers.
|
||||||
|
int LogScalePopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct LogScaleConfig* config,
|
||||||
|
struct LogScaleState* state);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_LOG_SCALE_UTIL_H_
|
@ -0,0 +1,99 @@
|
|||||||
|
/* 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_features_generator.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/frontend_util.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
FrontendState g_micro_features_state;
|
||||||
|
bool g_is_first_time = true;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TfLiteStatus InitializeMicroFeatures(tflite::ErrorReporter* error_reporter) {
|
||||||
|
FrontendConfig config;
|
||||||
|
config.window.size_ms = kFeatureSliceDurationMs;
|
||||||
|
config.window.step_size_ms = kFeatureSliceStrideMs;
|
||||||
|
config.noise_reduction.smoothing_bits = 10;
|
||||||
|
config.filterbank.num_channels = kFeatureSliceSize;
|
||||||
|
config.filterbank.lower_band_limit = 125.0;
|
||||||
|
config.filterbank.upper_band_limit = 7500.0;
|
||||||
|
config.noise_reduction.smoothing_bits = 10;
|
||||||
|
config.noise_reduction.even_smoothing = 0.025;
|
||||||
|
config.noise_reduction.odd_smoothing = 0.06;
|
||||||
|
config.noise_reduction.min_signal_remaining = 0.05;
|
||||||
|
config.pcan_gain_control.enable_pcan = 1;
|
||||||
|
config.pcan_gain_control.strength = 0.95;
|
||||||
|
config.pcan_gain_control.offset = 80.0;
|
||||||
|
config.pcan_gain_control.gain_bits = 21;
|
||||||
|
config.log_scale.enable_log = 1;
|
||||||
|
config.log_scale.scale_shift = 6;
|
||||||
|
if (!FrontendPopulateState(error_reporter, &config, &g_micro_features_state,
|
||||||
|
kAudioSampleFrequency)) {
|
||||||
|
error_reporter->Report("FrontendPopulateState() failed");
|
||||||
|
return kTfLiteError;
|
||||||
|
}
|
||||||
|
g_is_first_time = true;
|
||||||
|
return kTfLiteOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is not exposed in any header, and is only used for testing, to ensure
|
||||||
|
// that the state is correctly set up before generating results.
|
||||||
|
void SetMicroFeaturesNoiseEstimates(const uint32_t* estimate_presets) {
|
||||||
|
for (int i = 0; i < g_micro_features_state.filterbank.num_channels; ++i) {
|
||||||
|
g_micro_features_state.noise_reduction.estimate[i] = estimate_presets[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TfLiteStatus GenerateMicroFeatures(tflite::ErrorReporter* error_reporter,
|
||||||
|
const int16_t* input, int input_size,
|
||||||
|
int output_size, uint8_t* output,
|
||||||
|
size_t* num_samples_read) {
|
||||||
|
const int16_t* frontend_input;
|
||||||
|
if (g_is_first_time) {
|
||||||
|
frontend_input = input;
|
||||||
|
g_is_first_time = false;
|
||||||
|
} else {
|
||||||
|
frontend_input = input + 160;
|
||||||
|
}
|
||||||
|
FrontendOutput frontend_output = FrontendProcessSamples(
|
||||||
|
&g_micro_features_state, frontend_input, input_size, num_samples_read);
|
||||||
|
|
||||||
|
for (int i = 0; i < frontend_output.size; ++i) {
|
||||||
|
// These scaling values are derived from those used in input_data.py in the
|
||||||
|
// training pipeline.
|
||||||
|
constexpr int32_t value_scale = (10 * 255);
|
||||||
|
constexpr int32_t value_div = (256 * 26);
|
||||||
|
int32_t value =
|
||||||
|
((frontend_output.values[i] * value_scale) + (value_div / 2)) /
|
||||||
|
value_div;
|
||||||
|
if (value < 0) {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
if (value > 255) {
|
||||||
|
value = 255;
|
||||||
|
}
|
||||||
|
output[i] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return kTfLiteOk;
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/* 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
// Sets up any resources needed for the feature generation pipeline.
|
||||||
|
TfLiteStatus InitializeMicroFeatures(tflite::ErrorReporter* error_reporter);
|
||||||
|
|
||||||
|
// Converts audio sample data into a more compact form that's appropriate for
|
||||||
|
// feeding into a neural network.
|
||||||
|
TfLiteStatus GenerateMicroFeatures(tflite::ErrorReporter* error_reporter,
|
||||||
|
const int16_t* input, int input_size,
|
||||||
|
int output_size, uint8_t* output,
|
||||||
|
size_t* num_samples_read);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_
|
@ -0,0 +1,100 @@
|
|||||||
|
/* 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_features_generator.h"
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_feature_data_slice.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
// This is a test-only API, not exposed in any public headers, so declare it.
|
||||||
|
void SetMicroFeaturesNoiseEstimates(const uint32_t* estimate_presets);
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(TestMicroFeaturesGeneratorYes) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, InitializeMicroFeatures(error_reporter));
|
||||||
|
|
||||||
|
// The micro features pipeline retains state from previous calls to help
|
||||||
|
// estimate the background noise. Unfortunately this makes it harder to
|
||||||
|
// exactly reproduce results in a test environment, so use a known snapshot
|
||||||
|
// of the parameters at the point that the golden feature values were
|
||||||
|
// created.
|
||||||
|
const uint32_t yes_estimate_presets[] = {
|
||||||
|
1062898, 2644477, 1257642, 1864718, 412722, 725703, 395721, 474082,
|
||||||
|
173046, 255856, 158966, 153736, 69181, 199100, 144493, 227740,
|
||||||
|
110573, 164330, 79666, 144650, 122947, 476799, 398553, 497493,
|
||||||
|
322152, 1140005, 566716, 690605, 308902, 347481, 109891, 170457,
|
||||||
|
73901, 100975, 42963, 72325, 34183, 20207, 6640, 9468,
|
||||||
|
};
|
||||||
|
SetMicroFeaturesNoiseEstimates(yes_estimate_presets);
|
||||||
|
|
||||||
|
uint8_t yes_calculated_data[g_yes_feature_data_slice_size];
|
||||||
|
size_t num_samples_read;
|
||||||
|
TfLiteStatus yes_status = GenerateMicroFeatures(
|
||||||
|
error_reporter, g_yes_30ms_sample_data, g_yes_30ms_sample_data_size,
|
||||||
|
g_yes_feature_data_slice_size, yes_calculated_data, &num_samples_read);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, yes_status);
|
||||||
|
|
||||||
|
for (int i = 0; i < g_yes_feature_data_slice_size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(g_yes_feature_data_slice[i],
|
||||||
|
yes_calculated_data[i]);
|
||||||
|
if (g_yes_feature_data_slice[i] != yes_calculated_data[i]) {
|
||||||
|
error_reporter->Report("Expected value %d but found %d",
|
||||||
|
g_yes_feature_data_slice[i],
|
||||||
|
yes_calculated_data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(TestMicroFeaturesGeneratorNo) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, InitializeMicroFeatures(error_reporter));
|
||||||
|
// As we did for the previous features, set known good noise state
|
||||||
|
// parameters.
|
||||||
|
const uint32_t no_estimate_presets[] = {
|
||||||
|
2563964, 1909393, 559801, 538670, 203643, 175959, 75088, 139491,
|
||||||
|
59691, 95307, 43865, 129263, 52517, 80058, 51330, 100731,
|
||||||
|
76674, 76262, 15497, 22598, 13778, 21460, 8946, 17806,
|
||||||
|
10023, 18810, 8002, 10842, 7578, 9983, 6267, 10759,
|
||||||
|
8946, 18488, 9691, 39785, 9939, 17835, 9671, 18512,
|
||||||
|
};
|
||||||
|
SetMicroFeaturesNoiseEstimates(no_estimate_presets);
|
||||||
|
|
||||||
|
uint8_t no_calculated_data[g_no_feature_data_slice_size];
|
||||||
|
size_t num_samples_read;
|
||||||
|
TfLiteStatus no_status = GenerateMicroFeatures(
|
||||||
|
error_reporter, g_no_30ms_sample_data, g_no_30ms_sample_data_size,
|
||||||
|
g_no_feature_data_slice_size, no_calculated_data, &num_samples_read);
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, no_status);
|
||||||
|
|
||||||
|
for (int i = 0; i < g_no_feature_data_slice_size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(g_no_feature_data_slice[i], no_calculated_data[i]);
|
||||||
|
if (g_no_feature_data_slice[i] != no_calculated_data[i]) {
|
||||||
|
error_reporter->Report("Expected value %d but found %d",
|
||||||
|
g_no_feature_data_slice[i], no_calculated_data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
const char* kCategoryLabels[kCategoryCount] = {
|
const char* kCategoryLabels[kCategoryCount] = {
|
||||||
"silence",
|
"silence",
|
@ -0,0 +1,41 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_
|
||||||
|
|
||||||
|
// Keeping these as constant expressions allow us to allocate fixed-sized arrays
|
||||||
|
// on the stack for our working memory.
|
||||||
|
|
||||||
|
// The size of the input time series data we pass to the FFT to produce the
|
||||||
|
// frequency information. This has to be a power of two, and since we're dealing
|
||||||
|
// with 30ms of 16KHz inputs, which means 480 samples, this is the next value.
|
||||||
|
constexpr int kMaxAudioSampleSize = 512;
|
||||||
|
constexpr int kAudioSampleFrequency = 16000;
|
||||||
|
|
||||||
|
// All of these values are derived from the values used during model training,
|
||||||
|
// if you change your model you'll need to update these constants.
|
||||||
|
constexpr int kFeatureSliceSize = 40;
|
||||||
|
constexpr int kFeatureSliceCount = 49;
|
||||||
|
constexpr int kFeatureElementCount = (kFeatureSliceSize * kFeatureSliceCount);
|
||||||
|
constexpr int kFeatureSliceStrideMs = 20;
|
||||||
|
constexpr int kFeatureSliceDurationMs = 30;
|
||||||
|
|
||||||
|
constexpr int kCategoryCount = 4;
|
||||||
|
constexpr int kSilenceIndex = 0;
|
||||||
|
constexpr int kUnknownIndex = 1;
|
||||||
|
extern const char* kCategoryLabels[kCategoryCount];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_
|
@ -0,0 +1,24 @@
|
|||||||
|
/* 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.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
// See the header for documentation on the meaning of this data.
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_feature_data_slice.h"
|
||||||
|
|
||||||
|
const uint8_t g_no_feature_data_slice[g_no_feature_data_slice_size] = {
|
||||||
|
216, 195, 223, 211, 238, 223, 243, 215, 226, 204, 232, 211, 232, 213,
|
||||||
|
240, 218, 235, 214, 238, 205, 207, 173, 149, 201, 215, 200, 230, 213,
|
||||||
|
208, 195, 175, 151, 195, 175, 182, 163, 235, 217, 218, 190,
|
||||||
|
};
|
@ -0,0 +1,29 @@
|
|||||||
|
/* 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.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
// This data was extracted from the larger feature data held in
|
||||||
|
// no_features_data.cc and consists of the 29th spectrogram slice of 43 values.
|
||||||
|
// This is the expected result of running the sample data in
|
||||||
|
// no_30ms_sample_data.cc through through the preprocessing pipeline.
|
||||||
|
|
||||||
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_FEATURE_DATA_SLICE_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_FEATURE_DATA_SLICE_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
constexpr int g_no_feature_data_slice_size = 40;
|
||||||
|
extern const uint8_t g_no_feature_data_slice[];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_FEATURE_DATA_SLICE_H_
|
@ -0,0 +1,165 @@
|
|||||||
|
/* 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h"
|
||||||
|
|
||||||
|
/* File automatically created by
|
||||||
|
* tensorflow/examples/speech_commands/wav_to_features.py \
|
||||||
|
* --sample_rate=16000 \
|
||||||
|
* --clip_duration_ms=1000 \
|
||||||
|
* --window_size_ms=30 \
|
||||||
|
* --window_stride_ms=20 \
|
||||||
|
* --feature_bin_count=40 \
|
||||||
|
* --quantize=1 \
|
||||||
|
* --preprocess="micro" \
|
||||||
|
* --input_wav="speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav" \
|
||||||
|
* --output_c_file="/tmp/no_micro_features_data.cc" \
|
||||||
|
*/
|
||||||
|
|
||||||
|
const int g_no_micro_f9643d42_nohash_4_width = 40;
|
||||||
|
const int g_no_micro_f9643d42_nohash_4_height = 49;
|
||||||
|
const unsigned char g_no_micro_f9643d42_nohash_4_data[] = {
|
||||||
|
230, 205, 191, 203, 202, 181, 180, 194, 205, 187, 183, 197, 203, 198, 196,
|
||||||
|
186, 202, 159, 151, 126, 110, 138, 141, 142, 137, 148, 133, 120, 110, 126,
|
||||||
|
117, 110, 117, 116, 137, 134, 95, 116, 123, 110, 184, 144, 183, 189, 197,
|
||||||
|
172, 188, 164, 194, 179, 175, 174, 182, 173, 184, 174, 200, 145, 154, 148,
|
||||||
|
147, 135, 143, 122, 127, 138, 116, 99, 122, 105, 110, 125, 127, 133, 131,
|
||||||
|
123, 116, 119, 127, 114, 193, 176, 185, 170, 175, 146, 166, 167, 185, 185,
|
||||||
|
185, 183, 195, 185, 176, 178, 197, 155, 137, 144, 164, 132, 153, 132, 138,
|
||||||
|
137, 134, 95, 120, 116, 131, 122, 99, 120, 120, 110, 116, 110, 126, 127,
|
||||||
|
128, 159, 187, 119, 178, 187, 197, 167, 199, 184, 180, 165, 194, 176, 144,
|
||||||
|
134, 187, 136, 142, 134, 145, 132, 145, 105, 119, 123, 125, 116, 125, 102,
|
||||||
|
129, 138, 130, 99, 99, 90, 120, 123, 134, 95, 194, 172, 187, 123, 191,
|
||||||
|
179, 195, 182, 201, 137, 167, 142, 185, 161, 187, 146, 167, 152, 154, 107,
|
||||||
|
152, 112, 134, 144, 117, 116, 105, 85, 105, 105, 99, 90, 123, 112, 112,
|
||||||
|
68, 107, 105, 117, 99, 116, 143, 139, 90, 154, 142, 188, 172, 178, 135,
|
||||||
|
175, 149, 177, 110, 173, 160, 169, 162, 173, 119, 132, 110, 85, 85, 117,
|
||||||
|
129, 117, 112, 117, 51, 112, 95, 139, 102, 105, 90, 128, 119, 112, 99,
|
||||||
|
170, 168, 195, 152, 174, 173, 180, 0, 157, 130, 169, 149, 149, 123, 170,
|
||||||
|
130, 170, 133, 159, 102, 134, 90, 85, 105, 126, 119, 130, 90, 78, 68,
|
||||||
|
127, 120, 95, 51, 122, 110, 112, 78, 116, 95, 180, 135, 179, 146, 179,
|
||||||
|
162, 197, 153, 172, 135, 154, 0, 149, 95, 145, 114, 166, 0, 114, 110,
|
||||||
|
145, 107, 114, 90, 136, 68, 95, 95, 95, 85, 116, 99, 116, 0, 95,
|
||||||
|
68, 102, 51, 102, 78, 185, 157, 138, 158, 180, 117, 173, 142, 145, 117,
|
||||||
|
169, 130, 159, 99, 138, 123, 169, 90, 78, 0, 123, 85, 107, 51, 114,
|
||||||
|
102, 95, 0, 116, 85, 119, 95, 95, 68, 85, 51, 116, 68, 102, 78,
|
||||||
|
167, 105, 164, 163, 178, 126, 164, 154, 154, 51, 177, 120, 156, 85, 134,
|
||||||
|
139, 168, 90, 161, 102, 114, 116, 122, 95, 112, 102, 107, 51, 114, 85,
|
||||||
|
119, 78, 114, 90, 102, 51, 102, 51, 114, 99, 177, 68, 152, 102, 184,
|
||||||
|
166, 179, 129, 177, 129, 180, 110, 158, 105, 139, 0, 145, 85, 148, 102,
|
||||||
|
117, 102, 116, 0, 78, 68, 90, 51, 107, 85, 78, 0, 51, 0, 51,
|
||||||
|
0, 95, 51, 107, 68, 180, 117, 90, 0, 138, 0, 187, 146, 119, 140,
|
||||||
|
164, 90, 136, 0, 131, 51, 159, 99, 141, 138, 116, 51, 90, 51, 90,
|
||||||
|
68, 105, 0, 85, 78, 112, 51, 122, 95, 128, 68, 85, 0, 112, 68,
|
||||||
|
147, 126, 178, 146, 171, 130, 190, 147, 188, 123, 170, 78, 132, 0, 130,
|
||||||
|
125, 159, 95, 102, 0, 110, 0, 95, 85, 120, 68, 78, 51, 99, 51,
|
||||||
|
105, 0, 112, 102, 105, 68, 90, 51, 90, 0, 127, 95, 166, 175, 187,
|
||||||
|
133, 135, 0, 171, 139, 132, 128, 140, 51, 126, 107, 161, 0, 95, 51,
|
||||||
|
119, 0, 114, 0, 95, 110, 116, 51, 112, 0, 90, 0, 116, 51, 68,
|
||||||
|
0, 105, 68, 105, 0, 164, 78, 173, 0, 194, 166, 145, 114, 116, 51,
|
||||||
|
107, 122, 151, 0, 156, 102, 148, 51, 122, 95, 129, 0, 85, 0, 127,
|
||||||
|
78, 90, 0, 78, 0, 95, 0, 110, 0, 68, 119, 120, 68, 68, 0,
|
||||||
|
122, 99, 147, 127, 200, 167, 85, 114, 161, 85, 161, 125, 143, 99, 156,
|
||||||
|
85, 147, 68, 99, 0, 107, 102, 132, 51, 112, 68, 95, 78, 99, 0,
|
||||||
|
68, 0, 51, 0, 90, 78, 128, 51, 95, 0, 166, 136, 174, 138, 189,
|
||||||
|
144, 130, 129, 138, 134, 132, 120, 134, 0, 51, 78, 147, 51, 51, 0,
|
||||||
|
51, 0, 78, 0, 68, 68, 95, 78, 90, 0, 0, 0, 68, 0, 90,
|
||||||
|
68, 110, 0, 95, 51, 165, 151, 157, 0, 0, 0, 112, 0, 112, 95,
|
||||||
|
149, 107, 119, 68, 126, 68, 138, 0, 78, 0, 78, 0, 99, 51, 112,
|
||||||
|
0, 102, 0, 78, 51, 85, 0, 0, 0, 78, 0, 95, 0, 95, 78,
|
||||||
|
105, 0, 152, 0, 0, 51, 132, 105, 159, 0, 129, 102, 114, 0, 138,
|
||||||
|
51, 123, 0, 129, 78, 119, 51, 51, 51, 105, 0, 78, 85, 95, 0,
|
||||||
|
85, 0, 0, 0, 85, 0, 78, 0, 0, 0, 172, 142, 141, 0, 137,
|
||||||
|
0, 148, 128, 157, 120, 146, 120, 120, 0, 95, 78, 141, 68, 68, 0,
|
||||||
|
68, 0, 90, 0, 85, 0, 107, 0, 78, 0, 85, 51, 102, 0, 68,
|
||||||
|
78, 68, 0, 51, 0, 125, 0, 141, 51, 102, 138, 175, 51, 120, 51,
|
||||||
|
173, 85, 116, 141, 164, 68, 150, 123, 133, 51, 114, 0, 117, 68, 150,
|
||||||
|
51, 116, 68, 78, 0, 68, 0, 68, 0, 85, 0, 78, 0, 51, 78,
|
||||||
|
155, 90, 161, 0, 132, 99, 123, 78, 107, 0, 134, 90, 95, 0, 78,
|
||||||
|
0, 162, 143, 85, 0, 107, 78, 125, 90, 90, 51, 51, 0, 85, 0,
|
||||||
|
0, 0, 132, 102, 102, 154, 128, 0, 99, 68, 162, 102, 151, 0, 99,
|
||||||
|
51, 147, 141, 156, 0, 112, 120, 158, 127, 145, 139, 187, 171, 135, 138,
|
||||||
|
146, 0, 95, 68, 127, 0, 85, 0, 105, 0, 0, 0, 187, 170, 162,
|
||||||
|
188, 165, 51, 51, 78, 243, 215, 225, 196, 205, 181, 205, 168, 176, 134,
|
||||||
|
157, 110, 126, 114, 133, 139, 193, 163, 159, 116, 160, 126, 122, 127, 171,
|
||||||
|
99, 114, 68, 123, 85, 90, 0, 157, 146, 166, 179, 136, 0, 116, 90,
|
||||||
|
242, 219, 240, 204, 216, 164, 188, 171, 176, 164, 154, 158, 190, 157, 190,
|
||||||
|
141, 182, 177, 169, 128, 172, 145, 105, 129, 157, 90, 78, 51, 119, 68,
|
||||||
|
137, 68, 116, 78, 141, 132, 151, 122, 156, 140, 234, 206, 229, 201, 216,
|
||||||
|
174, 191, 144, 162, 85, 122, 157, 194, 167, 204, 149, 180, 166, 166, 139,
|
||||||
|
122, 133, 156, 126, 145, 85, 128, 0, 99, 51, 145, 0, 126, 51, 166,
|
||||||
|
162, 166, 162, 177, 157, 228, 198, 221, 197, 214, 177, 173, 166, 173, 139,
|
||||||
|
185, 191, 202, 163, 205, 172, 206, 189, 135, 68, 166, 134, 149, 134, 135,
|
||||||
|
90, 127, 107, 175, 90, 136, 117, 135, 140, 172, 167, 166, 149, 177, 152,
|
||||||
|
221, 191, 215, 194, 211, 0, 156, 147, 182, 178, 208, 163, 190, 157, 208,
|
||||||
|
200, 195, 164, 179, 154, 181, 150, 143, 99, 132, 137, 185, 143, 163, 85,
|
||||||
|
51, 107, 132, 134, 164, 127, 167, 159, 175, 141, 216, 195, 223, 211, 238,
|
||||||
|
223, 243, 215, 226, 204, 232, 211, 232, 213, 240, 218, 235, 214, 238, 205,
|
||||||
|
207, 173, 149, 201, 215, 200, 230, 213, 208, 195, 175, 151, 195, 175, 182,
|
||||||
|
163, 235, 217, 218, 190, 211, 191, 215, 191, 217, 220, 241, 215, 229, 206,
|
||||||
|
236, 210, 227, 216, 236, 188, 183, 149, 202, 189, 208, 172, 191, 201, 220,
|
||||||
|
193, 221, 207, 216, 208, 201, 131, 170, 187, 229, 197, 211, 194, 226, 201,
|
||||||
|
205, 184, 206, 177, 221, 210, 226, 184, 204, 197, 218, 198, 212, 209, 213,
|
||||||
|
141, 172, 110, 175, 167, 180, 156, 213, 188, 192, 179, 213, 205, 204, 174,
|
||||||
|
200, 147, 162, 181, 203, 167, 198, 187, 210, 164, 196, 169, 189, 168, 224,
|
||||||
|
198, 213, 204, 198, 195, 230, 211, 221, 197, 208, 0, 0, 0, 85, 90,
|
||||||
|
167, 130, 175, 173, 203, 164, 193, 144, 170, 145, 185, 148, 154, 139, 198,
|
||||||
|
159, 180, 171, 216, 174, 178, 161, 166, 136, 216, 184, 215, 197, 199, 190,
|
||||||
|
228, 195, 208, 51, 117, 0, 0, 0, 0, 0, 140, 51, 135, 154, 188,
|
||||||
|
155, 168, 0, 90, 0, 156, 85, 110, 0, 174, 90, 172, 154, 179, 99,
|
||||||
|
142, 166, 179, 157, 177, 95, 192, 142, 204, 198, 217, 147, 173, 0, 112,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 110, 0, 107, 0, 160, 0, 148, 95,
|
||||||
|
172, 0, 0, 0, 116, 0, 122, 114, 170, 0, 0, 0, 0, 0, 179,
|
||||||
|
110, 196, 85, 205, 183, 169, 0, 99, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 141, 0, 112, 0, 0, 0, 134, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 139, 0, 0, 0, 0, 112, 186, 78, 163, 0, 169, 128,
|
||||||
|
174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95,
|
||||||
|
0, 105, 0, 0, 0, 105, 0, 0, 0, 0, 0, 0, 0, 95, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 119, 0, 164, 78, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 68,
|
||||||
|
117, 0, 0, 0, 0, 0, 0, 0, 148, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51,
|
||||||
|
0, 0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
};
|
@ -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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_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 unsigned char g_no_micro_f9643d42_nohash_4_data[];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_
|
@ -0,0 +1,51 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void NoiseReductionApply(struct NoiseReductionState* state, uint32_t* signal) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state->num_channels; ++i) {
|
||||||
|
const uint32_t smoothing =
|
||||||
|
((i & 1) == 0) ? state->even_smoothing : state->odd_smoothing;
|
||||||
|
const uint32_t one_minus_smoothing = (1 << kNoiseReductionBits) - smoothing;
|
||||||
|
|
||||||
|
// Update the estimate of the noise.
|
||||||
|
const uint32_t signal_scaled_up = signal[i] << state->smoothing_bits;
|
||||||
|
uint32_t estimate =
|
||||||
|
((static_cast<uint64_t>(signal_scaled_up) * smoothing) +
|
||||||
|
(static_cast<uint64_t>(state->estimate[i]) * one_minus_smoothing)) >>
|
||||||
|
kNoiseReductionBits;
|
||||||
|
state->estimate[i] = estimate;
|
||||||
|
|
||||||
|
// Make sure that we can't get a negative value for the signal - estimate.
|
||||||
|
if (estimate > signal_scaled_up) {
|
||||||
|
estimate = signal_scaled_up;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32_t floor =
|
||||||
|
(static_cast<uint64_t>(signal[i]) * state->min_signal_remaining) >>
|
||||||
|
kNoiseReductionBits;
|
||||||
|
const uint32_t subtracted =
|
||||||
|
(signal_scaled_up - estimate) >> state->smoothing_bits;
|
||||||
|
const uint32_t output = subtracted > floor ? subtracted : floor;
|
||||||
|
signal[i] = output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NoiseReductionReset(struct NoiseReductionState* state) {
|
||||||
|
memset(state->estimate, 0, sizeof(*state->estimate) * state->num_channels);
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NOISE_REDUCTION_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NOISE_REDUCTION_H_
|
||||||
|
|
||||||
|
#define kNoiseReductionBits 14
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
|
struct NoiseReductionState {
|
||||||
|
int smoothing_bits;
|
||||||
|
uint16_t even_smoothing;
|
||||||
|
uint16_t odd_smoothing;
|
||||||
|
uint16_t min_signal_remaining;
|
||||||
|
int num_channels;
|
||||||
|
uint32_t estimate[kFeatureSliceSize];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Removes stationary noise from each channel of the signal using a low pass
|
||||||
|
// filter.
|
||||||
|
void NoiseReductionApply(struct NoiseReductionState* state, uint32_t* signal);
|
||||||
|
|
||||||
|
void NoiseReductionReset(struct NoiseReductionState* state);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NOISE_REDUCTION_H_
|
@ -0,0 +1,83 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_util.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int kNumChannels = 2;
|
||||||
|
|
||||||
|
// Test noise reduction using default config values.
|
||||||
|
class NoiseReductionTestConfig {
|
||||||
|
public:
|
||||||
|
NoiseReductionTestConfig() {
|
||||||
|
config_.smoothing_bits = 10;
|
||||||
|
config_.even_smoothing = 0.025;
|
||||||
|
config_.odd_smoothing = 0.06;
|
||||||
|
config_.min_signal_remaining = 0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct NoiseReductionConfig config_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(NoiseReductionTest_TestNoiseReductionEstimate) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
NoiseReductionTestConfig config;
|
||||||
|
struct NoiseReductionState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(NoiseReductionPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kNumChannels));
|
||||||
|
|
||||||
|
uint32_t signal[] = {247311, 508620};
|
||||||
|
NoiseReductionApply(&state, signal);
|
||||||
|
|
||||||
|
const uint32_t expected[] = {6321887, 31248341};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.estimate[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(NoiseReductionTest_TestNoiseReduction) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
NoiseReductionTestConfig config;
|
||||||
|
struct NoiseReductionState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(NoiseReductionPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, kNumChannels));
|
||||||
|
|
||||||
|
uint32_t signal[] = {247311, 508620};
|
||||||
|
NoiseReductionApply(&state, signal);
|
||||||
|
|
||||||
|
const uint32_t expected[] = {241137, 478104};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(signal[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction_util.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h"
|
||||||
|
|
||||||
|
void NoiseReductionFillConfigWithDefaults(struct NoiseReductionConfig* config) {
|
||||||
|
config->smoothing_bits = 10;
|
||||||
|
config->even_smoothing = 0.025;
|
||||||
|
config->odd_smoothing = 0.06;
|
||||||
|
config->min_signal_remaining = 0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NoiseReductionPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct NoiseReductionConfig* config,
|
||||||
|
struct NoiseReductionState* state,
|
||||||
|
int num_channels) {
|
||||||
|
state->smoothing_bits = config->smoothing_bits;
|
||||||
|
state->odd_smoothing = config->odd_smoothing * (1 << kNoiseReductionBits);
|
||||||
|
state->even_smoothing = config->even_smoothing * (1 << kNoiseReductionBits);
|
||||||
|
state->min_signal_remaining =
|
||||||
|
config->min_signal_remaining * (1 << kNoiseReductionBits);
|
||||||
|
state->num_channels = num_channels;
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->estimate, (state->num_channels * sizeof(*state->estimate)));
|
||||||
|
for (int i = 0; i < state->num_channels; ++i) {
|
||||||
|
state->estimate[i] = 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NOISE_REDUCTION_UTIL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NOISE_REDUCTION_UTIL_H_
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/noise_reduction.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
struct NoiseReductionConfig {
|
||||||
|
// scale the signal up by 2^(smoothing_bits) before reduction
|
||||||
|
int smoothing_bits;
|
||||||
|
// smoothing coefficient for even-numbered channels
|
||||||
|
float even_smoothing;
|
||||||
|
// smoothing coefficient for odd-numbered channels
|
||||||
|
float odd_smoothing;
|
||||||
|
// fraction of signal to preserve (1.0 disables this module)
|
||||||
|
float min_signal_remaining;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Populates the NoiseReductionConfig with "sane" default values.
|
||||||
|
void NoiseReductionFillConfigWithDefaults(struct NoiseReductionConfig* config);
|
||||||
|
|
||||||
|
// Prepares any buffers.
|
||||||
|
int NoiseReductionPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct NoiseReductionConfig* config,
|
||||||
|
struct NoiseReductionState* state,
|
||||||
|
int num_channels);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NOISE_REDUCTION_UTIL_H_
|
@ -0,0 +1,57 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/bits.h"
|
||||||
|
|
||||||
|
int16_t WideDynamicFunction(const uint32_t x, const int16_t* lut) {
|
||||||
|
if (x <= 2) {
|
||||||
|
return lut[x];
|
||||||
|
}
|
||||||
|
|
||||||
|
const int16_t interval = MostSignificantBit32(x);
|
||||||
|
lut += 4 * interval - 6;
|
||||||
|
|
||||||
|
const int16_t frac =
|
||||||
|
((interval < 11) ? (x << (11 - interval)) : (x >> (interval - 11))) &
|
||||||
|
0x3FF;
|
||||||
|
|
||||||
|
int32_t result = (static_cast<int32_t>(lut[2]) * frac) >> 5;
|
||||||
|
result += (static_cast<int32_t>(lut[1])) << 5;
|
||||||
|
result *= frac;
|
||||||
|
result = (result + (1 << 14)) >> 15;
|
||||||
|
result += lut[0];
|
||||||
|
return static_cast<int16_t>(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t PcanShrink(const uint32_t x) {
|
||||||
|
if (x < (2 << kPcanSnrBits)) {
|
||||||
|
return (x * x) >> (2 + 2 * kPcanSnrBits - kPcanOutputBits);
|
||||||
|
} else {
|
||||||
|
return (x >> (kPcanSnrBits - kPcanOutputBits)) - (1 << kPcanOutputBits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PcanGainControlApply(struct PcanGainControlState* state,
|
||||||
|
uint32_t* signal) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state->num_channels; ++i) {
|
||||||
|
const uint32_t gain =
|
||||||
|
WideDynamicFunction(state->noise_estimate[i], state->gain_lut);
|
||||||
|
const uint32_t snr =
|
||||||
|
(static_cast<uint64_t>(signal[i]) * gain) >> state->snr_shift;
|
||||||
|
signal[i] = PcanShrink(snr);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_PCAN_GAIN_CONTROL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_PCAN_GAIN_CONTROL_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define kPcanSnrBits 12
|
||||||
|
#define kPcanOutputBits 6
|
||||||
|
|
||||||
|
#define kWideDynamicFunctionBits 32
|
||||||
|
#define kWideDynamicFunctionLUTSize (4 * kWideDynamicFunctionBits - 3)
|
||||||
|
|
||||||
|
struct PcanGainControlState {
|
||||||
|
int enable_pcan;
|
||||||
|
uint32_t* noise_estimate;
|
||||||
|
int num_channels;
|
||||||
|
int16_t gain_lut[kWideDynamicFunctionLUTSize];
|
||||||
|
int32_t snr_shift;
|
||||||
|
};
|
||||||
|
|
||||||
|
int16_t WideDynamicFunction(const uint32_t x, const int16_t* lut);
|
||||||
|
|
||||||
|
uint32_t PcanShrink(const uint32_t x);
|
||||||
|
|
||||||
|
void PcanGainControlApply(struct PcanGainControlState* state, uint32_t* signal);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_PCAN_GAIN_CONTROL_H_
|
@ -0,0 +1,66 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_util.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int kNumChannels = 2;
|
||||||
|
const int kSmoothingBits = 10;
|
||||||
|
const int kCorrectionBits = -1;
|
||||||
|
|
||||||
|
// Test pcan auto gain control using default config values.
|
||||||
|
class PcanGainControlTestConfig {
|
||||||
|
public:
|
||||||
|
PcanGainControlTestConfig() {
|
||||||
|
config_.enable_pcan = 1;
|
||||||
|
config_.strength = 0.95;
|
||||||
|
config_.offset = 80.0;
|
||||||
|
config_.gain_bits = 21;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PcanGainControlConfig config_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(PcanGainControlTest_TestPcanGainControl) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
uint32_t estimate[] = {6321887, 31248341};
|
||||||
|
PcanGainControlTestConfig config;
|
||||||
|
struct PcanGainControlState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(PcanGainControlPopulateState(
|
||||||
|
error_reporter, &config.config_, &state, estimate, kNumChannels,
|
||||||
|
kSmoothingBits, kCorrectionBits));
|
||||||
|
|
||||||
|
uint32_t signal[] = {241137, 478104};
|
||||||
|
PcanGainControlApply(&state, signal);
|
||||||
|
|
||||||
|
const uint32_t expected[] = {3578, 1533};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.num_channels,
|
||||||
|
sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state.num_channels; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(signal[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -0,0 +1,87 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control_util.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h"
|
||||||
|
|
||||||
|
#define kint16max 0x00007FFF
|
||||||
|
|
||||||
|
void PcanGainControlFillConfigWithDefaults(
|
||||||
|
struct PcanGainControlConfig* config) {
|
||||||
|
config->enable_pcan = 0;
|
||||||
|
config->strength = 0.95;
|
||||||
|
config->offset = 80.0;
|
||||||
|
config->gain_bits = 21;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t PcanGainLookupFunction(const struct PcanGainControlConfig* config,
|
||||||
|
int32_t input_bits, uint32_t x) {
|
||||||
|
const float x_as_float =
|
||||||
|
(static_cast<float>(x)) / (static_cast<uint32_t>(1) << input_bits);
|
||||||
|
const float gain_as_float =
|
||||||
|
(static_cast<uint32_t>(1) << config->gain_bits) *
|
||||||
|
powf(x_as_float + config->offset, -config->strength);
|
||||||
|
|
||||||
|
if (gain_as_float > kint16max) {
|
||||||
|
return kint16max;
|
||||||
|
}
|
||||||
|
return static_cast<int16_t>(gain_as_float + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
int PcanGainControlPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct PcanGainControlConfig* config,
|
||||||
|
struct PcanGainControlState* state,
|
||||||
|
uint32_t* noise_estimate,
|
||||||
|
const int num_channels,
|
||||||
|
const uint16_t smoothing_bits,
|
||||||
|
const int32_t input_correction_bits) {
|
||||||
|
state->enable_pcan = config->enable_pcan;
|
||||||
|
if (!state->enable_pcan) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
state->noise_estimate = noise_estimate;
|
||||||
|
state->num_channels = num_channels;
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(
|
||||||
|
state->gain_lut, (kWideDynamicFunctionLUTSize * sizeof(int16_t)));
|
||||||
|
state->snr_shift = config->gain_bits - input_correction_bits - kPcanSnrBits;
|
||||||
|
|
||||||
|
const int32_t input_bits = smoothing_bits - input_correction_bits;
|
||||||
|
state->gain_lut[0] = PcanGainLookupFunction(config, input_bits, 0);
|
||||||
|
state->gain_lut[1] = PcanGainLookupFunction(config, input_bits, 1);
|
||||||
|
int16_t* temp_gain_lut = state->gain_lut - 6;
|
||||||
|
int interval;
|
||||||
|
for (interval = 2; interval <= kWideDynamicFunctionBits; ++interval) {
|
||||||
|
const uint32_t x0 = static_cast<uint32_t>(1) << (interval - 1);
|
||||||
|
const uint32_t x1 = x0 + (x0 >> 1);
|
||||||
|
const uint32_t x2 =
|
||||||
|
(interval == kWideDynamicFunctionBits) ? x0 + (x0 - 1) : 2 * x0;
|
||||||
|
|
||||||
|
const int16_t y0 = PcanGainLookupFunction(config, input_bits, x0);
|
||||||
|
const int16_t y1 = PcanGainLookupFunction(config, input_bits, x1);
|
||||||
|
const int16_t y2 = PcanGainLookupFunction(config, input_bits, x2);
|
||||||
|
|
||||||
|
const int32_t diff1 = static_cast<int32_t>(y1) - y0;
|
||||||
|
const int32_t diff2 = static_cast<int32_t>(y2) - y0;
|
||||||
|
const int32_t a1 = 4 * diff1 - diff2;
|
||||||
|
const int32_t a2 = diff2 - a1;
|
||||||
|
|
||||||
|
temp_gain_lut[4 * interval] = y0;
|
||||||
|
temp_gain_lut[4 * interval + 1] = static_cast<int16_t>(a1);
|
||||||
|
temp_gain_lut[4 * interval + 2] = static_cast<int16_t>(a2);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_PCAN_GAIN_CONTROL_UTIL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_PCAN_GAIN_CONTROL_UTIL_H_
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/pcan_gain_control.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
struct PcanGainControlConfig {
|
||||||
|
// set to false (0) to disable this module
|
||||||
|
int enable_pcan;
|
||||||
|
// gain normalization exponent (0.0 disables, 1.0 full strength)
|
||||||
|
float strength;
|
||||||
|
// positive value added in the normalization denominator
|
||||||
|
float offset;
|
||||||
|
// number of fractional bits in the gain
|
||||||
|
int gain_bits;
|
||||||
|
};
|
||||||
|
|
||||||
|
void PcanGainControlFillConfigWithDefaults(
|
||||||
|
struct PcanGainControlConfig* config);
|
||||||
|
|
||||||
|
int16_t PcanGainLookupFunction(const struct PcanGainControlConfig* config,
|
||||||
|
int32_t input_bits, uint32_t x);
|
||||||
|
|
||||||
|
int PcanGainControlPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct PcanGainControlConfig* config,
|
||||||
|
struct PcanGainControlState* state,
|
||||||
|
uint32_t* noise_estimate,
|
||||||
|
const int num_channels,
|
||||||
|
const uint16_t smoothing_bits,
|
||||||
|
const int32_t input_correction_bits);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_PCAN_GAIN_CONTROL_UTIL_H_
|
@ -0,0 +1,32 @@
|
|||||||
|
/* 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_STATIC_ALLOC_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_STATIC_ALLOC_H_
|
||||||
|
|
||||||
|
// Checks to ensure that the C-style array passed in has a compile-time size of
|
||||||
|
// at least the number of bytes requested. This doesn't work with raw pointers
|
||||||
|
// since sizeof() doesn't know their actual length, so only use this to check
|
||||||
|
// statically-allocated arrays with known sizes.
|
||||||
|
#define STATIC_ALLOC_ENSURE_ARRAY_SIZE(A, N) \
|
||||||
|
do { \
|
||||||
|
if (sizeof(A) < (N)) { \
|
||||||
|
error_reporter->Report(#A " too small (%d bytes, wanted %d) at %s:%d", \
|
||||||
|
sizeof(A), (N), __FILE__, __LINE__); \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_STATIC_ALLOC_H_
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
|||||||
|
/* 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.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
// This is a standard TensorFlow Lite 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 tiny_conv.tflite > tiny_conv_simple_features_model_data.cc
|
||||||
|
|
||||||
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_TINY_CONV_MICRO_FEATURES_MODEL_DATA_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_TINY_CONV_MICRO_FEATURES_MODEL_DATA_H_
|
||||||
|
|
||||||
|
extern const unsigned char g_tiny_conv_micro_features_model_data[];
|
||||||
|
extern const int g_tiny_conv_micro_features_model_data_len;
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_TINY_CONV_MICRO_FEATURES_MODEL_DATA_H_
|
@ -0,0 +1,70 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int WindowProcessSamples(struct WindowState* state, const int16_t* samples,
|
||||||
|
size_t num_samples, size_t* num_samples_read) {
|
||||||
|
const int size = state->size;
|
||||||
|
|
||||||
|
// Copy samples from the samples buffer over to our local input.
|
||||||
|
size_t max_samples_to_copy = state->size - state->input_used;
|
||||||
|
if (max_samples_to_copy > num_samples) {
|
||||||
|
max_samples_to_copy = num_samples;
|
||||||
|
}
|
||||||
|
memcpy(state->input + state->input_used, samples,
|
||||||
|
max_samples_to_copy * sizeof(*samples));
|
||||||
|
*num_samples_read = max_samples_to_copy;
|
||||||
|
state->input_used += max_samples_to_copy;
|
||||||
|
|
||||||
|
if (state->input_used < state->size) {
|
||||||
|
// We don't have enough samples to compute a window.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the window to the input.
|
||||||
|
const int16_t* coefficients = state->coefficients;
|
||||||
|
const int16_t* input = state->input;
|
||||||
|
int16_t* output = state->output;
|
||||||
|
int i;
|
||||||
|
int16_t max_abs_output_value = 0;
|
||||||
|
for (i = 0; i < size; ++i) {
|
||||||
|
int16_t new_value = ((static_cast<int32_t>(*input++)) * *coefficients++) >>
|
||||||
|
kFrontendWindowBits;
|
||||||
|
*output++ = new_value;
|
||||||
|
if (new_value < 0) {
|
||||||
|
new_value = -new_value;
|
||||||
|
}
|
||||||
|
if (new_value > max_abs_output_value) {
|
||||||
|
max_abs_output_value = new_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Shuffle the input down by the step size, and update how much we have used.
|
||||||
|
memmove(state->input, state->input + state->step,
|
||||||
|
sizeof(*state->input) * (state->size - state->step));
|
||||||
|
state->input_used -= state->step;
|
||||||
|
state->max_abs_output_value = max_abs_output_value;
|
||||||
|
|
||||||
|
// Indicate that the output buffer is valid for the next stage.
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowReset(struct WindowState* state) {
|
||||||
|
memset(state->input, 0, state->size * sizeof(*state->input));
|
||||||
|
memset(state->output, 0, state->size * sizeof(*state->output));
|
||||||
|
state->input_used = 0;
|
||||||
|
state->max_abs_output_value = 0;
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_WINDOW_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_WINDOW_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
|
|
||||||
|
#define kFrontendWindowBits 12
|
||||||
|
|
||||||
|
struct WindowState {
|
||||||
|
size_t size;
|
||||||
|
int16_t coefficients[kMaxAudioSampleSize];
|
||||||
|
size_t step;
|
||||||
|
|
||||||
|
int16_t input[kMaxAudioSampleSize];
|
||||||
|
size_t input_used;
|
||||||
|
int16_t output[kMaxAudioSampleSize];
|
||||||
|
int16_t max_abs_output_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Applies a window to the samples coming in, stepping forward at the given
|
||||||
|
// rate.
|
||||||
|
int WindowProcessSamples(struct WindowState* state, const int16_t* samples,
|
||||||
|
size_t num_samples, size_t* num_samples_read);
|
||||||
|
|
||||||
|
void WindowReset(struct WindowState* state);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_WINDOW_H_
|
@ -0,0 +1,183 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_util.h"
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const int kSampleRate = 1000;
|
||||||
|
const int kWindowSamples = 25;
|
||||||
|
const int kStepSamples = 10;
|
||||||
|
const int16_t kFakeAudioData[] = {
|
||||||
|
0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768,
|
||||||
|
0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768,
|
||||||
|
0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768};
|
||||||
|
|
||||||
|
// Test window function behaviors using default config values.
|
||||||
|
class WindowTestConfig {
|
||||||
|
public:
|
||||||
|
WindowTestConfig() {
|
||||||
|
config_.size_ms = 25;
|
||||||
|
config_.step_size_ms = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WindowConfig config_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(WindowState_CheckCoefficients) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
WindowTestConfig config;
|
||||||
|
struct WindowState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
|
||||||
|
const int16_t expected[] = {16, 144, 391, 743, 1176, 1664, 2177,
|
||||||
|
2681, 3145, 3541, 3843, 4032, 4096, 4032,
|
||||||
|
3843, 3541, 3145, 2681, 2177, 1664, 1176,
|
||||||
|
743, 391, 144, 16};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.size, sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state.size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.coefficients[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(WindowState_CheckResidualInput) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
WindowTestConfig config;
|
||||||
|
struct WindowState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read));
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = kStepSamples; i < kWindowSamples; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.input[i - kStepSamples], kFakeAudioData[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(WindowState_CheckOutputValues) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
WindowTestConfig config;
|
||||||
|
struct WindowState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read));
|
||||||
|
|
||||||
|
const int16_t expected[] = {
|
||||||
|
0, 1151, 0, -5944, 0, 13311, 0, -21448, 0, 28327, 0, -32256, 0, 32255,
|
||||||
|
0, -28328, 0, 21447, 0, -13312, 0, 5943, 0, -1152, 0};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.size, sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state.size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.output[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(WindowState_CheckMaxAbsValue) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
WindowTestConfig config;
|
||||||
|
struct WindowState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read));
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.max_abs_output_value, 32256);
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(WindowState_CheckConsecutiveWindow) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
WindowTestConfig config;
|
||||||
|
struct WindowState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read));
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData + kWindowSamples,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples,
|
||||||
|
&num_samples_read));
|
||||||
|
|
||||||
|
const int16_t expected[] = {
|
||||||
|
0, -1152, 0, 5943, 0, -13312, 0, 21447, 0, -28328, 0, 32255, 0, -32256,
|
||||||
|
0, 28327, 0, -21448, 0, 13311, 0, -5944, 0, 1151, 0};
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.size, sizeof(expected) / sizeof(expected[0]));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state.size; ++i) {
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(state.output[i], expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TEST(WindowState_CheckNotEnoughSamples) {
|
||||||
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
|
WindowTestConfig config;
|
||||||
|
struct WindowState state;
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowPopulateState(error_reporter, &config.config_,
|
||||||
|
&state, kSampleRate));
|
||||||
|
size_t num_samples_read;
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read));
|
||||||
|
TF_LITE_MICRO_EXPECT(WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData + kWindowSamples,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples,
|
||||||
|
&num_samples_read));
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(
|
||||||
|
false, WindowProcessSamples(
|
||||||
|
&state, kFakeAudioData + kWindowSamples + kStepSamples,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) -
|
||||||
|
kWindowSamples - kStepSamples,
|
||||||
|
&num_samples_read));
|
||||||
|
|
||||||
|
TF_LITE_MICRO_EXPECT_EQ(
|
||||||
|
state.input_used,
|
||||||
|
sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - 2 * kStepSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
TF_LITE_MICRO_TESTS_END
|
@ -0,0 +1,57 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window_util.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/static_alloc.h"
|
||||||
|
|
||||||
|
// Needed because some platforms don't have M_PI defined.
|
||||||
|
#define WINDOW_PI (3.14159265358979323846f)
|
||||||
|
|
||||||
|
void WindowFillConfigWithDefaults(struct WindowConfig* config) {
|
||||||
|
config->size_ms = 25;
|
||||||
|
config->step_size_ms = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WindowPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct WindowConfig* config,
|
||||||
|
struct WindowState* state, int sample_rate) {
|
||||||
|
state->size = config->size_ms * sample_rate / 1000;
|
||||||
|
state->step = config->step_size_ms * sample_rate / 1000;
|
||||||
|
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(state->coefficients,
|
||||||
|
(state->size * sizeof(*state->coefficients)));
|
||||||
|
|
||||||
|
// Populate the window values.
|
||||||
|
const float arg = WINDOW_PI * 2.0 / (static_cast<float>(state->size));
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < state->size; ++i) {
|
||||||
|
float float_value = 0.5 - (0.5 * cos(arg * (i + 0.5)));
|
||||||
|
// Scale it to fixed point and round it.
|
||||||
|
state->coefficients[i] =
|
||||||
|
floor(float_value * (1 << kFrontendWindowBits) + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
state->input_used = 0;
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(state->input,
|
||||||
|
(state->size * sizeof(*state->input)));
|
||||||
|
|
||||||
|
STATIC_ALLOC_ENSURE_ARRAY_SIZE(state->output,
|
||||||
|
(state->size * sizeof(*state->output)));
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright 2018 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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_WINDOW_UTIL_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_WINDOW_UTIL_H_
|
||||||
|
|
||||||
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/window.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
|
struct WindowConfig {
|
||||||
|
// length of window frame in milliseconds
|
||||||
|
size_t size_ms;
|
||||||
|
// length of step for next frame in milliseconds
|
||||||
|
size_t step_size_ms;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Populates the WindowConfig with "sane" default values.
|
||||||
|
void WindowFillConfigWithDefaults(struct WindowConfig* config);
|
||||||
|
|
||||||
|
// Allocates any buffers.
|
||||||
|
int WindowPopulateState(tflite::ErrorReporter* error_reporter,
|
||||||
|
const struct WindowConfig* config,
|
||||||
|
struct WindowState* state, int sample_rate);
|
||||||
|
|
||||||
|
// Frees any allocated buffers.
|
||||||
|
void WindowFreeStateContents(struct WindowState* state);
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_WINDOW_UTIL_H_
|
@ -0,0 +1,24 @@
|
|||||||
|
/* 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.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
// See the header for documentation on the meaning of this data.
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h"
|
||||||
|
|
||||||
|
const uint8_t g_yes_feature_data_slice[g_yes_feature_data_slice_size] = {
|
||||||
|
214, 215, 236, 202, 235, 203, 225, 191, 203, 188, 199, 194, 212, 127,
|
||||||
|
51, 0, 174, 188, 219, 196, 228, 221, 240, 207, 235, 220, 241, 219,
|
||||||
|
237, 207, 212, 142, 95, 0, 139, 78, 162, 177, 197, 183,
|
||||||
|
};
|
@ -0,0 +1,29 @@
|
|||||||
|
/* 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.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
// This data was extracted from the larger feature data held in
|
||||||
|
// no_micro_features_data.cc and consists of the 26th spectrogram slice of 40
|
||||||
|
// values. This is the expected result of running the sample data in
|
||||||
|
// yes_30ms_sample_data.cc through through the preprocessing pipeline.
|
||||||
|
|
||||||
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_FEATURE_DATA_SLICE_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_FEATURE_DATA_SLICE_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
constexpr int g_yes_feature_data_slice_size = 40;
|
||||||
|
extern const uint8_t g_yes_feature_data_slice[];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_FEATURE_DATA_SLICE_H_
|
@ -0,0 +1,165 @@
|
|||||||
|
/* 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 "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h"
|
||||||
|
|
||||||
|
/* File automatically created by
|
||||||
|
* tensorflow/examples/speech_commands/wav_to_features.py \
|
||||||
|
* --sample_rate=16000 \
|
||||||
|
* --clip_duration_ms=1000 \
|
||||||
|
* --window_size_ms=30 \
|
||||||
|
* --window_stride_ms=20 \
|
||||||
|
* --feature_bin_count=40 \
|
||||||
|
* --quantize=1 \
|
||||||
|
* --preprocess="micro" \
|
||||||
|
* --input_wav="speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav" \
|
||||||
|
* --output_c_file="yes_micro_features_data.cc" \
|
||||||
|
*/
|
||||||
|
|
||||||
|
const int g_yes_micro_f2e59fea_nohash_1_width = 40;
|
||||||
|
const int g_yes_micro_f2e59fea_nohash_1_height = 49;
|
||||||
|
const unsigned char g_yes_micro_f2e59fea_nohash_1_data[] = {
|
||||||
|
244, 226, 245, 223, 234, 213, 228, 208, 194, 110, 95, 116, 102, 0, 137,
|
||||||
|
161, 183, 173, 137, 116, 133, 157, 151, 156, 128, 110, 128, 0, 68, 78,
|
||||||
|
78, 90, 68, 68, 78, 102, 95, 78, 95, 78, 210, 188, 209, 183, 204,
|
||||||
|
188, 201, 191, 166, 119, 90, 107, 110, 107, 175, 157, 179, 168, 182, 145,
|
||||||
|
152, 164, 171, 165, 136, 143, 122, 68, 0, 78, 90, 90, 110, 90, 102,
|
||||||
|
99, 90, 68, 78, 68, 223, 186, 179, 123, 182, 110, 196, 171, 159, 110,
|
||||||
|
102, 95, 90, 99, 160, 134, 125, 136, 153, 152, 164, 134, 164, 151, 141,
|
||||||
|
136, 99, 90, 90, 90, 78, 78, 102, 119, 102, 90, 110, 90, 68, 51,
|
||||||
|
177, 175, 211, 172, 183, 0, 95, 68, 129, 102, 68, 85, 114, 105, 110,
|
||||||
|
85, 102, 95, 140, 51, 85, 51, 95, 90, 143, 116, 90, 78, 78, 51,
|
||||||
|
107, 85, 68, 0, 68, 51, 90, 51, 68, 0, 164, 117, 193, 120, 156,
|
||||||
|
0, 138, 51, 90, 0, 51, 0, 51, 85, 0, 0, 51, 0, 0, 0,
|
||||||
|
0, 0, 114, 0, 85, 78, 90, 51, 0, 0, 51, 85, 99, 85, 107,
|
||||||
|
68, 90, 85, 78, 0, 51, 0, 110, 0, 68, 0, 0, 0, 51, 0,
|
||||||
|
51, 0, 0, 0, 68, 90, 107, 0, 68, 0, 0, 0, 68, 0, 51,
|
||||||
|
68, 0, 78, 68, 0, 51, 0, 78, 68, 90, 68, 78, 51, 51, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0,
|
||||||
|
0, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 68,
|
||||||
|
0, 0, 78, 0, 78, 0, 78, 0, 51, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 51, 0, 51, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 0, 51,
|
||||||
|
0, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51,
|
||||||
|
0, 0, 0, 0, 51, 78, 0, 0, 51, 51, 0, 0, 0, 78, 0,
|
||||||
|
213, 170, 192, 180, 196, 188, 173, 131, 173, 116, 137, 105, 159, 127, 0,
|
||||||
|
0, 0, 0, 127, 164, 165, 161, 170, 164, 185, 197, 195, 167, 134, 138,
|
||||||
|
159, 134, 136, 105, 51, 0, 99, 0, 51, 0, 228, 215, 229, 218, 237,
|
||||||
|
215, 228, 210, 237, 222, 239, 211, 208, 211, 234, 218, 220, 209, 225, 219,
|
||||||
|
235, 222, 245, 225, 245, 224, 243, 223, 241, 218, 237, 224, 234, 213, 221,
|
||||||
|
193, 197, 164, 157, 128, 227, 188, 232, 196, 220, 220, 240, 219, 234, 213,
|
||||||
|
234, 211, 231, 218, 233, 213, 239, 215, 228, 207, 229, 206, 224, 208, 226,
|
||||||
|
207, 232, 210, 225, 208, 230, 199, 227, 206, 210, 205, 218, 174, 178, 141,
|
||||||
|
235, 208, 220, 206, 225, 203, 233, 203, 225, 167, 205, 199, 208, 190, 221,
|
||||||
|
204, 223, 207, 225, 188, 225, 197, 215, 188, 199, 183, 225, 195, 224, 200,
|
||||||
|
216, 178, 208, 188, 215, 202, 214, 183, 176, 140, 198, 150, 211, 194, 203,
|
||||||
|
120, 175, 188, 204, 189, 219, 192, 223, 202, 216, 186, 203, 185, 210, 182,
|
||||||
|
214, 183, 204, 170, 204, 125, 184, 187, 206, 185, 198, 182, 210, 161, 202,
|
||||||
|
198, 218, 173, 145, 120, 188, 183, 205, 168, 200, 170, 210, 177, 187, 190,
|
||||||
|
209, 193, 193, 166, 210, 162, 175, 119, 174, 147, 182, 161, 181, 134, 176,
|
||||||
|
143, 187, 165, 186, 149, 185, 141, 192, 181, 202, 123, 170, 143, 144, 78,
|
||||||
|
149, 0, 208, 182, 170, 78, 170, 0, 117, 51, 156, 99, 195, 170, 200,
|
||||||
|
130, 152, 68, 175, 141, 173, 134, 194, 132, 189, 164, 198, 134, 173, 117,
|
||||||
|
171, 149, 183, 181, 185, 99, 153, 117, 125, 0, 166, 0, 173, 117, 144,
|
||||||
|
0, 117, 102, 188, 120, 193, 166, 197, 68, 163, 119, 169, 99, 134, 0,
|
||||||
|
162, 0, 164, 68, 171, 116, 126, 0, 120, 68, 68, 0, 105, 0, 159,
|
||||||
|
95, 150, 51, 90, 85, 0, 0, 131, 0, 105, 0, 145, 51, 170, 51,
|
||||||
|
120, 0, 107, 0, 145, 85, 160, 0, 85, 0, 0, 51, 149, 0, 78,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 90, 0, 112, 0, 78, 102, 122, 0,
|
||||||
|
0, 0, 0, 0, 105, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112,
|
||||||
|
0, 164, 120, 143, 0, 0, 0, 0, 0, 51, 0, 90, 0, 78, 0,
|
||||||
|
0, 0, 0, 0, 110, 0, 139, 0, 112, 51, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 102, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 107,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 0, 51, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 127, 110, 133, 0, 167, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 132, 0, 190,
|
||||||
|
194, 202, 0, 197, 187, 161, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
214, 213, 223, 203, 218, 189, 200, 122, 78, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 191, 210, 231, 197, 226, 217, 238, 216, 236, 207,
|
||||||
|
199, 0, 0, 0, 0, 0, 107, 122, 155, 160, 214, 215, 236, 202, 235,
|
||||||
|
203, 225, 191, 203, 188, 199, 194, 212, 127, 51, 0, 174, 188, 219, 196,
|
||||||
|
228, 221, 240, 207, 235, 220, 241, 219, 237, 207, 212, 142, 95, 0, 139,
|
||||||
|
78, 162, 177, 197, 183, 211, 199, 235, 208, 238, 215, 227, 207, 211, 201,
|
||||||
|
224, 213, 226, 192, 213, 170, 223, 205, 234, 221, 245, 225, 242, 220, 245,
|
||||||
|
221, 239, 221, 238, 213, 226, 180, 159, 112, 176, 159, 208, 202, 213, 191,
|
||||||
|
205, 191, 225, 197, 238, 219, 224, 201, 227, 200, 221, 201, 225, 203, 212,
|
||||||
|
195, 229, 210, 228, 210, 239, 216, 226, 212, 233, 205, 225, 200, 229, 207,
|
||||||
|
222, 151, 147, 119, 179, 185, 230, 218, 223, 192, 202, 136, 205, 177, 223,
|
||||||
|
204, 228, 215, 232, 209, 221, 189, 221, 205, 209, 200, 226, 209, 229, 205,
|
||||||
|
235, 192, 209, 198, 228, 190, 206, 185, 207, 187, 214, 175, 177, 184, 220,
|
||||||
|
195, 214, 207, 230, 184, 205, 159, 208, 184, 189, 169, 224, 213, 219, 199,
|
||||||
|
229, 203, 216, 205, 222, 204, 224, 206, 231, 208, 231, 176, 197, 184, 216,
|
||||||
|
193, 211, 139, 212, 195, 231, 164, 166, 195, 217, 182, 208, 190, 217, 179,
|
||||||
|
205, 68, 182, 119, 195, 168, 182, 136, 204, 179, 193, 158, 182, 140, 188,
|
||||||
|
154, 197, 169, 190, 99, 184, 0, 125, 0, 131, 0, 99, 68, 179, 85,
|
||||||
|
190, 184, 213, 203, 223, 202, 212, 190, 209, 138, 178, 0, 159, 51, 128,
|
||||||
|
51, 105, 0, 139, 51, 179, 125, 185, 114, 171, 128, 175, 132, 181, 174,
|
||||||
|
155, 0, 0, 0, 90, 0, 125, 0, 176, 188, 227, 217, 244, 215, 234,
|
||||||
|
221, 239, 192, 224, 210, 0, 0, 134, 0, 51, 0, 105, 0, 105, 0,
|
||||||
|
143, 90, 192, 119, 175, 147, 141, 51, 184, 110, 85, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 151, 139, 201, 203, 232, 203, 226, 208, 236, 206, 230, 212,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 169, 0, 119,
|
||||||
|
0, 78, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 133,
|
||||||
|
200, 180, 220, 197, 228, 201, 221, 184, 213, 193, 110, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 78, 0, 164, 0, 0, 0, 0, 0, 107, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 150, 164, 202, 182, 224,
|
||||||
|
197, 211, 179, 212, 193, 134, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
85, 0, 150, 0, 85, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 102, 90, 193, 160, 203, 164, 200, 178, 205, 174,
|
||||||
|
116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 114, 123, 0, 114,
|
||||||
|
0, 145, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
102, 68, 199, 170, 195, 180, 208, 176, 200, 164, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 110, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 142, 102, 172, 110, 186,
|
||||||
|
167, 185, 147, 189, 154, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 177, 0, 158, 136, 197, 155, 189, 166,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
85, 0, 155, 90, 175, 117, 175, 138, 202, 165, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 0, 139,
|
||||||
|
0, 120, 68, 51, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 119, 0, 78, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
};
|
@ -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_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_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 unsigned char g_yes_micro_f2e59fea_nohash_1_data[];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_
|
@ -13,9 +13,9 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_features_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/no_micro_features_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/tiny_conv_micro_features_model_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_features_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/yes_micro_features_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h"
|
#include "tensorflow/lite/experimental/micro/kernels/all_ops_resolver.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_interpreter.h"
|
#include "tensorflow/lite/experimental/micro/micro_interpreter.h"
|
||||||
@ -32,7 +32,8 @@ TF_LITE_MICRO_TEST(TestInvoke) {
|
|||||||
|
|
||||||
// Map the model into a usable data structure. This doesn't involve any
|
// Map the model into a usable data structure. This doesn't involve any
|
||||||
// copying or parsing, it's a very lightweight operation.
|
// copying or parsing, it's a very lightweight operation.
|
||||||
const tflite::Model* model = ::tflite::GetModel(g_tiny_conv_model_data);
|
const tflite::Model* model =
|
||||||
|
::tflite::GetModel(g_tiny_conv_micro_features_model_data);
|
||||||
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
||||||
error_reporter->Report(
|
error_reporter->Report(
|
||||||
"Model provided is schema version %d not equal "
|
"Model provided is schema version %d not equal "
|
||||||
@ -61,12 +62,12 @@ TF_LITE_MICRO_TEST(TestInvoke) {
|
|||||||
TF_LITE_MICRO_EXPECT_EQ(4, input->dims->size);
|
TF_LITE_MICRO_EXPECT_EQ(4, input->dims->size);
|
||||||
TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]);
|
TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]);
|
||||||
TF_LITE_MICRO_EXPECT_EQ(49, input->dims->data[1]);
|
TF_LITE_MICRO_EXPECT_EQ(49, input->dims->data[1]);
|
||||||
TF_LITE_MICRO_EXPECT_EQ(43, input->dims->data[2]);
|
TF_LITE_MICRO_EXPECT_EQ(40, input->dims->data[2]);
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteUInt8, input->type);
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteUInt8, input->type);
|
||||||
|
|
||||||
// Copy a spectrogram created from a .wav audio file of someone saying "Yes",
|
// Copy a spectrogram created from a .wav audio file of someone saying "Yes",
|
||||||
// into the memory area used for the input.
|
// into the memory area used for the input.
|
||||||
const uint8_t* yes_features_data = g_yes_f2e59fea_nohash_1_data;
|
const uint8_t* yes_features_data = g_yes_micro_f2e59fea_nohash_1_data;
|
||||||
for (int i = 0; i < input->bytes; ++i) {
|
for (int i = 0; i < input->bytes; ++i) {
|
||||||
input->data.uint8[i] = yes_features_data[i];
|
input->data.uint8[i] = yes_features_data[i];
|
||||||
}
|
}
|
||||||
@ -102,7 +103,7 @@ TF_LITE_MICRO_TEST(TestInvoke) {
|
|||||||
TF_LITE_MICRO_EXPECT_GT(yes_score, no_score);
|
TF_LITE_MICRO_EXPECT_GT(yes_score, no_score);
|
||||||
|
|
||||||
// Now test with a different input, from a recording of "No".
|
// Now test with a different input, from a recording of "No".
|
||||||
const uint8_t* no_features_data = g_no_f9643d42_nohash_4_data;
|
const uint8_t* no_features_data = g_no_micro_f9643d42_nohash_4_data;
|
||||||
for (int i = 0; i < input->bytes; ++i) {
|
for (int i = 0; i < input->bytes; ++i) {
|
||||||
input->data.uint8[i] = no_features_data[i];
|
input->data.uint8[i] = no_features_data[i];
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
|||||||
|
/* 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.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
// This data was created from the PCM data in a WAV file held in v2 of the
|
||||||
|
// Speech Commands test dataset, at the path:
|
||||||
|
// speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav
|
||||||
|
// This should contain all 16,000 samples from the one-second file.
|
||||||
|
|
||||||
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_1000MS_SAMPLE_DATA_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_1000MS_SAMPLE_DATA_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
extern const int g_no_1000ms_sample_data_size;
|
||||||
|
extern const int16_t g_no_1000ms_sample_data[];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_1000MS_SAMPLE_DATA_H_
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <AudioToolbox/AudioToolbox.h>
|
#include <AudioToolbox/AudioToolbox.h>
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_model_settings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ RecognizeCommands::RecognizeCommands(tflite::ErrorReporter* error_reporter,
|
|||||||
suppression_ms_(suppression_ms),
|
suppression_ms_(suppression_ms),
|
||||||
minimum_count_(minimum_count),
|
minimum_count_(minimum_count),
|
||||||
previous_results_(error_reporter) {
|
previous_results_(error_reporter) {
|
||||||
previous_top_label_ = "_silence_";
|
previous_top_label_ = "silence";
|
||||||
previous_top_label_time_ = 0;
|
previous_top_label_time_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ limitations under the License.
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "tensorflow/lite/c/c_api_internal.h"
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
|
|
||||||
// Partial implementation of std::dequeue, just providing the functionality
|
// Partial implementation of std::dequeue, just providing the functionality
|
||||||
@ -129,8 +129,8 @@ class RecognizeCommands {
|
|||||||
// help reduce spurious recognitions.
|
// help reduce spurious recognitions.
|
||||||
explicit RecognizeCommands(tflite::ErrorReporter* error_reporter,
|
explicit RecognizeCommands(tflite::ErrorReporter* error_reporter,
|
||||||
int32_t average_window_duration_ms = 1000,
|
int32_t average_window_duration_ms = 1000,
|
||||||
uint8_t detection_threshold = 51,
|
uint8_t detection_threshold = 200,
|
||||||
int32_t suppression_ms = 500,
|
int32_t suppression_ms = 1500,
|
||||||
int32_t minimum_count = 3);
|
int32_t minimum_count = 3);
|
||||||
|
|
||||||
// Call this with the results of running a model on sample data.
|
// Call this with the results of running a model on sample data.
|
||||||
|
@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#define IFFT_FLAG_R 0
|
#define IFFT_FLAG_R 0
|
||||||
#define BIT_REVERSE_FLAG 1
|
#define BIT_REVERSE_FLAG 1
|
||||||
@ -23,8 +25,6 @@ extern "C" {
|
|||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/CMSIS/hanning.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/CMSIS/hanning.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h"
|
|
||||||
|
|
||||||
void quantize(q15_t* bufA, q15_t* bufB, uint8_t* output);
|
void quantize(q15_t* bufA, q15_t* bufB, uint8_t* output);
|
||||||
|
|
||||||
q15_t bufA[FFT_SIZE];
|
q15_t bufA[FFT_SIZE];
|
||||||
@ -41,9 +41,9 @@ constexpr int kOutputSize =
|
|||||||
((kInputSize / 2) + (kAverageWindowSize - 1)) / kAverageWindowSize;
|
((kInputSize / 2) + (kAverageWindowSize - 1)) / kAverageWindowSize;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TfLiteStatus Preprocess(tflite::ErrorReporter* error_reporter,
|
TfLiteStatus GenerateSimpleFeatures(tflite::ErrorReporter* error_reporter,
|
||||||
const int16_t* input, int input_size, int output_size,
|
const int16_t* input, int input_size,
|
||||||
uint8_t* output) {
|
int output_size, uint8_t* output) {
|
||||||
if (input_size > kInputSize) {
|
if (input_size > kInputSize) {
|
||||||
error_reporter->Report("Input size %d larger than %d", input_size,
|
error_reporter->Report("Input size %d larger than %d", input_size,
|
||||||
kInputSize);
|
kInputSize);
|
||||||
@ -93,12 +93,3 @@ void quantize(q15_t* bufA, q15_t* bufB, uint8_t* output) {
|
|||||||
output[i] = (uint8_t)(bufA[i] >> 5);
|
output[i] = (uint8_t)(bufA[i] >> 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TfLiteStatus Preprocess_1sec(tflite::ErrorReporter* error_reporter,
|
|
||||||
const int16_t* input, uint8_t* output) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 49; i++) {
|
|
||||||
Preprocess(error_reporter, input + i * 320, 480, 43, output + i * 43);
|
|
||||||
}
|
|
||||||
return kTfLiteOk;
|
|
||||||
}
|
|
@ -27,11 +27,11 @@ limitations under the License.
|
|||||||
// instead of floating point, to help show how this can work on platforms that
|
// instead of floating point, to help show how this can work on platforms that
|
||||||
// don't have good float support.
|
// don't have good float support.
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_model_settings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -118,9 +118,9 @@ void CalculatePeriodicHann(int window_length, int16_t* window_function) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TfLiteStatus Preprocess(tflite::ErrorReporter* error_reporter,
|
TfLiteStatus GenerateSimpleFeatures(tflite::ErrorReporter* error_reporter,
|
||||||
const int16_t* input, int input_size, int output_size,
|
const int16_t* input, int input_size,
|
||||||
uint8_t* output) {
|
int output_size, uint8_t* output) {
|
||||||
// Ensure our input and output data arrays are valid.
|
// Ensure our input and output data arrays are valid.
|
||||||
if (input_size > kMaxAudioSampleSize) {
|
if (input_size > kMaxAudioSampleSize) {
|
||||||
error_reporter->Report("Input size %d larger than %d", input_size,
|
error_reporter->Report("Input size %d larger than %d", input_size,
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
|
|
||||||
// See the header for documentation on the meaning of this data.
|
// See the header for documentation on the meaning of this data.
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_power_spectrum_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h"
|
||||||
|
|
||||||
const uint8_t g_no_power_spectrum_data[g_no_power_spectrum_data_size] = {
|
const uint8_t g_no_power_spectrum_data[g_no_power_spectrum_data_size] = {
|
||||||
255, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
255, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
@ -18,12 +18,12 @@ limitations under the License.
|
|||||||
// This is the expected result of running the sample data in
|
// This is the expected result of running the sample data in
|
||||||
// no_30ms_sample_data.cc through through the preprocessing pipeline.
|
// no_30ms_sample_data.cc through through the preprocessing pipeline.
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_POWER_SPECTRUM_DATA_H_
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_POWER_SPECTRUM_DATA_H_
|
||||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_POWER_SPECTRUM_DATA_H_
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_POWER_SPECTRUM_DATA_H_
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
constexpr int g_no_power_spectrum_data_size = 43;
|
constexpr int g_no_power_spectrum_data_size = 43;
|
||||||
extern const uint8_t g_no_power_spectrum_data[];
|
extern const uint8_t g_no_power_spectrum_data[];
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_POWER_SPECTRUM_DATA_H_
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_POWER_SPECTRUM_DATA_H_
|
@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_features_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/no_simple_features_data.h"
|
||||||
|
|
||||||
/* File automatically created by
|
/* File automatically created by
|
||||||
* tensorflow/examples/speech_commands/wav_to_features.py \
|
* tensorflow/examples/speech_commands/wav_to_features.py \
|
||||||
@ -22,15 +22,15 @@ limitations under the License.
|
|||||||
* --window_size_ms=30 \
|
* --window_size_ms=30 \
|
||||||
* --window_stride_ms=20 \
|
* --window_stride_ms=20 \
|
||||||
* --feature_bin_count=40 \
|
* --feature_bin_count=40 \
|
||||||
* --quantize \
|
* --quantize=1 \
|
||||||
* --preprocess="average" \
|
* --preprocess="average" \
|
||||||
* --input_wav="speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav" \
|
* --input_wav="speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav" \
|
||||||
* --output_c_file="no_features_data.cc" \
|
* --output_c_file="no_simple_features_data.cc" \
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const int g_no_f9643d42_nohash_4_width = 43;
|
const int g_no_simple_f9643d42_nohash_4_width = 43;
|
||||||
const int g_no_f9643d42_nohash_4_height = 49;
|
const int g_no_simple_f9643d42_nohash_4_height = 49;
|
||||||
const unsigned char g_no_f9643d42_nohash_4_data[] = {
|
const unsigned char g_no_simple_f9643d42_nohash_4_data[] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
@ -13,11 +13,11 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_FEATURES_DATA_H_
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_SIMPLE_FEATURES_DATA_H_
|
||||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_FEATURES_DATA_H_
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_SIMPLE_FEATURES_DATA_H_
|
||||||
|
|
||||||
extern const int g_no_f9643d42_nohash_4_width;
|
extern const int g_no_simple_f9643d42_nohash_4_width;
|
||||||
extern const int g_no_f9643d42_nohash_4_height;
|
extern const int g_no_simple_f9643d42_nohash_4_height;
|
||||||
extern const unsigned char g_no_f9643d42_nohash_4_data[];
|
extern const unsigned char g_no_simple_f9643d42_nohash_4_data[];
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_NO_FEATURES_DATA_H_
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_SIMPLE_FEATURES_DATA_H_
|
@ -24,11 +24,11 @@ limitations under the License.
|
|||||||
// functions used here, for example replacing the DFT with an FFT, so this
|
// functions used here, for example replacing the DFT with an FFT, so this
|
||||||
// version shouldn't be used where performance is critical.
|
// version shouldn't be used where performance is critical.
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/model_settings.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_model_settings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -72,9 +72,9 @@ void CalculatePeriodicHann(int window_length, float* window_function) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TfLiteStatus Preprocess(tflite::ErrorReporter* error_reporter,
|
TfLiteStatus GenerateSimpleFeatures(tflite::ErrorReporter* error_reporter,
|
||||||
const int16_t* input, int input_size, int output_size,
|
const int16_t* input, int input_size,
|
||||||
uint8_t* output) {
|
int output_size, uint8_t* output) {
|
||||||
// Ensure our input and output data arrays are valid.
|
// Ensure our input and output data arrays are valid.
|
||||||
if (input_size > kMaxAudioSampleSize) {
|
if (input_size > kMaxAudioSampleSize) {
|
||||||
error_reporter->Report("Input size %d larger than %d", input_size,
|
error_reporter->Report("Input size %d larger than %d", input_size,
|
||||||
@ -146,12 +146,3 @@ TfLiteStatus Preprocess(tflite::ErrorReporter* error_reporter,
|
|||||||
}
|
}
|
||||||
return kTfLiteOk;
|
return kTfLiteOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
TfLiteStatus Preprocess_1sec(tflite::ErrorReporter* error_reporter,
|
|
||||||
const int16_t* input, uint8_t* output) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 49; i++) {
|
|
||||||
Preprocess(error_reporter, input + i * 320, 480, 43, output + i * 43);
|
|
||||||
}
|
|
||||||
return kTfLiteOk;
|
|
||||||
}
|
|
@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_PREPROCESSOR_H_
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_FEATURES_GENERATOR_H_
|
||||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_PREPROCESSOR_H_
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_FEATURES_GENERATOR_H_
|
||||||
|
|
||||||
#include "tensorflow/lite/c/c_api_internal.h"
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
@ -24,11 +24,8 @@ limitations under the License.
|
|||||||
// both floating point and fixed point available, but because the calculations
|
// both floating point and fixed point available, but because the calculations
|
||||||
// involved can be time-consuming, it's recommended that you use or write
|
// involved can be time-consuming, it's recommended that you use or write
|
||||||
// specialized versions for your platform.
|
// specialized versions for your platform.
|
||||||
TfLiteStatus Preprocess(tflite::ErrorReporter* error_reporter,
|
TfLiteStatus GenerateSimpleFeatures(tflite::ErrorReporter* error_reporter,
|
||||||
const int16_t* input, int input_size, int output_size,
|
const int16_t* input, int input_size,
|
||||||
uint8_t* output);
|
int output_size, uint8_t* output);
|
||||||
|
|
||||||
TfLiteStatus Preprocess_1sec(tflite::ErrorReporter* error_reporter,
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_FEATURES_GENERATOR_H_
|
||||||
const int16_t* input, uint8_t* output);
|
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_PREPROCESSOR_H_
|
|
@ -13,23 +13,23 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/preprocessor.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_features_generator.h"
|
||||||
#include "tensorflow/lite/c/c_api_internal.h"
|
#include "tensorflow/lite/c/c_api_internal.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_30ms_sample_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/no_power_spectrum_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h"
|
||||||
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_30ms_sample_data.h"
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_power_spectrum_data.h"
|
|
||||||
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
|
||||||
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
#include "tensorflow/lite/experimental/micro/testing/micro_test.h"
|
||||||
|
|
||||||
TF_LITE_MICRO_TESTS_BEGIN
|
TF_LITE_MICRO_TESTS_BEGIN
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(TestPreprocessor) {
|
TF_LITE_MICRO_TEST(TestSimpleFeaturesGenerator) {
|
||||||
tflite::MicroErrorReporter micro_error_reporter;
|
tflite::MicroErrorReporter micro_error_reporter;
|
||||||
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
tflite::ErrorReporter* error_reporter = µ_error_reporter;
|
||||||
|
|
||||||
uint8_t yes_calculated_data[g_yes_power_spectrum_data_size];
|
uint8_t yes_calculated_data[g_yes_power_spectrum_data_size];
|
||||||
TfLiteStatus yes_status = Preprocess(
|
TfLiteStatus yes_status = GenerateSimpleFeatures(
|
||||||
error_reporter, g_yes_30ms_sample_data, g_yes_30ms_sample_data_size,
|
error_reporter, g_yes_30ms_sample_data, g_yes_30ms_sample_data_size,
|
||||||
g_yes_power_spectrum_data_size, yes_calculated_data);
|
g_yes_power_spectrum_data_size, yes_calculated_data);
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, yes_status);
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, yes_status);
|
||||||
@ -45,7 +45,7 @@ TF_LITE_MICRO_TEST(TestPreprocessor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t no_calculated_data[g_yes_power_spectrum_data_size];
|
uint8_t no_calculated_data[g_yes_power_spectrum_data_size];
|
||||||
TfLiteStatus no_status = Preprocess(
|
TfLiteStatus no_status = GenerateSimpleFeatures(
|
||||||
error_reporter, g_no_30ms_sample_data, g_no_30ms_sample_data_size,
|
error_reporter, g_no_30ms_sample_data, g_no_30ms_sample_data_size,
|
||||||
g_no_power_spectrum_data_size, no_calculated_data);
|
g_no_power_spectrum_data_size, no_calculated_data);
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, no_status);
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, no_status);
|
@ -0,0 +1,23 @@
|
|||||||
|
/* Copyright 2018 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 "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/simple_model_settings.h"
|
||||||
|
|
||||||
|
const char* kCategoryLabels[kCategoryCount] = {
|
||||||
|
"silence",
|
||||||
|
"unknown",
|
||||||
|
"yes",
|
||||||
|
"no",
|
||||||
|
};
|
@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MODEL_SETTINGS_H_
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_MODEL_SETTINGS_H_
|
||||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MODEL_SETTINGS_H_
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_MODEL_SETTINGS_H_
|
||||||
|
|
||||||
// Keeping these as constant expressions allow us to allocate fixed-sized arrays
|
// Keeping these as constant expressions allow us to allocate fixed-sized arrays
|
||||||
// on the stack for our working memory.
|
// on the stack for our working memory.
|
||||||
@ -40,4 +40,4 @@ constexpr int kSilenceIndex = 0;
|
|||||||
constexpr int kUnknownIndex = 1;
|
constexpr int kUnknownIndex = 1;
|
||||||
extern const char* kCategoryLabels[kCategoryCount];
|
extern const char* kCategoryLabels[kCategoryCount];
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_MODEL_SETTINGS_H_
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_MODEL_SETTINGS_H_
|
@ -14,12 +14,12 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
// Automatically created from a TensorFlow Lite flatbuffer using the command:
|
// Automatically created from a TensorFlow Lite flatbuffer using the command:
|
||||||
// xxd -i tiny_conv.tflite > tiny_conv_model_data.cc
|
// xxd -i tiny_conv.tflite > tiny_conv_simple_features_model_data.cc
|
||||||
// See the README for a full description of the creation process.
|
// See the README for a full description of the creation process.
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/tiny_conv_model_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/tiny_conv_simple_features_model_data.h"
|
||||||
|
|
||||||
const unsigned char g_tiny_conv_model_data[] = {
|
const unsigned char g_tiny_conv_simple_features_model_data[] = {
|
||||||
0x18, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x0e, 0x00,
|
0x18, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x0e, 0x00,
|
||||||
0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00,
|
0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00,
|
||||||
0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4d, 0x00, 0x00,
|
0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4d, 0x00, 0x00,
|
||||||
@ -1670,4 +1670,4 @@ const unsigned char g_tiny_conv_model_data[] = {
|
|||||||
0x04, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0xff, 0x00, 0x19, 0x06, 0x00,
|
0x04, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0xff, 0x00, 0x19, 0x06, 0x00,
|
||||||
0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x00,
|
0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x00,
|
||||||
0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04};
|
0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04};
|
||||||
const int g_tiny_conv_model_data_len = 19800;
|
const int g_tiny_conv_simple_features_model_data_len = 19800;
|
@ -16,12 +16,12 @@ limitations under the License.
|
|||||||
// This is a standard TensorFlow Lite model file that has been converted into a
|
// This is a standard TensorFlow Lite model file that has been converted into a
|
||||||
// C data array, so it can be easily compiled into a binary for devices that
|
// 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:
|
// don't have a file system. It was created using the command:
|
||||||
// xxd -i tiny_conv.tflite > tiny_conv_model_data.cc
|
// xxd -i tiny_conv.tflite > tiny_conv_simple_features_model_data.cc
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_TINY_CONV_MODEL_DATA_H_
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_TINY_CONV_SIMPLE_FEATURES_MODEL_DATA_H_
|
||||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_TINY_CONV_MODEL_DATA_H_
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_TINY_CONV_SIMPLE_FEATURES_MODEL_DATA_H_
|
||||||
|
|
||||||
extern const unsigned char g_tiny_conv_model_data[];
|
extern const unsigned char g_tiny_conv_simple_features_model_data[];
|
||||||
extern const int g_tiny_conv_model_data_len;
|
extern const int g_tiny_conv_simple_features_model_data_len;
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_TINY_CONV_MODEL_DATA_H_
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_TINY_CONV_SIMPLE_FEATURES_MODEL_DATA_H_
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
|
|
||||||
// See the header for documentation on the meaning of this data.
|
// See the header for documentation on the meaning of this data.
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_power_spectrum_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h"
|
||||||
|
|
||||||
const uint8_t g_yes_power_spectrum_data[g_yes_power_spectrum_data_size] = {
|
const uint8_t g_yes_power_spectrum_data[g_yes_power_spectrum_data_size] = {
|
||||||
8, 89, 8, 0, 0, 0, 0, 0, 0, 0, 0, 4, 13, 1, 6, 23, 20, 6, 4, 0, 0, 0,
|
8, 89, 8, 0, 0, 0, 0, 0, 0, 0, 0, 4, 13, 1, 6, 23, 20, 6, 4, 0, 0, 0,
|
@ -18,12 +18,12 @@ limitations under the License.
|
|||||||
// This is the expected result of running the sample data in
|
// This is the expected result of running the sample data in
|
||||||
// yes_30ms_sample_data.cc through through the preprocessing pipeline.
|
// yes_30ms_sample_data.cc through through the preprocessing pipeline.
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_POWER_SPECTRUM_DATA_H_
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_POWER_SPECTRUM_DATA_H_
|
||||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_POWER_SPECTRUM_DATA_H_
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_POWER_SPECTRUM_DATA_H_
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
constexpr int g_yes_power_spectrum_data_size = 43;
|
constexpr int g_yes_power_spectrum_data_size = 43;
|
||||||
extern const uint8_t g_yes_power_spectrum_data[];
|
extern const uint8_t g_yes_power_spectrum_data[];
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_POWER_SPECTRUM_DATA_H_
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_POWER_SPECTRUM_DATA_H_
|
@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#include "tensorflow/lite/experimental/micro/examples/micro_speech/yes_features_data.h"
|
#include "tensorflow/lite/experimental/micro/examples/micro_speech/simple_features/yes_simple_features_data.h"
|
||||||
|
|
||||||
/* File automatically created by
|
/* File automatically created by
|
||||||
* tensorflow/examples/speech_commands/wav_to_features.py \
|
* tensorflow/examples/speech_commands/wav_to_features.py \
|
||||||
@ -22,15 +22,15 @@ limitations under the License.
|
|||||||
* --window_size_ms=30 \
|
* --window_size_ms=30 \
|
||||||
* --window_stride_ms=20 \
|
* --window_stride_ms=20 \
|
||||||
* --feature_bin_count=40 \
|
* --feature_bin_count=40 \
|
||||||
* --quantize \
|
* --quantize=1 \
|
||||||
* --preprocess="average" \
|
* --preprocess="average" \
|
||||||
* --input_wav="speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav" \
|
* --input_wav="speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav" \
|
||||||
* --output_c_file="yes_features_data.cc" \
|
* --output_c_file="yes_simple_features_data.cc" \
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const int g_yes_f2e59fea_nohash_1_width = 43;
|
const int g_yes_simple_f2e59fea_nohash_1_width = 43;
|
||||||
const int g_yes_f2e59fea_nohash_1_height = 49;
|
const int g_yes_simple_f2e59fea_nohash_1_height = 49;
|
||||||
const unsigned char g_yes_f2e59fea_nohash_1_data[] = {
|
const unsigned char g_yes_simple_f2e59fea_nohash_1_data[] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
@ -13,11 +13,11 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_FEATURES_DATA_H_
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_SIMPLE_FEATURES_DATA_H_
|
||||||
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_FEATURES_DATA_H_
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_SIMPLE_FEATURES_DATA_H_
|
||||||
|
|
||||||
extern const int g_yes_f2e59fea_nohash_1_width;
|
extern const int g_yes_simple_f2e59fea_nohash_1_width;
|
||||||
extern const int g_yes_f2e59fea_nohash_1_height;
|
extern const int g_yes_simple_f2e59fea_nohash_1_height;
|
||||||
extern const unsigned char g_yes_f2e59fea_nohash_1_data[];
|
extern const unsigned char g_yes_simple_f2e59fea_nohash_1_data[];
|
||||||
|
|
||||||
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_FEATURES_DATA_H_
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_SIMPLE_FEATURES_DATA_H_
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
|||||||
|
/* 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.
|
||||||
|
==============================================================================*/
|
||||||
|
|
||||||
|
// This data was created from the PCM data in a WAV file held in v2 of the
|
||||||
|
// Speech Commands test dataset, at the path:
|
||||||
|
// speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav
|
||||||
|
// This should contain all 16,000 samples from the one-second file.
|
||||||
|
|
||||||
|
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_1000MS_SAMPLE_DATA_H_
|
||||||
|
#define TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_1000MS_SAMPLE_DATA_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
extern const int g_yes_1000ms_sample_data_size;
|
||||||
|
extern const int16_t g_yes_1000ms_sample_data[];
|
||||||
|
|
||||||
|
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICRO_EXAMPLES_MICRO_SPEECH_YES_1000MS_SAMPLE_DATA_H_
|
@ -110,8 +110,8 @@ extern tflite::ErrorReporter* reporter;
|
|||||||
#define TF_LITE_MICRO_EXPECT_EQ(x, y) \
|
#define TF_LITE_MICRO_EXPECT_EQ(x, y) \
|
||||||
do { \
|
do { \
|
||||||
if ((x) != (y)) { \
|
if ((x) != (y)) { \
|
||||||
micro_test::reporter->Report(#x " == " #y " failed at %s:%d", __FILE__, \
|
micro_test::reporter->Report(#x " == " #y " failed at %s:%d (%d vs %d)", \
|
||||||
__LINE__); \
|
__FILE__, __LINE__, (x), (y)); \
|
||||||
micro_test::did_test_fail = true; \
|
micro_test::did_test_fail = true; \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
@ -39,6 +39,7 @@ AM_SDK_URL="http://s3.asia.ambiqmicro.com/downloads/AmbiqSuite-Rel2.0.0.zip"
|
|||||||
AP3_URL="https://github.com/AmbiqMicro/TFLiteMicro_Apollo3/archive/dfbcef9a57276c087d95aab7cb234f1d4c9eaaba.zip"
|
AP3_URL="https://github.com/AmbiqMicro/TFLiteMicro_Apollo3/archive/dfbcef9a57276c087d95aab7cb234f1d4c9eaaba.zip"
|
||||||
CUST_CMSIS_URL="https://github.com/AmbiqMicro/TFLiteMicro_CustCMSIS/archive/8f63966c5692e6a3a83956efd2e4aed77c4c9949.zip"
|
CUST_CMSIS_URL="https://github.com/AmbiqMicro/TFLiteMicro_CustCMSIS/archive/8f63966c5692e6a3a83956efd2e4aed77c4c9949.zip"
|
||||||
GCC_EMBEDDED_URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2"
|
GCC_EMBEDDED_URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2"
|
||||||
|
KISSFFT_URL="http://downloads.sourceforge.net/project/kissfft/kissfft/v1_3_0/kiss_fft130.zip"
|
||||||
|
|
||||||
download_and_extract() {
|
download_and_extract() {
|
||||||
local usage="Usage: download_and_extract URL DIR"
|
local usage="Usage: download_and_extract URL DIR"
|
||||||
@ -100,6 +101,15 @@ patch_am_sdk() {
|
|||||||
echo "Finished preparing Apollo3 files"
|
echo "Finished preparing Apollo3 files"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patch_kissfft() {
|
||||||
|
sed -i -E "s@#ifdef FIXED_POINT@// Patched automatically by download_dependencies.sh so default is 16 bit.\n#ifndef FIXED_POINT\n#define FIXED_POINT (16)\n#endif\n// End patch.\n\n#ifdef FIXED_POINT@g" tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.h
|
||||||
|
sed -i -E "s@#define KISS_FFT_MALLOC malloc@#define KISS_FFT_MALLOC(X) (void*)(0) /* Patched. */@g" tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.h
|
||||||
|
sed -i -E "s@#define KISS_FFT_FREE free@#define KISS_FFT_FREE(X) /* Patched. */@g" tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.h
|
||||||
|
sed -i -E "s@(fprintf.*\);)@/* \1 */@g" tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/tools/kiss_fftr.c
|
||||||
|
sed -i -E "s@(exit.*\);)@return; /* \1 */@g" tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/tools/kiss_fftr.c
|
||||||
|
echo "Finished patching kissfft"
|
||||||
|
}
|
||||||
|
|
||||||
download_and_extract "${GEMMLOWP_URL}" "${DOWNLOADS_DIR}/gemmlowp"
|
download_and_extract "${GEMMLOWP_URL}" "${DOWNLOADS_DIR}/gemmlowp"
|
||||||
download_and_extract "${FLATBUFFERS_URL}" "${DOWNLOADS_DIR}/flatbuffers"
|
download_and_extract "${FLATBUFFERS_URL}" "${DOWNLOADS_DIR}/flatbuffers"
|
||||||
download_and_extract "${CMSIS_URL}" "${DOWNLOADS_DIR}/cmsis"
|
download_and_extract "${CMSIS_URL}" "${DOWNLOADS_DIR}/cmsis"
|
||||||
@ -111,5 +121,7 @@ patch_am_sdk "${DOWNLOADS_DIR}/AmbiqSuite-Rel2.0.0"
|
|||||||
download_and_extract "${AP3_URL}" "${DOWNLOADS_DIR}/apollo3_ext"
|
download_and_extract "${AP3_URL}" "${DOWNLOADS_DIR}/apollo3_ext"
|
||||||
download_and_extract "${CUST_CMSIS_URL}" "${DOWNLOADS_DIR}/CMSIS_ext"
|
download_and_extract "${CUST_CMSIS_URL}" "${DOWNLOADS_DIR}/CMSIS_ext"
|
||||||
download_and_extract "${GCC_EMBEDDED_URL}" "${DOWNLOADS_DIR}/gcc_embedded"
|
download_and_extract "${GCC_EMBEDDED_URL}" "${DOWNLOADS_DIR}/gcc_embedded"
|
||||||
|
download_and_extract "${KISSFFT_URL}" "${DOWNLOADS_DIR}/kissfft"
|
||||||
|
patch_kissfft "${DOWNLOADS_DIR}/kissfft"
|
||||||
|
|
||||||
echo "download_dependencies.sh completed successfully." >&2
|
echo "download_dependencies.sh completed successfully." >&2
|
||||||
|
Loading…
Reference in New Issue
Block a user