Skip to content

Commit a188e04

Browse files
committed
Fixes
1 parent bac2541 commit a188e04

8 files changed

Lines changed: 16 additions & 13 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ weight: 2
66

77
layout: "learningpathall"
88
---
9-
The goal of this tutorial is to provide developers with a practical, end-to-end pathway for working with Open Neural Network Exchange (ONNX) in real-world scenarios. Starting from the fundamentals, we will build a simple neural network model in Python, export it to the ONNX format, and demonstrate how it can be used for both inference and training on Arm64 platforms. Along the way, we will cover model optimization techniques such as layer fusion, and conclude by deploying the optimized model into a fully functional Android application. By following this series, you will gain not only a solid understanding of ONNX’s philosophy and ecosystem but also the hands-on skills required to integrate ONNX into your own projectsfrom prototyping to deployment.
9+
The goal of this tutorial is to provide developers with a practical, end-to-end pathway for working with Open Neural Network Exchange (ONNX) in real-world scenarios. Starting from the fundamentals, we will build a simple neural network model in Python, export it to the ONNX format, and demonstrate how it can be used for both inference and training on Arm64 platforms. Along the way, we will cover model optimization techniques such as layer fusion, and conclude by deploying the optimized model into a fully functional Android application. By following this series, you will gain not only a solid understanding of ONNX’s philosophy and ecosystem but also the hands-on skills required to integrate ONNX into your own projects from prototyping to deployment.
1010

11-
In this first step, we will introduce the ONNX standard and explain why it has become a cornerstone of modern machine learning workflows. You will learn what ONNX is, how it represents models in a framework-agnostic format, and why this matters for developers targeting different platforms such as desktops, Arm64 devices, or mobile environments. We will also discuss the role of ONNX Runtime as the high-performance engine that brings these models to life, enabling efficient inference and even training across CPUs, GPUs, and specialized accelerators. Finally, we will outline the typical ONNX workflowfrom training in frameworks like PyTorch or TensorFlow, through export and optimization, to deployment on edge and Android deviceswhich we will gradually demonstrate throughout the tutorial.
11+
In this first step, we will introduce the ONNX standard and explain why it has become a cornerstone of modern machine learning workflows. You will learn what ONNX is, how it represents models in a framework-agnostic format, and why this matters for developers targeting different platforms such as desktops, Arm64 devices, or mobile environments. We will also discuss the role of ONNX Runtime as the high-performance engine that brings these models to life, enabling efficient inference and even training across CPUs, GPUs, and specialized accelerators. Finally, we will outline the typical ONNX workflow, from training in frameworks like PyTorch or TensorFlow, through export and optimization, to deployment on edge and Android devices, which we will gradually demonstrate throughout the tutorial.
1212

1313
## What is ONNX
1414
The ONNX is an open standard for representing machine learning models in a framework-independent format. Instead of being tied to the internal model representation of a specific framework—such as PyTorch, TensorFlow, or scikit-learn—ONNX provides a universal way to describe models using a common set of operators, data types, and computational graphs.
@@ -17,7 +17,7 @@ At its core, an ONNX model is a directed acyclic graph (DAG) where nodes represe
1717

1818
ONNX was originally developed by Microsoft and Facebook to address a growing need in the machine learning community: the ability to move models seamlessly between training environments and deployment targets. Today, it is supported by a wide ecosystem of contributors and hardware vendors, making it the de facto choice for interoperability and cross-platform deployment.
1919

20-
For developers, this means flexibility: you can train your model in PyTorch, export it to ONNX, run it with ONNX Runtime on an Arm64 device such as a Raspberry Pi, and later deploy it inside an Android application without rewriting the model. This portability is the main reason ONNX has become a central building block in modern AI workflows.
20+
For developers, this means flexibility. You can train your model in PyTorch, export it to ONNX, run it with ONNX Runtime on an Arm64 device such as a Raspberry Pi, and later deploy it inside an Android application without rewriting the model. This portability is the main reason ONNX has become a central building block in modern AI workflows.
2121

2222
A useful way to think of ONNX is to compare it to a PDF for machine learning models. Just as a PDF file ensures that a document looks the same regardless of whether you open it in Adobe Reader, Preview on macOS, or a web browser, ONNX ensures that a machine learning model behaves consistently whether you run it on a server GPU, a Raspberry Pi, or an Android phone. It is this “write once, run anywhere” principle that makes ONNX especially powerful for developers working across diverse hardware platforms.
2323

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ By generating synthetic Sudoku pages directly from the parquet dataset, we get:
2323
4. Scalability. With millions of Sudoku solutions available, we can easily generate tens of thousands of training samples in minutes, ensuring a dataset that is both large and diverse.
2424

2525
This synthetic data generation strategy allows us to create a custom-fit dataset for our Sudoku digit recognition problem, bridging the gap between clean digital puzzles and noisy real-world inputs.
26-
In this Learning Path, you have created an Android application to capture and process camera images using OpenCV.
2726

2827
## What we’ll produce
2928
By the end of this step, you will have two complementary datasets:
@@ -246,7 +245,7 @@ pip install pandas pyarrow opencv-python tqdm numpy
246245

247246
3. Run the generator
248247
```console
249-
python 02_PrepareData.py
248+
python3 02_PrepareData.py
250249
```
251250

252251
4. Inspect outputs:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Right after export, the script runs a parity test: it feeds the same randomly ge
192192
To run the training script, type:
193193

194194
```console
195-
python 03_Training.py
195+
python3 03_Training.py
196196
```
197197

198198
The script will train, validate, export, and verify the digit recognizer in one go. After it finishes, you’ll have both a portable ONNX model and a PyTorch checkpoint ready for the next step—building the image processor that detects the Sudoku grid, rectifies it, segments cells, and performs batched ONNX inference to reconstruct the board for solving.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ In the sample grid, each tile shows one crop together with its True label (T:) a
216216
Run the evaluation script from the project root:
217217

218218
```console
219-
python 04_Test.py
219+
python3 04_Test.py
220220
```
221221

222222
In the example below, the PyTorch and ONNX accuracies match exactly, confirming that the export process preserved model behavior.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ The processor saves several artifacts to help debugging and demonstration:
375375
- `artifacts/overlay_solution.png` – solution digits overlaid onto the original image (if solved).
376376
- (Optional) `artifacts/recognized_board.png`, `artifacts/solved_board.png`, `artifacts/boards_side_by_side.png` – clean board renderings if you enabled those helpers.
377377

378+
The driver script below saves warped.png and overlay_solution.png by default.
379+
378380
## Running the processor
379381
A small driver script (05_RunSudokuProcessor.py) demonstrates how to use the SudokuProcessor:
380382

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To quantify these contributions, we will add simple timing measurements around e
2121
* preprocess_ms – total time spent preprocessing all 81 cells
2222
* onnx_ms – time spent running batched ONNX inference
2323
* solve_ms – time spent solving the Sudoku
24+
* split_ms – time spent splitting the warped grid into 81 cells
2425
* total_ms – end-to-end processing time
2526

2627
## Performance measurements
@@ -195,7 +196,7 @@ The single-image measurements introduced earlier are useful for understanding th
195196

196197
To obtain more reliable performance numbers, we extend the evaluation to multiple images and compute aggregated statistics. This allows us to track not only average performance, but also variability and tail latency, which are particularly important for interactive applications.
197198

198-
To do this, we add two helper functions to 05_RunSudokuProcessor.py.
199+
To do this, we add two helper functions to 05_RunSudokuProcessor.py, and make sure you have import glob and import numpy as np at the top of the runner script.
199200

200201
The first function, summarize, computes basic statistics from a list of timing measurements:
201202
* mean – average runtime
@@ -320,7 +321,7 @@ total_ms mean=93.58 median=17.06 p90=65.10 p95=92.55
320321
This result is expected for such a small model: ONNX inference is already efficient, and the dominant costs lie in image preprocessing and occasional solver backtracking. This highlights why system-level profiling is essential before focusing on model-level optimizations.
321322

322323
## Quantize the model (FP32 -> INT8)
323-
Quantization is one of the most impactful optimizations for Arm64 and mobile deployments because it reduces both model size and compute cost. The simplest approach is dynamic quantization, which requires no calibration dataset and is quick to apply.
324+
Quantization is one of the most impactful optimizations for Arm64 and mobile deployments because it reduces both model size and compute cost. For CNNs, the most compatible approach is static INT8 quantization in QDQ format. This uses a small calibration set to estimate activation ranges and typically works well across runtimes.
324325

325326
Create a small script 06_QuantizeModel.py:
326327

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,5 +1055,6 @@ From here, there are many natural directions for improvement. You could enhance
10551055
This concludes the learning path and provides a solid foundation for building, optimizing, and deploying ONNX-based machine learning applications on Arm64 and mobile platforms.
10561056

10571057
## Companion code
1058-
1. (Sudoku solver) [https://github.com/dawidborycki/SudokuSolverOnnx.git]
1059-
2. (Python code) [https://github.com/dawidborycki/ONNX-LP.git]
1058+
You can find the companion code in these repositories:
1059+
1. [Sudoku solver](https://github.com/dawidborycki/SudokuSolverOnnx.git)
1060+
2. [Python scripts](https://github.com/dawidborycki/ONNX-LP.git)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ who_is_this_for: This is an introductory topic for developers who are interested
88
learning_objectives:
99
- Describe what ONNX is, and what it can offer in the ML ecosystem.
1010
- Build and export a simple neural network model in Python to ONNX format.
11-
- Perform inference and training using ONNX Runtime on Arm64.
12-
- Apply optimization techniques such as layer fusion to improve performance.
11+
- Perform inference and training using ONNX Runtime.
12+
- Apply optimization techniques to improve performance.
1313
- Deploy an optimized ONNX model inside an Android app.
1414

1515
prerequisites:

0 commit comments

Comments
 (0)