alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 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 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 18 | USER_OPTION(${use_case}_FILE_PATH "Directory with WAV files, or path to a single WAV file, to use in the evaluation application." |
| 19 | ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/samples/ |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 20 | PATH_OR_FILE) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 21 | |
| 22 | USER_OPTION(${use_case}_AUDIO_RATE "Specify the target sampling rate. Default is 16000." |
| 23 | 16000 |
| 24 | STRING) |
| 25 | |
| 26 | USER_OPTION(${use_case}_AUDIO_MONO "Specify if the audio needs to be converted to mono. Default is ON." |
| 27 | ON |
| 28 | BOOL) |
| 29 | |
| 30 | USER_OPTION(${use_case}_AUDIO_OFFSET "Specify the offset to start reading after this time (in seconds). Default is 0." |
| 31 | 0 |
| 32 | STRING) |
| 33 | |
| 34 | USER_OPTION(${use_case}_AUDIO_DURATION "Specify the audio duration to load (in seconds). If set to 0 the entire audio will be processed." |
| 35 | 0 |
| 36 | STRING) |
| 37 | |
| 38 | USER_OPTION(${use_case}_AUDIO_RES_TYPE "Specify re-sampling algorithm to use. By default is 'kaiser_best'." |
| 39 | kaiser_best |
| 40 | STRING) |
| 41 | |
| 42 | USER_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." |
| 43 | 16000 |
| 44 | STRING) |
| 45 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 46 | # Generate kws labels file: |
| 47 | USER_OPTION(${use_case}_LABELS_TXT_FILE_KWS "Labels' txt file for the chosen model." |
Kshitij Sisodia | 76a1580 | 2021-12-24 11:05:11 +0000 | [diff] [blame] | 48 | ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/micronet_kws_labels.txt |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 49 | FILEPATH) |
| 50 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 51 | # Generate asr labels file: |
| 52 | USER_OPTION(${use_case}_LABELS_TXT_FILE_ASR "Labels' txt file for the chosen model." |
| 53 | ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/labels_wav2letter.txt |
| 54 | FILEPATH) |
| 55 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 56 | |
| 57 | USER_OPTION(${use_case}_ACTIVATION_BUF_SZ "Activation buffer size for the chosen model" |
Kshitij Sisodia | 661959c | 2021-11-24 10:39:52 +0000 | [diff] [blame] | 58 | 0x00200000 |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 59 | STRING) |
| 60 | |
| 61 | USER_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." |
| 62 | 0.9 |
| 63 | STRING) |
| 64 | |
| 65 | USER_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." |
| 66 | 0.5 |
| 67 | STRING) |
| 68 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 69 | if (ETHOS_U_NPU_ENABLED) |
Kshitij Sisodia | 76a1580 | 2021-12-24 11:05:11 +0000 | [diff] [blame] | 70 | set(DEFAULT_MODEL_PATH_KWS ${DEFAULT_MODEL_DIR}/kws_micronet_m_vela_${ETHOS_U_NPU_CONFIG_ID}.tflite) |
Kshitij Sisodia | 3be2623 | 2021-10-29 12:29:06 +0100 | [diff] [blame] | 71 | set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_pruned_int8_vela_${ETHOS_U_NPU_CONFIG_ID}.tflite) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 72 | else() |
Kshitij Sisodia | 76a1580 | 2021-12-24 11:05:11 +0000 | [diff] [blame] | 73 | set(DEFAULT_MODEL_PATH_KWS ${DEFAULT_MODEL_DIR}/kws_micronet_m.tflite) |
Kshitij Sisodia | e12ac83 | 2021-05-20 11:18:53 +0100 | [diff] [blame] | 74 | set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_pruned_int8.tflite) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 75 | endif() |
| 76 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 77 | USER_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." |
| 78 | ${DEFAULT_MODEL_PATH_KWS} |
| 79 | FILEPATH |
| 80 | ) |
| 81 | |
| 82 | USER_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." |
| 83 | ${DEFAULT_MODEL_PATH_ASR} |
| 84 | FILEPATH |
| 85 | ) |
| 86 | |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 87 | # If the target platform is native |
| 88 | if (${TARGET_PLATFORM} STREQUAL native) |
| 89 | set(DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR}/asr ${DEFAULT_TEST_DATA_DIR}/kws) |
| 90 | endif() |
| 91 | |
| 92 | set(EXTRA_MODEL_CODE_KWS |
| 93 | "/* Model parameters for ${use_case} */" |
| 94 | "extern const uint32_t g_NumMfcc = 10" |
| 95 | "extern const uint32_t g_NumAudioWins = 49" |
| 96 | "extern const int g_FrameLength = 640" |
| 97 | "extern const int g_FrameStride = 320" |
| 98 | "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_KWS}" |
| 99 | ) |
| 100 | |
| 101 | set(EXTRA_MODEL_CODE_ASR |
| 102 | "/* Model parameters for ${use_case} */" |
| 103 | "extern const int g_FrameLength = 512" |
| 104 | "extern const int g_FrameStride = 160" |
| 105 | "extern const int g_ctxLen = 98" |
| 106 | "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_ASR}" |
| 107 | ) |
| 108 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 109 | # Generate model file for KWS |
| 110 | generate_tflite_code( |
| 111 | MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_KWS} |
| 112 | DESTINATION ${SRC_GEN_DIR} |
| 113 | EXPRESSIONS ${EXTRA_MODEL_CODE_KWS} |
| 114 | NAMESPACE "arm" "app" "kws" |
| 115 | ) |
| 116 | |
| 117 | # and for ASR |
| 118 | generate_tflite_code( |
| 119 | MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_ASR} |
| 120 | DESTINATION ${SRC_GEN_DIR} |
| 121 | EXPRESSIONS ${EXTRA_MODEL_CODE_ASR} |
| 122 | NAMESPACE "arm" "app" "asr" |
| 123 | ) |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 124 | |
| 125 | generate_labels_code( |
| 126 | INPUT "${${use_case}_LABELS_TXT_FILE_ASR}" |
| 127 | DESTINATION_SRC ${SRC_GEN_DIR} |
| 128 | DESTINATION_HDR ${INC_GEN_DIR} |
| 129 | OUTPUT_FILENAME "Labels_wav2letter" |
| 130 | NAMESPACE "arm" "app" "asr" |
| 131 | ) |
| 132 | |
| 133 | generate_labels_code( |
| 134 | INPUT "${${use_case}_LABELS_TXT_FILE_KWS}" |
| 135 | DESTINATION_SRC ${SRC_GEN_DIR} |
| 136 | DESTINATION_HDR ${INC_GEN_DIR} |
Kshitij Sisodia | 76a1580 | 2021-12-24 11:05:11 +0000 | [diff] [blame] | 137 | OUTPUT_FILENAME "Labels_micronetkws" |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 138 | NAMESPACE "arm" "app" "kws" |
| 139 | ) |
| 140 | |
| 141 | # Generate audio .cc files: |
| 142 | generate_audio_code(${${use_case}_FILE_PATH} ${SRC_GEN_DIR} ${INC_GEN_DIR} |
| 143 | ${${use_case}_AUDIO_RATE} |
| 144 | ${${use_case}_AUDIO_MONO} |
| 145 | ${${use_case}_AUDIO_OFFSET} |
| 146 | ${${use_case}_AUDIO_DURATION} |
| 147 | ${${use_case}_AUDIO_RES_TYPE} |
| 148 | ${${use_case}_AUDIO_MIN_SAMPLES}) |