Exporting with a fixed input size and then discovering the model refuses any image at a different resolution.
AI and on-device processing
ONNX
Also called open neural network exchange, .onnx or onnx runtime. Here is what it means, when it changes what you export, and what people get wrong.
The short answer
ONNX (Open Neural Network Exchange) is an open format for saving a trained model so a different framework or runtime can load it. The file holds the computation graph, the operators it uses and the learned weights, which lets a model trained in one toolkit run somewhere else entirely.
Updated
The short version
ONNX at a glance
| Quick fact | Detail |
|---|---|
| Stands for | Open Neural Network Exchange |
| File extension | .onnx |
| Encoding | Protocol buffers |
| Contains | Graph, operators, weights, metadata |
| Compatibility marker | Opset version |
| Web backends | WebAssembly and WebGPU |
Slide the table sideways to see every column.
What is inside an .onnx file?
A single file, encoded as protocol buffers, containing four things worth knowing about.
- A graph of nodes and the tensors flowing between them, describing the order of operations from input to output.
- Operators at each node, drawn from a standard set with defined semantics, so a convolution means the same thing to every runtime.
- Initialisers, which are the trained weights, and usually the bulk of the file size.
- Metadata, including input and output tensor names, shapes and data types, and an
opsetversion that pins which revision of the operator set the graph relies on.
That last item causes more real problems than the rest combined, because a runtime that predates the opset a model was exported with will refuse to load it.
Why does it matter for shipping models to browsers?
Models are trained in Python, on large frameworks, on machines with plenty of memory. None of that exists in a browser tab. ONNX breaks the dependency: you export once from whatever you trained in, and any runtime that understands the format can execute it, including runtimes compiled to WebAssembly or backed by WebGPU.
The practical effect is that the training stack and the delivery stack stop being the same decision. A segmentation or matting model can be developed with the usual research tooling, exported, quantised, and then run on a phone, a laptop and a server from one artefact, rather than being reimplemented for each target.
What tends to go wrong on export?
Three failures account for most of them. Unsupported operators: the model uses something the target runtime or backend does not implement, so it either fails to load or silently falls back to a slower path. Dynamic shapes: the graph was exported expecting a fixed input size, and then you feed it a different resolution. Exporting with dynamic axes declared avoids a lot of pain.
The subtlest is preprocessing mismatch. Whether the model expects pixel values scaled to a particular range, in a particular channel order, with a particular normalisation, is a convention that often lives in the training code rather than in the file. Get it wrong and nothing errors, you just receive a plausible-looking mask that is quietly incorrect.
What people get wrong about onnx
Each one is a real failure mode, not a style preference.
Ignoring the opset version, so a model loads on a development machine and fails in the runtime you ship.
Reimplementing preprocessing by hand in the target application and getting the value range or channel order subtly wrong.
Assuming a model that exports without warnings is numerically identical, rather than comparing outputs against the original.
Questions people ask
ONNX, answered
The follow-up questions people search for once they have the definition.
Is ONNX a model, a runtime, or a file format?
The format, primarily: a specification for how to serialise a computation graph and its weights. Several separate runtimes can load and execute that format, and people often use the name loosely for the whole ecosystem, but the standard itself is the interchange format.
Does converting to ONNX change the model's accuracy?
It should not, since the graph and weights are preserved. In practice small numeric differences appear because operators are implemented differently across backends, and larger ones appear if the export simplified something. Always compare outputs on a test set before and after conversion.
Can I quantise an ONNX model after exporting it?
Yes. Post-training quantisation operates on the exported file and rewrites the weights at lower precision, optionally using a small calibration set. This is the usual way a model gets shrunk for browser delivery, since it needs no access to the original training pipeline.
Why is my ONNX model slower in the browser than expected?
Usually one unsupported operator forcing part of the graph onto a slower fallback path, or the model running on the CPU because the GPU backend was unavailable. Profiling which nodes ran on which backend is the fastest way to find it.
Same cluster
More from the glossary
Neighbouring entries, so every term in the set is one hop from every other.
Orientation tag
The orientation tag is an EXIF value from 1 to 8 that tells software how to rotate or flip a photo for display.
Passport photo spec
A passport photo spec is the set of rules a government publishes for identity photographs: print size, how much of the frame the head occupies, background, expression and recency.
Nearest-neighbour interpolation
Nearest-neighbour interpolation sets each new pixel to the value of the closest pixel in the original, with no blending at all.
From the studio
Tools that do this
Each one runs on your own device, so the photo stays where it is.
Sources
Where the facts on this page come from. Every link opens the specification, standard or documentation the claim was read at.
Keep reading
Elsewhere on Photomop
Platform image rules
Image size, file type and background rules for 22 selling platforms, each one sourced.
Read itConvert image
JPG, PNG, WebP and AVIF, with an honest answer about HEIC and alpha.
Read itAll the tools
The whole toolbox in three families, with what each one needs before it can run.
Read itOn-device privacy
The pipeline in five steps, what leaves your device, and how to check it yourself.
Read it
Now do it to a photo
Photomop is a photo studio that runs on your own device. Resize, crop, compress, convert, batch edit, remove a background and change one all work in the browser tab you are reading this in, at full resolution and with no watermark. The on-device page shows you how to check that the photo stays put.