Skip to content

Commit 537554a

Browse files
Merge pull request #42 from google-ai-edge:add-shufflenet
PiperOrigin-RevId: 917556145
2 parents 861b0fe + c8e05df commit 537554a

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

examples/models/shufflenet.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
# Copyright 2026 The LiteRT CLI Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
17+
# LiteRT CLI ShuffleNetV2 Demo & Test Script
18+
set -e
19+
20+
# Source shared utilities relative to script
21+
source "$(dirname "${BASH_SOURCE[0]}")/../utils.sh"
22+
23+
setup_test_env "shufflenet" "ShuffleNetV2 Demo Script"
24+
25+
# --- 1. Download ShuffleNetV2 model ---
26+
run_case "Download: ShuffleNetV2 from HuggingFace" \
27+
litert download litert-community/shufflenet_v2_x1_0 --file "*.tflite" --output "models/shufflenet"
28+
29+
# Verify the downloaded model exists using the exact repository naming convention
30+
SHUFFLENET_TFLITE="models/shufflenet/shufflenet_v2_x1_0.tflite"
31+
if [ ! -f "$SHUFFLENET_TFLITE" ]; then
32+
echo -e "${RED}Error: Downloaded model not found at $SHUFFLENET_TFLITE${NC}"
33+
exit 1
34+
fi
35+
36+
# --- 2. Quantize the ShuffleNet model ---
37+
run_case "Quantize: ShuffleNet Dynamic Range INT8" \
38+
litert quantize "$SHUFFLENET_TFLITE" --recipe dynamic_wi8_afp32 --output "models/shufflenet/shufflenet_v2_x1_0_int8_dynamic.tflite"
39+
40+
run_case "Quantize: ShuffleNet Weight-Only INT8" \
41+
litert quantize "$SHUFFLENET_TFLITE" --recipe weight_only_wi8_afp32 --output "models/shufflenet/shufflenet_v2_x1_0_int8_weight_only.tflite"
42+
43+
# --- 3. Run Inference (Desktop & Android) ---
44+
run_case "Run: ShuffleNet FP32 on Desktop (CPU)" \
45+
litert run "$SHUFFLENET_TFLITE" --desktop --cpu --iterations 1
46+
47+
if has_desktop_gpu "$SHUFFLENET_TFLITE"; then
48+
run_case "Run: ShuffleNet FP32 on Desktop (GPU)" \
49+
litert run "$SHUFFLENET_TFLITE" --desktop --gpu --iterations 1
50+
else
51+
echo -e "\n${YELLOW}Desktop GPU delegate is not supported. Skipping Desktop GPU run.${NC}"
52+
fi
53+
54+
run_case "Run: ShuffleNet Dynamic INT8 on Desktop (CPU)" \
55+
litert run "models/shufflenet/shufflenet_v2_x1_0_int8_dynamic.tflite" --desktop --cpu --iterations 1
56+
57+
if has_android_device; then
58+
echo -e "\n${GREEN}Android device detected. Running Android inference...${NC}"
59+
run_case "Run: ShuffleNet FP32 on Android (CPU)" \
60+
litert run "$SHUFFLENET_TFLITE" --android --cpu --iterations 1
61+
62+
run_case "Run: ShuffleNet FP32 on Android (GPU)" \
63+
litert run "$SHUFFLENET_TFLITE" --android --gpu --cpu --iterations 1
64+
65+
# If you have Android devices with NPU connected, enable those use cases.
66+
run_case "Run: ShuffleNet FP32 on Android (NPU)" \
67+
litert run "$SHUFFLENET_TFLITE" --android --npu --iterations 1
68+
69+
run_case "Run: ShuffleNet Dynamic INT8 on Android (CPU)" \
70+
litert run "models/shufflenet/shufflenet_v2_x1_0_int8_dynamic.tflite" --android --cpu --iterations 1
71+
fi
72+
73+
# --- 4. Benchmark (Desktop & Android) ---
74+
run_case "Benchmark: ShuffleNet FP32 on Desktop (CPU)" \
75+
litert benchmark "$SHUFFLENET_TFLITE" --desktop --cpu
76+
77+
run_case "Benchmark: ShuffleNet Dynamic INT8 on Desktop (CPU)" \
78+
litert benchmark "models/shufflenet/shufflenet_v2_x1_0_int8_dynamic.tflite" --desktop --cpu
79+
80+
if has_android_device; then
81+
echo -e "\n${GREEN}Android device detected. Running Android benchmarks...${NC}"
82+
run_case "Benchmark: ShuffleNet FP32 on Android (CPU)" \
83+
litert benchmark "$SHUFFLENET_TFLITE" --android
84+
85+
run_case "Benchmark: ShuffleNet FP32 on Android (GPU)" \
86+
litert benchmark "$SHUFFLENET_TFLITE" --android --gpu
87+
88+
# If you have Android devices with NPU connected, enable those use cases.
89+
run_case "Benchmark: ShuffleNet FP32 on Android (NPU)" \
90+
litert benchmark "$SHUFFLENET_TFLITE" --android --npu
91+
92+
run_case "Benchmark: ShuffleNet Dynamic INT8 on Android" \
93+
litert benchmark "models/shufflenet/shufflenet_v2_x1_0_int8_dynamic.tflite" --android
94+
else
95+
echo -e "\n${YELLOW}No Android device detected. Skipping benchmarks on Android.${NC}"
96+
fi
97+
98+
# --- 5. Compile (AOT Compilation) ---
99+
if [[ "$(uname)" == "Linux" ]]; then
100+
run_case "Compile: ShuffleNet FP32 for Qualcomm sm8750 NPU" \
101+
litert compile "$SHUFFLENET_TFLITE" --target sm8750 --output-dir "models/shufflenet"
102+
else
103+
echo -e "\n${YELLOW}Skipping offline AOT compilation on non-Linux platform ($(uname)).${NC}"
104+
fi
105+
106+
# --- 6. Visualize (Model Explorer) ---
107+
run_case "Visualize: Launch Model Explorer in the background" \
108+
litert visualize "$SHUFFLENET_TFLITE"
109+
110+
run_case "Visualize: Stop all Model Explorer servers" \
111+
litert visualize --stop-all
112+
113+
# --- Summary Report ---
114+
print_summary_report "ShuffleNet"

0 commit comments

Comments
 (0)