Skip to content

Commit c1c9a5e

Browse files
authored
Arm backend: add VGF image classification flow (pytorch#18012)
### Summary - Add a VGF‑specific image classification example (export script + docs) alongside the Ethos‑U example. - Keep Ethos‑U example docs/scripts scoped to Ethos‑U; add wget/curl fallback for OOTB image download. cc @digantdesai @SS-JIA @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell Signed-off-by: Usamah Zaheer <usamah.zaheer@arm.com>
1 parent e458023 commit c1c9a5e

17 files changed

Lines changed: 436 additions & 18 deletions

File tree

‎backends/arm/test/test_arm_ootb.sh‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if [[ "$1" == "-h" || "$1" == "--help" ]]; then
2222
fi
2323

2424
if [[ $# -eq 0 ]]; then
25-
TEST_SUITES=(run_ootb_tests_ethos_u run_ootb_tests_tosa run_deit_e2e_ethos_u)
25+
TEST_SUITES=(run_ootb_tests_ethos_u run_ootb_tests_tosa run_ootb_tests_vgf run_deit_e2e_ethos_u)
2626
else
2727
TEST_SUITES=("$1")
2828
fi
@@ -44,13 +44,21 @@ run_ootb_tests_tosa() {
4444
echo "${FUNCNAME}: PASS"
4545
}
4646

47+
run_ootb_tests_vgf() {
48+
echo "$FUNCNAME: Running out-of-the-box tests for VGF"
49+
jupyter nbconvert \
50+
--to notebook \
51+
--execute examples/arm/vgf_minimal_example.ipynb
52+
echo "${FUNCNAME}: PASS"
53+
}
54+
4755
run_deit_e2e_ethos_u() {
4856
echo "$FUNCNAME: Fine-tune, export, build, and run the DEiT e2e test"
4957

5058
local script_dir
5159
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
5260
et_root_dir=$(cd "${script_dir}/../../.." && pwd)
53-
local example_dir="${et_root_dir}/examples/arm/image_classification_example"
61+
local example_dir="${et_root_dir}/examples/arm/image_classification_example_ethos_u"
5462
local work_root="${et_root_dir}/arm_test/deit_tiny_ootb_smoke"
5563
local model_dir="${work_root}/deit_tiny_finetuned"
5664
local export_dir="${work_root}/export"
@@ -74,7 +82,7 @@ run_deit_e2e_ethos_u() {
7482
cmake --build "${et_root_dir}/cmake-out-arm" --target install -j"$n_proc"
7583

7684
# Install requirements
77-
pip install -r examples/arm/image_classification_example/requirements.txt
85+
pip install -r examples/arm/image_classification_example_ethos_u/requirements.txt
7886

7987
# Get and finetune model
8088
echo "${FUNCNAME}: Running DeiT fine-tuning script"
@@ -99,7 +107,14 @@ run_deit_e2e_ethos_u() {
99107
local image_url="https://gitlab.arm.com/artificial-intelligence/ethos-u/ml-embedded-evaluation-kit/-/raw/main/resources/img_class/samples/dog.bmp?ref_type=heads"
100108
if [[ ! -f "${image_path}" ]]; then
101109
echo "${FUNCNAME}: Downloading sample image from ${image_url}"
102-
wget -O "${image_path}" "${image_url}"
110+
if command -v wget >/dev/null 2>&1; then
111+
wget -O "${image_path}" "${image_url}"
112+
elif command -v curl >/dev/null 2>&1; then
113+
curl -L "${image_url}" -o "${image_path}"
114+
else
115+
echo "${FUNCNAME}: Missing wget or curl; unable to download sample image"
116+
return 1
117+
fi
103118
else
104119
echo "${FUNCNAME}: Reusing sample image at ${image_path}"
105120
fi

‎examples/arm/image_classification_example/requirements.txt‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/arm/image_classification_example/README.md renamed to examples/arm/image_classification_example_ethos_u/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,3 @@ The example is divided into two sections:
1313

1414
- `model_export/README.md` — Covers fine-tuning a model for a new usecase, quantization to INT8, lowering to Ethos-U via ExecuTorch and `.pte` generation.
1515
- `runtime/README.md` — Covers building the bare-metal app, generating headers from the `.pte` and image, and running on the FVP.
16-
17-
In addition, this example uses `../executor_runner/` for various utilities (linker scripts, memory allocators, and the PTE-to-header converter).

examples/arm/image_classification_example/model_export/README.md renamed to examples/arm/image_classification_example_ethos_u/model_export/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ See the sections below for requirements and exact commands.
1212

1313
## Requirements
1414

15-
- Python 3.10+ with `executorch` and the dependencies in `examples/arm/image_classification_example/requirements.txt`.
15+
- Python 3.10+ with `executorch` and the dependencies in `examples/arm/image_classification_example_ethos_u/requirements.txt`.
1616
- Internet access to download pretrained weights and the Oxford-IIIT Pet dataset.
1717

1818
## Fine-tuning DEiT Tiny
1919

2020
The `train_deit.py` script can be run as follows:
2121

2222
```bash
23-
python examples/arm/image_classification_example/model_export/train_deit.py \
23+
python examples/arm/image_classification_example_ethos_u/model_export/train_deit.py \
2424
--output-dir ./deit-tiny-oxford-pet \
2525
--num-epochs 3
2626
```
@@ -33,7 +33,7 @@ Running this script achieves a test set accuracy of 86.10% in FP32.
3333
The `export_deit.py` script can be run as follows:
3434

3535
```bash
36-
python examples/arm/image_classification_example/model_export/export_deit.py \
36+
python examples/arm/image_classification_example_ethos_u/model_export/export_deit.py \
3737
--model-path ./deit-tiny-oxford-pet/final_model \
3838
--output-path ./deit_quantized_exported.pte \
3939
--num-calibration-samples 300 \

examples/arm/image_classification_example/model_export/export_deit.py renamed to examples/arm/image_classification_example_ethos_u/model_export/export_deit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def measure_accuracy(quantized_model, test_set):
8484

8585

8686
if __name__ == "__main__":
87-
argparser = argparse.ArgumentParser(description="Export ViT model")
87+
argparser = argparse.ArgumentParser(description="Export ViT model for Ethos-U")
8888
argparser.add_argument(
8989
"--model-path",
9090
type=str,
@@ -123,13 +123,12 @@ def measure_accuracy(quantized_model, test_set):
123123
use_fast=True,
124124
revision="b3428f18dcc7b543470d07f14b4a4157815d1880",
125125
)
126-
127126
compile_spec = EthosUCompileSpec(
128127
target="ethos-u85-256",
129128
memory_mode="Shared_Sram",
130129
)
131-
132130
quantizer = EthosUQuantizer(compile_spec)
131+
133132
operator_config = get_symmetric_quantization_config()
134133
quantizer.set_global(operator_config)
135134

examples/arm/image_classification_example/model_export/train_deit.py renamed to examples/arm/image_classification_example_ethos_u/model_export/train_deit.py

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2026 Arm Limited and/or its affiliates.
2+
#
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
evaluate == 0.4.6
7+
transformers[torch] == 4.56.1
8+
tqdm == 4.67.1

examples/arm/image_classification_example/runtime/CMakeLists.txt renamed to examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt

File renamed without changes.

examples/arm/image_classification_example/runtime/README.md renamed to examples/arm/image_classification_example_ethos_u/runtime/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ cmake --build ../../cmake-out-arm --target install -j$(nproc)
1212
```
1313

1414
3. Set up the build system. You need to provide path to the DEiT-Tiny pte generated in the
15-
`examples/arm/image_classification_example/model_export` folder. You also need to provide an image of a dog or cat, you can download such image from the [HuggingFace Oxford iiit pet dataset](https://huggingface.co/datasets/timm/oxford-iiit-pet).
15+
`examples/arm/image_classification_example_ethos_u/model_export` folder. You also need to provide an image of a dog or cat, you can download such image from the [HuggingFace Oxford iiit pet dataset](https://huggingface.co/datasets/timm/oxford-iiit-pet).
1616

1717
```
18-
$ cmake -DCMAKE_TOOLCHAIN_FILE=$(pwd)/ethos-u-setup/arm-none-eabi-gcc.cmake -DET_PTE_FILE_PATH=<path to DEiT-Tiny compiled for Ethos-U85-256> -DIMAGE_PATH=<path to a JPG image> -Bsimple_app_deit_tiny image_classification_example/runtime
18+
$ cmake -DCMAKE_TOOLCHAIN_FILE=$(pwd)/ethos-u-setup/arm-none-eabi-gcc.cmake -DET_PTE_FILE_PATH=<path to DEiT-Tiny compiled for Ethos-U85-256> -DIMAGE_PATH=<path to a JPG image> -Bsimple_app_deit_tiny image_classification_example_ethos_u/runtime
1919
```
2020

2121
4. Compile the application.
@@ -28,4 +28,4 @@ $ cmake --build simple_app_deit_tiny -j$(nproc) -- img_class_example
2828

2929
```
3030
$ FVP_Corstone_SSE-320 -C mps4_board.subsystem.ethosu.num_macs=256 -C mps4_board.visualisation.disable-visualisation=1 -C vis_hdlcd.disable_visualisation=1 -C mps4_board.telnetterminal0.start_telnet=0 -C mps4_board.uart0.out_file='-' -C mps4_board.uart0.shutdown_on_eot=1 -a simple_app_deit_tiny/img_class_example -C mps4_board.subsystem.ethosu.extra_args="--fast"
31-
```
31+
```

examples/arm/image_classification_example/runtime/main.cpp renamed to examples/arm/image_classification_example_ethos_u/runtime/main.cpp

File renamed without changes.

0 commit comments

Comments
 (0)