blob: 7bac23091a3c208643ac28b4de4bdcfd5ea409aa [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
2# Copyright (c) 2021 Arm Limited. All rights reserved.
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#----------------------------------------------------------------------------
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010017# Append the API to use for this use case
18list(APPEND ${use_case}_API_LIST "kws")
alexander3c798932021-03-26 21:42:19 +000019
Eanna O Cathain4c0ac912022-09-22 15:18:34 +010020set_input_file_path_user_option(".wav" ${use_case})
alexander3c798932021-03-26 21:42:19 +000021
22USER_OPTION(${use_case}_LABELS_TXT_FILE "Labels' txt file for the chosen model."
Kshitij Sisodia76a15802021-12-24 11:05:11 +000023 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/micronet_kws_labels.txt
alexander3c798932021-03-26 21:42:19 +000024 FILEPATH)
25
26USER_OPTION(${use_case}_AUDIO_RATE "Specify the target sampling rate. Default is 16000."
27 16000
28 STRING)
29
30USER_OPTION(${use_case}_AUDIO_MONO "Specify if the audio needs to be converted to mono. Default is ON."
31 ON
32 BOOL)
33
34USER_OPTION(${use_case}_AUDIO_OFFSET "Specify the offset to start reading after this time (in seconds). Default is 0."
35 0
36 STRING)
37
38USER_OPTION(${use_case}_AUDIO_DURATION "Specify the audio duration to load (in seconds). If set to 0 the entire audio will be processed."
39 0
40 STRING)
41
42USER_OPTION(${use_case}_AUDIO_RES_TYPE "Specify re-sampling algorithm to use. By default is 'kaiser_best'."
43 kaiser_best
44 STRING)
45
46USER_OPTION(${use_case}_AUDIO_MIN_SAMPLES "Specify the minimum number of samples to use. By default is 16000, if the audio is shorter will be automatically padded."
47 16000
48 STRING)
49
50USER_OPTION(${use_case}_MODEL_SCORE_THRESHOLD "Specify the score threshold [0.0, 1.0) that must be applied to the inference results for a label to be deemed valid."
Kshitij Sisodia76a15802021-12-24 11:05:11 +000051 0.7
alexander3c798932021-03-26 21:42:19 +000052 STRING)
53
54# Generate input files
55generate_audio_code(${${use_case}_FILE_PATH} ${SRC_GEN_DIR} ${INC_GEN_DIR}
56 ${${use_case}_AUDIO_RATE}
57 ${${use_case}_AUDIO_MONO}
58 ${${use_case}_AUDIO_OFFSET}
59 ${${use_case}_AUDIO_DURATION}
60 ${${use_case}_AUDIO_RES_TYPE}
61 ${${use_case}_AUDIO_MIN_SAMPLES})
62
63# Generate labels file
64set(${use_case}_LABELS_CPP_FILE Labels)
65generate_labels_code(
66 INPUT "${${use_case}_LABELS_TXT_FILE}"
67 DESTINATION_SRC ${SRC_GEN_DIR}
68 DESTINATION_HDR ${INC_GEN_DIR}
69 OUTPUT_FILENAME "${${use_case}_LABELS_CPP_FILE}"
70)
71
72USER_OPTION(${use_case}_ACTIVATION_BUF_SZ "Activation buffer size for the chosen model"
73 0x00100000
74 STRING)
75
Kshitij Sisodia76a15802021-12-24 11:05:11 +000076
Cisco Cervelleraf085fa52021-08-02 09:32:07 +010077if (ETHOS_U_NPU_ENABLED)
Kshitij Sisodia76a15802021-12-24 11:05:11 +000078 set(DEFAULT_MODEL_PATH ${DEFAULT_MODEL_DIR}/kws_micronet_m_vela_${ETHOS_U_NPU_CONFIG_ID}.tflite)
alexander3c798932021-03-26 21:42:19 +000079else()
Kshitij Sisodia76a15802021-12-24 11:05:11 +000080 set(DEFAULT_MODEL_PATH ${DEFAULT_MODEL_DIR}/kws_micronet_m.tflite)
alexander3c798932021-03-26 21:42:19 +000081endif()
82
83set(EXTRA_MODEL_CODE
84 "/* Model parameters for ${use_case} */"
85 "extern const int g_FrameLength = 640"
86 "extern const int g_FrameStride = 320"
87 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD}"
88 )
89
90USER_OPTION(${use_case}_MODEL_TFLITE_PATH "NN models file to be used in the evaluation application. Model files must be in tflite format."
91 ${DEFAULT_MODEL_PATH}
92 FILEPATH)
93
94# Generate model file
95generate_tflite_code(
96 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH}
97 DESTINATION ${SRC_GEN_DIR}
98 EXPRESSIONS ${EXTRA_MODEL_CODE}
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010099 NAMESPACE "arm" "app" "kws"
alexander3c798932021-03-26 21:42:19 +0000100)