blob: 384c58e5c5cc46c2e8ee453c2b3e0bac382c1071 [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 # Set the default type if path is not a dir or file path (or undefined)
23 if (NOT ${PATH_TYPE} STREQUAL PATH AND NOT ${PATH_TYPE} STREQUAL FILEPATH)
24 message(FATAL_ERROR "Invalid ${use_case}_FILE_PATH. It should be a dir or file path.")
25 endif()
26else()
27 # Default is a directory path
28 set(PATH_TYPE PATH)
29endif()
30
31message(STATUS "${use_case}_FILE_PATH is of type: ${PATH_TYPE}")
32
33USER_OPTION(${use_case}_FILE_PATH "Directory with custom image files to use, or path to a single image, in the evaluation application"
34 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/samples/
35 ${PATH_TYPE})
36
37USER_OPTION(${use_case}_IMAGE_SIZE "Square image size in pixels. Images will be resized to this size."
38 224
39 STRING)
40
41USER_OPTION(${use_case}_LABELS_TXT_FILE "Labels' txt file for the chosen model"
42 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/labels_mobilenet_v2_1.0_224.txt
43 FILEPATH)
44
45# Generate input files
46generate_images_code("${${use_case}_FILE_PATH}"
47 ${SRC_GEN_DIR}
48 ${INC_GEN_DIR}
49 "${${use_case}_IMAGE_SIZE}")
50
51# Generate labels file
52set(${use_case}_LABELS_CPP_FILE Labels)
53generate_labels_code(
54 INPUT "${${use_case}_LABELS_TXT_FILE}"
55 DESTINATION_SRC ${SRC_GEN_DIR}
56 DESTINATION_HDR ${INC_GEN_DIR}
57 OUTPUT_FILENAME "${${use_case}_LABELS_CPP_FILE}"
58)
59
60USER_OPTION(${use_case}_ACTIVATION_BUF_SZ "Activation buffer size for the chosen model"
61 0x00200000
62 STRING)
63
64# If there is no tflite file pointed to
65if (NOT DEFINED ${use_case}_MODEL_TFLITE_PATH)
66
67 set(MODEL_RESOURCES_DIR ${DOWNLOAD_DEP_DIR}/${use_case})
68 file(MAKE_DIRECTORY ${MODEL_RESOURCES_DIR})
69 set(MODEL_FILENAME mobilenet_v2_1.0_224_quantized_1_default_1.tflite)
70 set(DEFAULT_MODEL_PATH ${MODEL_RESOURCES_DIR}/${MODEL_FILENAME})
71
72 # Download the default model
73 set(ZOO_COMMON_SUBPATH "models/image_classification/mobilenet_v2_1.0_224/tflite_uint8")
74 set(ZOO_MODEL_SUBPATH "${ZOO_COMMON_SUBPATH}/${MODEL_FILENAME}")
Isabella Gottardib88705d2021-04-21 13:09:51 +010075 set(ZOO_MODEL_VERSION "68b5fbc77ed28e67b2efc915997ea4477c1d9d5b")
alexander3c798932021-03-26 21:42:19 +000076
Isabella Gottardib88705d2021-04-21 13:09:51 +010077 download_file_from_modelzoo(${ZOO_MODEL_VERSION} ${ZOO_MODEL_SUBPATH} ${DEFAULT_MODEL_PATH})
alexander3c798932021-03-26 21:42:19 +000078
79 if (ETHOS_U55_ENABLED)
80 message(STATUS
81 "Ethos-U55 is enabled, but the model downloaded is not optimized by vela. "
82 "To use Ethos-U55 acceleration, optimise the downloaded model and pass it "
83 "as ${use_case}_MODEL_TFLITE_PATH to the CMake configuration.")
84 endif()
85
86 # If the target platform is native
87 if (${TARGET_PLATFORM} STREQUAL native)
88
89 # Download test vectors
90 set(ZOO_TEST_IFM_SUBPATH "${ZOO_COMMON_SUBPATH}/testing_input/input/0.npy")
91 set(ZOO_TEST_OFM_SUBPATH "${ZOO_COMMON_SUBPATH}/testing_output/output/0.npy")
92
93 set(${use_case}_TEST_IFM ${MODEL_RESOURCES_DIR}/ifm0.npy CACHE FILEPATH
94 "Input test vector for ${use_case}")
95 set(${use_case}_TEST_OFM ${MODEL_RESOURCES_DIR}/ofm0.npy CACHE FILEPATH
96 "Input test vector for ${use_case}")
97
Isabella Gottardib88705d2021-04-21 13:09:51 +010098 download_file_from_modelzoo(${ZOO_MODEL_VERSION} ${ZOO_TEST_IFM_SUBPATH} ${${use_case}_TEST_IFM})
99 download_file_from_modelzoo(${ZOO_MODEL_VERSION} ${ZOO_TEST_OFM_SUBPATH} ${${use_case}_TEST_OFM})
alexander3c798932021-03-26 21:42:19 +0000100
101 set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src)
102 set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include)
103 file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR})
104
105 # Generate test data files to be included in x86 tests
106 generate_test_data_code(
107 INPUT_DIR "${DOWNLOAD_DEP_DIR}/${use_case}"
108 DESTINATION_SRC ${TEST_SRC_GEN_DIR}
109 DESTINATION_HDR ${TEST_INC_GEN_DIR}
110 USECASE "${use_case}")
111 endif()
112
113else()
114 set(DEFAULT_MODEL_PATH "N/A")
115endif()
116
117USER_OPTION(${use_case}_MODEL_TFLITE_PATH "NN models file to be used in the evaluation application. Model files must be in tflite format."
118 ${DEFAULT_MODEL_PATH}
119 FILEPATH
120 )
121
122# Generate model file
123generate_tflite_code(
124 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH}
125 DESTINATION ${SRC_GEN_DIR}
126 )