blob: b5ac09eece26e3d8810b753f36aafb71bb6ce844 [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):
20if (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()
27else()
28 # Default is a directory path
29 set(PATH_TYPE PATH)
30endif()
31
32message(STATUS "${use_case}_FILE_PATH is of type: ${PATH_TYPE}")
33USER_OPTION(${use_case}_FILE_PATH "Directory with custom WAV input files, or path to a single WAV file, to use in the evaluation application."
34 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/samples/
35 ${PATH_TYPE})
36
37USER_OPTION(${use_case}_LABELS_TXT_FILE "Labels' txt file for the chosen model."
38 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/ds_cnn_labels.txt
39 FILEPATH)
40
41USER_OPTION(${use_case}_AUDIO_RATE "Specify the target sampling rate. Default is 16000."
42 16000
43 STRING)
44
45USER_OPTION(${use_case}_AUDIO_MONO "Specify if the audio needs to be converted to mono. Default is ON."
46 ON
47 BOOL)
48
49USER_OPTION(${use_case}_AUDIO_OFFSET "Specify the offset to start reading after this time (in seconds). Default is 0."
50 0
51 STRING)
52
53USER_OPTION(${use_case}_AUDIO_DURATION "Specify the audio duration to load (in seconds). If set to 0 the entire audio will be processed."
54 0
55 STRING)
56
57USER_OPTION(${use_case}_AUDIO_RES_TYPE "Specify re-sampling algorithm to use. By default is 'kaiser_best'."
58 kaiser_best
59 STRING)
60
61USER_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."
62 16000
63 STRING)
64
65USER_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."
66 0.9
67 STRING)
68
69# Generate input files
70generate_audio_code(${${use_case}_FILE_PATH} ${SRC_GEN_DIR} ${INC_GEN_DIR}
71 ${${use_case}_AUDIO_RATE}
72 ${${use_case}_AUDIO_MONO}
73 ${${use_case}_AUDIO_OFFSET}
74 ${${use_case}_AUDIO_DURATION}
75 ${${use_case}_AUDIO_RES_TYPE}
76 ${${use_case}_AUDIO_MIN_SAMPLES})
77
78# Generate labels file
79set(${use_case}_LABELS_CPP_FILE Labels)
80generate_labels_code(
81 INPUT "${${use_case}_LABELS_TXT_FILE}"
82 DESTINATION_SRC ${SRC_GEN_DIR}
83 DESTINATION_HDR ${INC_GEN_DIR}
84 OUTPUT_FILENAME "${${use_case}_LABELS_CPP_FILE}"
85)
86
87USER_OPTION(${use_case}_ACTIVATION_BUF_SZ "Activation buffer size for the chosen model"
88 0x00100000
89 STRING)
90
91# If there is no tflite file pointed to
92if (NOT DEFINED ${use_case}_MODEL_TFLITE_PATH)
93
94 set(MODEL_FILENAME ds_cnn_clustered_int8.tflite)
95 set(MODEL_RESOURCES_DIR ${DOWNLOAD_DEP_DIR}/${use_case})
96 file(MAKE_DIRECTORY ${MODEL_RESOURCES_DIR})
97 set(DEFAULT_MODEL_PATH ${MODEL_RESOURCES_DIR}/${MODEL_FILENAME})
98
99 # Download the default model
100 set(ZOO_COMMON_SUBPATH "models/keyword_spotting/ds_cnn_large/tflite_clustered_int8")
101 set(ZOO_MODEL_SUBPATH "${ZOO_COMMON_SUBPATH}/${MODEL_FILENAME}")
102
103 download_file_from_modelzoo(${ZOO_MODEL_SUBPATH} ${DEFAULT_MODEL_PATH})
104
105 if (ETHOS_U55_ENABLED)
106 message(STATUS
107 "Ethos-U55 is enabled, but the model downloaded is not optimized by vela. "
108 "To use Ethos-U55 acceleration, optimise the downloaded model and pass it "
109 "as ${use_case}_MODEL_TFLITE_PATH to the CMake configuration.")
110 endif()
111
112 # If the target platform is native
113 if (${TARGET_PLATFORM} STREQUAL native)
114
115 # Download test vectors
116 set(ZOO_TEST_IFM_SUBPATH "${ZOO_COMMON_SUBPATH}/testing_input/input_2/0.npy")
117 set(ZOO_TEST_OFM_SUBPATH "${ZOO_COMMON_SUBPATH}/testing_output/Identity/0.npy")
118
119 set(${use_case}_TEST_IFM ${MODEL_RESOURCES_DIR}/ifm0.npy CACHE FILEPATH
120 "Input test vector for ${use_case}")
121 set(${use_case}_TEST_OFM ${MODEL_RESOURCES_DIR}/ofm0.npy CACHE FILEPATH
122 "Input test vector for ${use_case}")
123
124 download_file_from_modelzoo(${ZOO_TEST_IFM_SUBPATH} ${${use_case}_TEST_IFM})
125 download_file_from_modelzoo(${ZOO_TEST_OFM_SUBPATH} ${${use_case}_TEST_OFM})
126
127 set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src)
128 set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include)
129 file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR})
130
131 # Generate test data files to be included in x86 tests
132 generate_test_data_code(
133 INPUT_DIR "${DOWNLOAD_DEP_DIR}/${use_case}"
134 DESTINATION_SRC ${TEST_SRC_GEN_DIR}
135 DESTINATION_HDR ${TEST_INC_GEN_DIR}
136 USECASE "${use_case}")
137 endif()
138
139else()
140 set(DEFAULT_MODEL_PATH "N/A")
141endif()
142
143set(EXTRA_MODEL_CODE
144 "/* Model parameters for ${use_case} */"
145 "extern const int g_FrameLength = 640"
146 "extern const int g_FrameStride = 320"
147 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD}"
148 )
149
150USER_OPTION(${use_case}_MODEL_TFLITE_PATH "NN models file to be used in the evaluation application. Model files must be in tflite format."
151 ${DEFAULT_MODEL_PATH}
152 FILEPATH)
153
154# Generate model file
155generate_tflite_code(
156 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH}
157 DESTINATION ${SRC_GEN_DIR}
158 EXPRESSIONS ${EXTRA_MODEL_CODE}
159)