Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: Prepare your environment and image
description: Install the Swin2SR example and Arm ML SDK, then prepare a 64 × 64 input image and its high-resolution reference.
weight: 2

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## What you'll build

You will upscale a low-resolution image using Swin2SR, a pretrained image super-resolution model. It predicts finer detail as it doubles the image's width and height.

You export the model with ExecuTorch, then run it through the Arm Vulkan Graph Format (VGF) backend. The result is a PNG image you can open and compare with a high-resolution reference.

![Equal-size views compare a 64 by 64 low-resolution input with its 128 by 128 Swin2SR output. The input is enlarged for display only; labels show actual pixel dimensions. ExecuTorch and Arm VGF run the model on the host.#center](swin2sr-image-flow.svg "Images shown at the same display size to compare detail; labels show actual resolution")

This workflow runs on your Linux host using the Arm ML SDK's Vulkan emulation layer. It introduces the model execution flow used by Arm neural graphics; it doesn't deploy an application to a phone or measure Mali GPU performance.

## Install the example

Use a 64-bit Linux system (AArch64 or x86_64) with a working Vulkan 1.3 GPU driver. The packaged ML SDK checks for the `shaderFloat64` feature, even though you export a floating-point 32-bit model. The setup script stops if your GPU doesn't support it. Apple Silicon with MoltenVK needs a separate source-built SDK, which isn't covered here.

Have Python 3.12 with development headers and virtual environment support, Git, `curl`, `xz-utils`, a C++17 compiler, and [CMake 3.24–3.x](/install-guides/cmake/) available before continuing. On Ubuntu 24.04, the Python packages are `python3.12`, `python3.12-dev`, and `python3.12-venv`.

From a directory without an existing `executorch` folder, clone upstream ExecuTorch and select the revision containing this example. Keep the checkout folder named `executorch`; the build requires this exact name:

```bash
git clone https://github.com/pytorch/executorch.git
cd executorch
git checkout 32a86b69388b5a5208e367a96b0f5b7cb39df8e2
```

Create a Python environment and install ExecuTorch and the example's dependencies:

```bash
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
./install_executorch.sh --minimal
python -m pip install -r examples/arm/super_resolution_example_vgf/requirements.txt
```

Confirm that the installation succeeded before continuing:

```bash
python -c "import executorch.exir; from executorch.extension.pybindings import portable_lib; print('ExecuTorch is ready')"
```

Install the Arm ML SDK dependencies and activate their paths:

```bash
./examples/arm/setup.sh \
--disable-ethos-u-deps \
--disable-cortex-m-deps \
--enable-mlsdk-deps
source examples/arm/arm-scratch/setup_path.sh
```

The setup script installs the Vulkan SDK and the tools that compile and execute VGF graphs. Keep this terminal open and run the remaining commands from the `executorch` directory.

## Prepare the input image

Create the example images from a screenshot included in ExecuTorch:

```bash
python examples/arm/super_resolution_example_vgf/model_export/prepare_demo_assets.py \
--output-dir swin2sr-work
```

The script creates a 128 × 128 crop and downsizes a copy to 64 × 64. You use these two files:

| File in `swin2sr-work/runtime/` | What it is |
| --- | --- |
| `demo_lr_64.png` | Small image you give to the model |
| `demo_hr_128.png` | High-resolution reference: the original crop before downsampling |

The helper also prepares calibration and evaluation folders. You don't need them for this floating-point walkthrough.

## What you've accomplished and what's next

You have the example, its tools, and a small input image with a high-resolution reference. Next, export Swin2SR as an ExecuTorch program.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Export Swin2SR for Arm VGF
description: Convert the pretrained Swin2SR ×2 model into a floating-point ExecuTorch program with Arm VGF.
weight: 3

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Export the pretrained model

You don't need to train Swin2SR. The exporter downloads the pretrained ×2 checkpoint and converts it into an ExecuTorch `.pte` program. The pinned checkpoint revision keeps the model weights consistent between runs.

Run the exporter from your ExecuTorch directory:

```bash
python examples/arm/super_resolution_example_vgf/model_export/export_super_resolution.py \
--model-name swin2sr \
--checkpoint caidas/swin2SR-classical-sr-x2-64 \
--checkpoint-revision cee1c923c6a37361c6e5650b65dcf4be821e5d52 \
--input-height 64 \
--input-width 64 \
--quantization-mode none \
--output-path swin2sr-work/swin2sr.pte
```

The first run downloads the model weights. `--quantization-mode none` keeps floating-point calculations, so you don't need calibration images.

The `64` dimensions fix the input size for this export. The model produces a 128 × 128 image because the checkpoint upscales by two.

## Keep the program and metadata together

After export finishes, check the two files the runner needs:

```bash
ls -lh swin2sr-work/swin2sr.pte swin2sr-work/swin2sr.json
```

`swin2sr.pte` contains the executable model, including its VGF graphs. `swin2sr.json` tells the image helper how to read the input and reconstruct the output. Keep both files in the same directory with the same base name.

The exporter also saves `swin2sr_delegation.txt`. It records which operations run through VGF and which remain in ExecuTorch. You don't need to change this report to run the example.

## What you've accomplished and what's next

You have a floating-point Swin2SR program configured for one 64 × 64 RGB image. Next, build the host runner and use it to upscale your image.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Run Swin2SR on your image
description: Build the VGF host runner and use the exported Swin2SR program to save a 128 × 128 image.
weight: 4

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Build the host runner

ExecuTorch's `executor_runner` loads your `.pte` program and executes it. Continue from the same terminal in your `executorch` directory.

If you opened a new terminal, restore the environment first:

```bash
source .venv/bin/activate
source examples/arm/arm-scratch/setup_path.sh
```

Use the repository's build script to enable VGF and the runtime libraries it needs:

```bash
bash backends/arm/scripts/build_executor_runner_vkml.sh \
--output=swin2sr-work/build
```

This builds a Release executable at `swin2sr-work/build/executor_runner`. You only need to build it once for this walkthrough.

## Upscale the image

Run the image helper with your exported program, the host runner, and the 64 × 64 input:

```bash
python examples/arm/super_resolution_example_vgf/runtime/run_super_resolution.py \
--model-path swin2sr-work/swin2sr.pte \
--runner swin2sr-work/build/executor_runner \
--input-image swin2sr-work/runtime/demo_lr_64.png \
--output-image swin2sr-work/runtime/demo_sr_128.png
```

The helper converts the image into a tensor, runs the model, and saves the output tensor as a PNG. A successful run ends with `Saved super-resolved image to` followed by the full path to `demo_sr_128.png`.

Your input must be exactly 64 × 64 pixels. If you see an `expected (1, 3, 64, 64)` error, check that you used `demo_lr_64.png`, not the larger reference image.

## What you've accomplished and what's next

You have executed the exported program and saved its 128 × 128 output. Next, open the result and compare it with the input and high-resolution reference.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Inspect the upscaled image
description: Verify the Swin2SR output size and compare the generated image with the low-resolution input and high-resolution reference.
weight: 5

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Check the image dimensions

Confirm that the input is 64 × 64 and that the model created a 128 × 128 RGB image:

```bash
python - <<'PY'
from PIL import Image

for name in ("demo_lr_64.png", "demo_sr_128.png", "demo_hr_128.png"):
with Image.open(f"swin2sr-work/runtime/{name}") as image:
print(f"{name}: {image.width} x {image.height}, {image.mode}")
PY
```

The expected output is:

```output
demo_lr_64.png: 64 x 64, RGB
demo_sr_128.png: 128 x 128, RGB
demo_hr_128.png: 128 x 128, RGB
```

Twice the width and twice the height give you four times as many pixels.

## Compare the images

Open `swin2sr-work/runtime/` in your image viewer. Compare the low-resolution input, the Swin2SR output, and the high-resolution reference. Enlarge the input to the same display size so you can compare the same text and edges.

The high-resolution reference is the original 128 × 128 crop, before downsampling creates the 64 × 64 input. You keep it for comparison; the model receives only the low-resolution input.

![Low-resolution input enlarged for display, an actual Swin2SR output from an earlier run, and the high-resolution reference at the same display size. Compare letter edges to see reconstructed detail and remaining differences.#center](swin2sr-result-comparison.png "Low-resolution input, Swin2SR output, and high-resolution reference at the same display size")

The example output shown here comes from an earlier run with the same checkpoint and demo image. It illustrates the comparison; it isn't a new measurement on your host.

Look at the edges of the letters. The output estimates detail that was lost when the original was reduced to 64 × 64. It won't reproduce every detail of the original, and a larger image doesn't automatically mean a more accurate one.

Your end-to-end flow succeeds when the runner finishes, the generated image has the expected dimensions, and it shows the same scene without obvious corruption. This visual check doesn't establish a quality benchmark or a performance result.

## Try another image

Use another 64 × 64 RGB image with the same program. Replace `my-image.png` with its path and choose a new output name:

```bash
python examples/arm/super_resolution_example_vgf/runtime/run_super_resolution.py \
--model-path swin2sr-work/swin2sr.pte \
--runner swin2sr-work/build/executor_runner \
--input-image my-image.png \
--output-image swin2sr-work/runtime/my-image-sr.png
```

For a different input size, export a matching program first. The helper doesn't resize or tile images automatically.

## What you've accomplished

You have prepared an image, exported a pretrained Swin2SR model, run it through Arm VGF with ExecuTorch, and inspected the upscaled output. You can now repeat the same flow with your own 64 × 64 images.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: Upscale an image with Swin2SR and Arm VGF

draft: true
cascade:
draft: true

description: Export Swin2SR with ExecuTorch and run it through Arm VGF on your Linux host to upscale a low-resolution image and reconstruct finer detail.

minutes_to_complete: 60
lastmod: 2026-09-14

who_is_this_for: This is an introductory topic for machine learning and graphics developers who want to run image super-resolution with ExecuTorch and Arm VGF.

learning_objectives:
- Prepare ExecuTorch, the Arm ML SDK for Vulkan, and a sample image
- Export a pretrained Swin2SR model as a VGF-backed ExecuTorch program
- Build the host runner and upscale a 64 × 64 image to 128 × 128
- Check the output dimensions and compare the result with the high-resolution reference

prerequisites:
- A 64-bit Linux host (AArch64 or x86_64) with a Vulkan 1.3 GPU and driver that support shaderFloat64, as required by the packaged ML SDK emulation layer
- Python 3.12 with development headers and venv support, Git, curl, xz-utils, CMake 3.24–3.x, and a C++17 compiler
- An internet connection to download ExecuTorch, model weights, and the Arm ML SDK dependencies
- Basic familiarity with Python and command-line tools

author: Usamah Zaheer

generate_summary_faq: true
rerun_summary: false
rerun_faqs: false

### Tags
skilllevels: Introductory
subjects: ML
armips:
- Mali
tools_software_languages:
- ExecuTorch
- PyTorch
- Python
- Vulkan
- VGF
operatingsystems:
- Linux

further_reading:
- resource:
title: Swin2SR VGF example source
link: https://github.com/pytorch/executorch/tree/32a86b69388b5a5208e367a96b0f5b7cb39df8e2/examples/arm/super_resolution_example_vgf
type: code
- resource:
title: Swin2SR pretrained model
link: https://huggingface.co/caidas/swin2SR-classical-sr-x2-64
type: website
- resource:
title: Arm ML SDK for Vulkan
link: https://github.com/arm/ai-ml-sdk-for-vulkan
type: documentation
- resource:
title: Prepare models for neural graphics with Arm neural technology
link: /learning-paths/mobile-graphics-and-gaming/preparing-models-for-nt/
type: learningpath
- resource:
title: Quantize neural upscaling models with ExecuTorch
link: /learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/
type: learningpath

### FIXED, DO NOT MODIFY
# ================================================================================
weight: 1
layout: "learningpathall"
learning_path_main_page: "yes"
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# ================================================================================
# FIXED, DO NOT MODIFY THIS FILE
# ================================================================================
weight: 21
title: "Next Steps"
layout: "learningpathall"
---
Loading
Loading