blob: 440eabef142185f177858b6b27832358ec98e745 [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}")
75
76 download_file_from_modelzoo(${ZOO_MODEL_SUBPATH} ${DEFAULT_MODEL_PATH})
77
78 if (ETHOS_U55_ENABLED)
79 message(STATUS
80 "Ethos-U55 is enabled, but the model downloaded is not optimized by vela. "
81 "To use Ethos-U55 acceleration, optimise the downloaded model and pass it "
82 "as ${use_case}_MODEL_TFLITE_PATH to the CMake configuration.")
83 endif()
84
85 # If the target platform is native
86 if (${TARGET_PLATFORM} STREQUAL native)
87
88 # Download test vectors
89 set(ZOO_TEST_IFM_SUBPATH "${ZOO_COMMON_SUBPATH}/testing_input/input/0.npy")
90 set(ZOO_TEST_OFM_SUBPATH "${ZOO_COMMON_SUBPATH}/testing_output/output/0.npy")
91
92 set(${use_case}_TEST_IFM ${MODEL_RESOURCES_DIR}/ifm0.npy CACHE FILEPATH
93 "Input test vector for ${use_case}")
94 set(${use_case}_TEST_OFM ${MODEL_RESOURCES_DIR}/ofm0.npy CACHE FILEPATH
95 "Input test vector for ${use_case}")
96
97 download_file_from_modelzoo(${ZOO_TEST_IFM_SUBPATH} ${${use_case}_TEST_IFM})
98 download_file_from_modelzoo(${ZOO_TEST_OFM_SUBPATH} ${${use_case}_TEST_OFM})
99
100 set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src)
101 set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include)
102 file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR})
103
104 # Generate test data files to be included in x86 tests
105 generate_test_data_code(
106 INPUT_DIR "${DOWNLOAD_DEP_DIR}/${use_case}"
107 DESTINATION_SRC ${TEST_SRC_GEN_DIR}
108 DESTINATION_HDR ${TEST_INC_GEN_DIR}
109 USECASE "${use_case}")
110 endif()
111
112else()
113 set(DEFAULT_MODEL_PATH "N/A")
114endif()
115
116USER_OPTION(${use_case}_MODEL_TFLITE_PATH "NN models file to be used in the evaluation application. Model files must be in tflite format."
117 ${DEFAULT_MODEL_PATH}
118 FILEPATH
119 )
120
121# Generate model file
122generate_tflite_code(
123 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH}
124 DESTINATION ${SRC_GEN_DIR}
125 )