Skip to content

Commit 1c40cbd

Browse files
test_yolo12.sh WIP
1 parent 853a16e commit 1c40cbd

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

.ci/scripts/test_yolo12.sh

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -exu
9+
# shellcheck source=/dev/null
10+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
11+
12+
while [[ $# -gt 0 ]]; do
13+
case "$1" in
14+
-model)
15+
MODEL_NAME="$2" # stories110M
16+
shift 2
17+
;;
18+
-mode)
19+
MODE="$2" # portable or xnnpack+custom or xnnpack+custom+qe
20+
shift 2
21+
;;
22+
-pt2e_quantize)
23+
PT2E_QUANTIZE="$2"
24+
shift 2
25+
;;
26+
-upload)
27+
UPLOAD_DIR="$2"
28+
shift 2
29+
;;
30+
-video_path)
31+
VIDEO_PATH="$2" # portable or xnnpack+custom or xnnpack+custom+qe
32+
shift 2
33+
;;
34+
*)
35+
echo "Unknown option: $1"
36+
usage
37+
;;
38+
esac
39+
done
40+
41+
# Default mode to xnnpack+custom if not set
42+
MODE=${MODE:-"openvino"}
43+
44+
# Default UPLOAD_DIR to empty string if not set
45+
UPLOAD_DIR="${UPLOAD_DIR:-}"
46+
47+
# Default PT2E_QUANTIZE to empty string if not set
48+
PT2E_QUANTIZE="${PT2E_QUANTIZE:-}"
49+
50+
# Default CMake Build Type to release mode
51+
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release}
52+
53+
if [[ $# -lt 5 ]]; then # Assuming 4 mandatory args
54+
echo "Expecting atleast 5 positional arguments"
55+
echo "Usage: [...]"
56+
fi
57+
if [[ -z "${MODEL_NAME:-}" ]]; then
58+
echo "Missing model name, exiting..."
59+
exit 1
60+
fi
61+
62+
63+
if [[ -z "${MODE:-}" ]]; then
64+
echo "Missing mode, choose openvino or xnnpack, exiting..."
65+
exit 1
66+
fi
67+
68+
TARGET_LIBS=""
69+
70+
if [[ "${MODE}" =~ .*openvino.* ]]; then
71+
OPENVINO=ON
72+
TARGET_LIBS="$TARGET_LIBS openvino_backend "
73+
else
74+
OPENVINO=OFF
75+
fi
76+
77+
if [[ "${MODE}" =~ .*xnnpack.* ]]; then
78+
XNNPACK=ON
79+
TARGET_LIBS="$TARGET_LIBS xnnpack_backend "
80+
else
81+
XNNPACK=OFF
82+
fi
83+
84+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
85+
PYTHON_EXECUTABLE=python3
86+
fi
87+
88+
which "${PYTHON_EXECUTABLE}"
89+
90+
cmake_install_executorch_libraries() {
91+
echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a"
92+
rm -rf cmake-out
93+
mkdir cmake-out
94+
95+
retry cmake \
96+
-DCMAKE_INSTALL_PREFIX=cmake-out \
97+
-DEXECUTORCH_BUILD_OPENVINO="$OPENVINO" \
98+
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
99+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
100+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
101+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
102+
-DEXECUTORCH_ENABLE_LOGGING=ON \
103+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
104+
-DEXECUTORCH_BUILD_PYBIND=ON \
105+
-Bcmake-out
106+
cmake --build cmake-out -j9 --target install --config "$CMAKE_BUILD_TYPE"
107+
}
108+
109+
cmake_build_demo() {
110+
echo "Building yolo12 runner"
111+
dir="examples/models/yolo12"
112+
retry cmake \
113+
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
114+
-DUSE_OPENVINO_BACKEND="$OPENVINO" \
115+
-DUSE_OPENVINO_BACKEND="$XNNPACK" \
116+
-Bcmake-out/${dir} \
117+
${dir}
118+
cmake --build cmake-out/${dir} -j9 --config "$CMAKE_BUILD_TYPE"
119+
120+
}
121+
122+
cleanup_files() {
123+
true
124+
}
125+
126+
prepare_artifacts_upload() {
127+
if [ -n "${UPLOAD_DIR}" ]; then
128+
true
129+
fi
130+
}
131+
132+
133+
# Export model.
134+
EXPORTED_MODEL_NAME="${MODEL_NAME}_fp32_${MODE}.pte"
135+
echo "Exporting ${EXPORTED_MODEL_NAME}"
136+
EXPORT_ARGS="--model_name=${MODEL_NAME} --backend=${MODE}"
137+
138+
# Add dynamically linked library location
139+
cmake_install_executorch_libraries
140+
141+
$PYTHON_EXECUTABLE -m examples.models.yolo12.export_and_validate ${EXPORT_ARGS}
142+
143+
144+
RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --input_path=${INPUT_VIDEO}"
145+
# Check build tool.
146+
cmake_build_demo
147+
# Run llama runner
148+
NOW=$(date +"%H:%M:%S")
149+
echo "Starting to run llama runner at ${NOW}"
150+
# shellcheck source=/dev/null
151+
cmake-out/examples/models/yolo12/Yolo12Detection ${RUNTIME_ARGS} > result.txt
152+
NOW=$(date +"%H:%M:%S")
153+
echo "Finished at ${NOW}"
154+
155+
RESULT=$(cat result.txt)
156+
157+
prepare_artifacts_upload
158+
cleanup_files

0 commit comments

Comments
 (0)