Skip to content

Commit ee420ef

Browse files
committed
first review of onnx LP
1 parent 749ae72 commit ee420ef

5 files changed

Lines changed: 64 additions & 13 deletions

File tree

content/learning-paths/mobile-graphics-and-gaming/onnx/02_setup.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,55 @@ You can choose a variety of hardware, including:
1919
The nice thing about ONNX is that the **same model file** can run across all of these, so your setup is flexible.
2020

2121
## Install Python
22-
Depending on the hardware you use you follow different installation paths
2322

24-
1. Linux (Arm64). In the console type:
23+
{{% notice Note %}}
24+
ONNX Runtime provides prebuilt wheels only for specific Python versions. At the time of writing, Python 3.12 is not yet supported by ONNX Runtime on macOS or Arm platforms. If you see an error like:
25+
26+
```output
27+
ERROR: No matching distribution found for onnxruntime
28+
```
29+
30+
it usually means your Python version is too new. Python 3.10 is tested and recommended for this Learning Path.
31+
{{% /notice %}}
32+
33+
Depending on the hardware you use, follow different installation paths:
34+
35+
1. Linux (Arm64). Install Python 3.10 by typing in the console:
2536
```console
2637
sudo apt update
27-
sudo apt install -y python3 python3-venv python3-pip build-essential libopenblas-dev libgl1 libglib2.0-0
38+
sudo apt install -y python3.10 python3.10-venv python3.10-dev python3-pip build-essential libopenblas-dev libgl1 libglib2.0-0
2839
```
2940

30-
2. macOS (Apple Sillicon):
41+
If Python 3.10 is not available in your default repositories, you can use the deadsnakes PPA:
3142
```console
32-
brew install python
43+
sudo add-apt-repository ppa:deadsnakes/ppa
44+
sudo apt update
45+
sudo apt install -y python3.10 python3.10-venv python3.10-dev
3346
```
3447

48+
2. macOS (Apple Silicon). Install Python 3.10 using Homebrew:
49+
```console
50+
brew install python@3.10
51+
```
52+
53+
After installation, use `python3.10` explicitly when creating virtual environments.
54+
3555
3. Windows on Arm:
36-
* Install Python 3.10+ from python.org (Arm64 build).
56+
* Download and install Python 3.10 from [python.org](https://www.python.org/downloads/) (select the Arm64 build).
3757
* Ensure pip is on PATH.
3858

39-
After installing Python, open a terminal or console, create a clean virtual environment, and update pip and wheel:
59+
After installing Python 3.10, open a terminal or console, create a clean virtual environment using Python 3.10 explicitly, and update pip and wheel:
60+
61+
```console
62+
python3.10 -m venv .venv
63+
source .venv/bin/activate
64+
python -m pip install --upgrade pip wheel
65+
```
4066

67+
On macOS, if `python3.10` is not found, use the full Homebrew path:
4168
```console
42-
python3 -m venv .venv
43-
source .venv/bin/activate # on Windows use: .venv\Scripts\activate
69+
/opt/homebrew/bin/python3.10 -m venv .venv
70+
source .venv/bin/activate
4471
python -m pip install --upgrade pip wheel
4572
```
4673

content/learning-paths/mobile-graphics-and-gaming/onnx/03_preparingdata.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,18 @@ data/
241241
pip install pandas pyarrow opencv-python tqdm numpy
242242
```
243243

244-
2. Place the Parquet file (e.g., train_1.parquet) next to the script or update PARQUET_PATH accordingly. Here we used the file from [this location](https://huggingface.co/datasets/Ritvik19/Sudoku-Dataset/blob/main/train_1.parquet).
244+
2. Download the Sudoku dataset from Hugging Face. This Learning Path uses the `train_1.parquet` file from the [Ritvik19/Sudoku-Dataset](https://huggingface.co/datasets/Ritvik19/Sudoku-Dataset) repository.
245245

246-
3. Run the generator
246+
Download the dataset file:
247+
```console
248+
wget https://huggingface.co/datasets/Ritvik19/Sudoku-Dataset/resolve/main/train_1.parquet
249+
```
250+
251+
Alternatively, you can download it manually from the [direct link](https://huggingface.co/datasets/Ritvik19/Sudoku-Dataset/blob/main/train_1.parquet) and save it as `train_1.parquet` in your working directory.
252+
253+
The Parquet file should be placed next to the script, or you can update `PARQUET_PATH` in the code to point to its location.
254+
255+
3. Run the generator:
247256
```console
248257
python3 02_PrepareData.py
249258
```

content/learning-paths/mobile-graphics-and-gaming/onnx/04_training.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import torch.nn.functional as F
6161
from torch.utils.data import DataLoader
6262
from torchvision import datasets, transforms
6363
from tqdm import tqdm
64-
from torch.onnx import dynamo_export
6564
from torch.export import Dim
6665
import onnxruntime as ort
6766

@@ -189,6 +188,15 @@ The file will create two artifacts:
189188
Right after export, the script runs a parity test: it feeds the same randomly generated batch through both the PyTorch model and the ONNX model (executed by ONNX Runtime) and prints the mean absolute error between their logits. A tiny value confirms the exported graph faithfully matches your trained network.
190189

191190
## Running the script
191+
192+
{{% notice Note %}}
193+
The Dynamo-based ONNX exporter requires PyTorch 2.1 or later. If you encounter errors related to `torch.export.Dim` or the `dynamo` parameter, ensure you have an up-to-date PyTorch installation:
194+
195+
```console
196+
pip install --upgrade torch torchvision
197+
```
198+
{{% /notice %}}
199+
192200
To run the training script, type:
193201

194202
```console

content/learning-paths/mobile-graphics-and-gaming/onnx/05_inference.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ These artifacts provide both quantitative and qualitative insight into model per
213213
In the sample grid, each tile shows one crop together with its True label (T:) and Predicted label (P:), with correct predictions highlighted in green and mistakes highlighted in red. This makes it easy to quickly verify that the classifier behaves sensibly and to spot remaining failure modes.
214214

215215
## Running the script
216+
217+
Before running the evaluation script, install matplotlib for visualization:
218+
219+
```console
220+
pip install matplotlib
221+
```
222+
216223
Run the evaluation script from the project root:
217224

218225
```console

content/learning-paths/mobile-graphics-and-gaming/onnx/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ learning_objectives:
1717
- Deploy an optimized ONNX model inside an Android app.
1818

1919
prerequisites:
20-
- A development machine with Python 3.10+ installed.
20+
- A development machine with Python 3.10 installed (Python 3.11 also works; Python 3.12 is not yet supported by ONNX Runtime on Arm platforms).
2121
- Basic familiarity with PyTorch or TensorFlow.
2222
- An Arm64 device (e.g., Raspberry Pi or Android smartphone).
2323
- "[Android Studio](https://developer.android.com/studio) installed for deployment testing."

0 commit comments

Comments
 (0)