Despliega 1000+ apps y plantillas en un clic
Recetas listas para Wasmer.
Recetas listas para Wasmer.
Upload an image and get the top-5 ImageNet labels from a MobileNetV2 model on ONNX Runtime, with a JSON API.

Upload a photo, or pick a bundled sample, and get the five most likely ImageNet labels with their confidences. The same classifier is available as a JSON API. Inference runs on the server with ONNX Runtime and a bundled MobileNetV2 model, so no GPU, API key or outbound network call is needed.
Live demo: https://onnx-image-classifier-template.wasmer.app
Click Try the cat or Try the coffee to classify a sample, or drop in your own image. From a terminal:
curl -F image=@photo.jpg https://onnx-image-classifier-template.wasmer.app/api/classify
{"model": "mobilenetv2-12", "predictions": [{"label": "Egyptian cat", "confidence": 0.7103}, ...]}
Uploads that are not images return HTTP 400; uploads over 10 MB or images over 25 megapixels return HTTP 413. Errors carry an error field.
main.py is a small Flask app. It loads the model once at startup with onnxruntime.InferenceSession, serves the page from static/, and handles POST /api/classify (multipart field image).static/index.html is built from the shared Wasmer starter components. static/wasmer-starter-ui.js is a generated copy of _shared/starter-ui/wasmer-starter-ui.js; refresh it from the repository root with node scripts/sync-starter-ui.mjs python-onnx-image-classifier/static/wasmer-starter-ui.js instead of editing it.imagenet_preprocess.py using Pillow and numpy only: resize the short side to 256, center-crop 224×224, scale to [0, 1], normalize with the ImageNet mean and standard deviation, and reorder to NCHW. The resize and crop run as one Image.resize(..., box=...) on the central square, and JPEGs are decoded at reduced size with Image.draft, so very large or extremely narrow images never create a large intermediate. A softmax over the 1,000 outputs gives the confidences.model/mobilenetv2-12.onnx (13.3 MB) and model/synset.txt (ImageNet labels) are bundled, so the app starts without downloading anything. Tunable values (input size, top-k, upload and pixel limits) live in one constants block at the top of main.py.requirements.txt is installed for the wasix_wasm32 platform, which provides WASIX builds of numpy, Pillow and onnxruntime. onnxruntime~=1.27.0 resolves to 1.27.1 on WASIX and 1.27.0 on PyPI. ONNX Runtime prints a harmless Unsupported platform (wasi) warning at startup.Anybuild selects Python 3.13 and the python main.py start command. The repository-root Anybuild.python-onnx-image-classifier provides the same configuration when building this monorepo with --subdir python-onnx-image-classifier.Nothing is stored: uploads are classified in memory and discarded.
Use Python 3.13:
cd python-onnx-image-classifier
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt pytest
PORT=8080 .venv/bin/python main.py
Open http://localhost:8080/. Run the tests with .venv/bin/python -m pytest.
To run the same code under Wasmer's Python, install the WASIX wheels into ./pkgs and mount them:
uvx pip install -r requirements.txt --index-url https://python-registry.wasmer.app/all/simple/ \
--extra-index-url https://pypi.org/simple --platform wasix_wasm32 --python-version 3.13 \
--only-binary=:all: --target ./pkgs
wasmer run python/python@=3.13.20 --volume ./pkgs:/packages --volume .:/app \
--env PYTHONPATH=/packages --env PORT=8080 --net -- /app/main.py
https://github.com/wasmerio/examples in Wasmer and set the root directory to python-onnx-image-classifier, or upload the contents of this directory as a folder.python main.py. No database, secrets or volumes are needed.With the Wasmer CLI, from this directory:
wasmer deploy --build-remote
To swap in another ImageNet classifier from the ONNX model zoo, replace the .onnx file and update MODEL_PATH. Models with different input sizes or normalization need the matching constants changed.
model/mobilenetv2-12.onnx and model/synset.txt: ONNX model zoo, MobileNet v2-1.0 fp32, Apache License 2.0. SHA-256 of the model: c0c3f76d93fa3fd6580652a45618618a220fced18babf65774ed169de0432ad5.static/samples/cat.jpg ("chelsea", photo by Stefan van der Walt) and static/samples/coffee.jpg (photo by Rachel Michetti): from scikit-image's sample data, released under CC0. Converted from PNG to JPEG.