blob: d8ac89771861a9daefad94aed6f8a5d9a123147b [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#----------------------------------------------------------------------------
17
18# If the path to a directory or source file has been defined,
19# get the type here (FILEPATH or PATH):
Isabella Gottardi2181d0a2021-04-07 09:27:38 +010020#if (DEFINED ${use_case}_FILE_PATH)
21# get_path_type(${${use_case}_FILE_PATH} PATH_TYPE)
22#
23# # Set the default type if path is not a dir or file path (or undefined)
24# if (NOT ${PATH_TYPE} STREQUAL PATH AND NOT ${PATH_TYPE} STREQUAL FILEPATH)
25# message(FATAL_ERROR "Invalid ${use_case}_FILE_PATH. It should be a dir or file path.")
26# endif()
27#else()
28# # Default is a directory path
29# set(PATH_TYPE PATH)
30#endif()
alexander3c798932021-03-26 21:42:19 +000031
32USER_OPTION(${use_case}_FILE_PATH "Directory with WAV files, or path to a single WAV file, to use in the evaluation application."
33 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/samples/
Isabella Gottardi2181d0a2021-04-07 09:27:38 +010034 PATH_OR_FILE)
alexander3c798932021-03-26 21:42:19 +000035
36USER_OPTION(${use_case}_AUDIO_RATE "Specify the target sampling rate. Default is 16000."
37 16000
38 STRING)
39
40USER_OPTION(${use_case}_AUDIO_MONO "Specify if the audio needs to be converted to mono. Default is ON."
41 ON
42 BOOL)
43
44USER_OPTION(${use_case}_AUDIO_OFFSET "Specify the offset to start reading after this time (in seconds). Default is 0."
45 0
46 STRING)
47
48USER_OPTION(${use_case}_AUDIO_DURATION "Specify the audio duration to load (in seconds). If set to 0 the entire audio will be processed."
49 0
50 STRING)
51
52USER_OPTION(${use_case}_AUDIO_RES_TYPE "Specify re-sampling algorithm to use. By default is 'kaiser_best'."
53 kaiser_best
54 STRING)
55
56USER_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."
57 16000
58 STRING)
59
alexander3c798932021-03-26 21:42:19 +000060# Generate kws labels file:
61USER_OPTION(${use_case}_LABELS_TXT_FILE_KWS "Labels' txt file for the chosen model."
62 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/ds_cnn_labels.txt
63 FILEPATH)
64
alexander3c798932021-03-26 21:42:19 +000065# Generate asr labels file:
66USER_OPTION(${use_case}_LABELS_TXT_FILE_ASR "Labels' txt file for the chosen model."
67 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/labels_wav2letter.txt
68 FILEPATH)
69
alexander3c798932021-03-26 21:42:19 +000070
71USER_OPTION(${use_case}_ACTIVATION_BUF_SZ "Activation buffer size for the chosen model"
72 0x00200000
73 STRING)
74
75USER_OPTION(${use_case}_MODEL_SCORE_THRESHOLD_KWS "Specify the score threshold [0.0, 1.0) that must be applied to the KWS results for a label to be deemed valid."
76 0.9
77 STRING)
78
79USER_OPTION(${use_case}_MODEL_SCORE_THRESHOLD_ASR "Specify the score threshold [0.0, 1.0) that must be applied to the ASR results for a label to be deemed valid."
80 0.5
81 STRING)
82
Isabella Gottardi2181d0a2021-04-07 09:27:38 +010083if (ETHOS_U55_ENABLED)
84 set(DEFAULT_MODEL_PATH_KWS ${DEFAULT_MODEL_DIR}/ds_cnn_clustered_int8_vela.tflite)
85 set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_int8_vela.tflite)
alexander3c798932021-03-26 21:42:19 +000086else()
Isabella Gottardi2181d0a2021-04-07 09:27:38 +010087 set(DEFAULT_MODEL_PATH_KWS ${DEFAULT_MODEL_DIR}/ds_cnn_clustered_int8.tflite)
88 set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_int8.tflite)
alexander3c798932021-03-26 21:42:19 +000089endif()
90
alexander3c798932021-03-26 21:42:19 +000091USER_OPTION(${use_case}_MODEL_TFLITE_PATH_KWS "NN models file to be used for KWS in the evaluation application. Model files must be in tflite format."
92 ${DEFAULT_MODEL_PATH_KWS}
93 FILEPATH
94 )
95
96USER_OPTION(${use_case}_MODEL_TFLITE_PATH_ASR "NN models file to be used for ASR in the evaluation application. Model files must be in tflite format."
97 ${DEFAULT_MODEL_PATH_ASR}
98 FILEPATH
99 )
100
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100101# If the target platform is native
102if (${TARGET_PLATFORM} STREQUAL native)
103 set(DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR}/asr ${DEFAULT_TEST_DATA_DIR}/kws)
104endif()
105
106set(EXTRA_MODEL_CODE_KWS
107 "/* Model parameters for ${use_case} */"
108 "extern const uint32_t g_NumMfcc = 10"
109 "extern const uint32_t g_NumAudioWins = 49"
110 "extern const int g_FrameLength = 640"
111 "extern const int g_FrameStride = 320"
112 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_KWS}"
113 )
114
115set(EXTRA_MODEL_CODE_ASR
116 "/* Model parameters for ${use_case} */"
117 "extern const int g_FrameLength = 512"
118 "extern const int g_FrameStride = 160"
119 "extern const int g_ctxLen = 98"
120 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_ASR}"
121 )
122
alexander3c798932021-03-26 21:42:19 +0000123# Generate model file for KWS
124generate_tflite_code(
125 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_KWS}
126 DESTINATION ${SRC_GEN_DIR}
127 EXPRESSIONS ${EXTRA_MODEL_CODE_KWS}
128 NAMESPACE "arm" "app" "kws"
129)
130
131# and for ASR
132generate_tflite_code(
133 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_ASR}
134 DESTINATION ${SRC_GEN_DIR}
135 EXPRESSIONS ${EXTRA_MODEL_CODE_ASR}
136 NAMESPACE "arm" "app" "asr"
137)
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100138
139generate_labels_code(
140 INPUT "${${use_case}_LABELS_TXT_FILE_ASR}"
141 DESTINATION_SRC ${SRC_GEN_DIR}
142 DESTINATION_HDR ${INC_GEN_DIR}
143 OUTPUT_FILENAME "Labels_wav2letter"
144 NAMESPACE "arm" "app" "asr"
145)
146
147generate_labels_code(
148 INPUT "${${use_case}_LABELS_TXT_FILE_KWS}"
149 DESTINATION_SRC ${SRC_GEN_DIR}
150 DESTINATION_HDR ${INC_GEN_DIR}
151 OUTPUT_FILENAME "Labels_dscnn"
152 NAMESPACE "arm" "app" "kws"
153)
154
155# Generate audio .cc files:
156generate_audio_code(${${use_case}_FILE_PATH} ${SRC_GEN_DIR} ${INC_GEN_DIR}
157 ${${use_case}_AUDIO_RATE}
158 ${${use_case}_AUDIO_MONO}
159 ${${use_case}_AUDIO_OFFSET}
160 ${${use_case}_AUDIO_DURATION}
161 ${${use_case}_AUDIO_RES_TYPE}
162 ${${use_case}_AUDIO_MIN_SAMPLES})