Repository navigation
onnxruntime #5225
|
I tried to install onnxruntime but its not resolved, So i wanted to be clear either.
|
Replies: 4 comments 2 replies
|
At my last look at Onnx on embedded devices/Android/iOS, you needed to compile binaries from source(ie. they haven't got arm64-v8a binaries). I would build that wheel (C++), create the Python bindings, and then have it contained within your package. I think the key question from a Flet POV would be whether you could place something like this within your reqs.txt / .toml requirements when working on an Android build: I would guess that you can - as you can on MacOS/Windows, and I use custom wheels/binaries. But I haven't done Flet -> Android. Answering your question, I think the most relevant link to start this journey is this: |
|
I tested it today, https://github.com/SamYuan1990/i18n-agent-action/actions/runs/17670451604/job/50220801655?pr=104 related with microsoft/onnxruntime#26025 I am not sure if onnx runtime can provide a package. |
|
well, for me I am attempting sherpa_onnx for STT(sound to text). hope it help, https://github.com/SamYuan1990/flet_sherpa_onnx |
|
It's a CPU-only build — the CPU execution provider (MLAS, NEON-optimized). The NNAPI (Android) and CoreML (iOS) accelerator backends are off in this first release, which keeps Android and iOS running the exact same dependable baseline. Everything runs offline; the only network you need is a one-time model download. InstallAdd it to your deps: # pyproject.toml
dependencies = [
"flet",
"onnxruntime",
"numpy",
]Note this is 64-bit only ( [tool.flet.android]
target_arch = ["arm64-v8a", "x86_64"]
# or
flet build apk --arch arm64-v8a x86_64Storage & the model file (the important bit)
import os, urllib.request
data_dir = os.getenv("FLET_APP_STORAGE_DATA")
model_path = os.path.join(data_dir, "model.onnx")
if not os.path.exists(model_path):
urllib.request.urlretrieve("https://<your-host>/model.onnx", model_path)A genuinely small model (a few hundred KB) could be shipped with the app (for example, by storing it in the Exampleimport os
import numpy as np
import onnxruntime as ort
model_path = os.path.join(os.getenv("FLET_APP_STORAGE_DATA"), "model.onnx")
# Set intra_op_num_threads to your device's performance-core count (often 4)
# rather than leaving it unbounded — that's where mobile latency comes from.
opts = ort.SessionOptions()
opts.intra_op_num_threads = 4
sess = ort.InferenceSession(model_path, opts, providers=["CPUExecutionProvider"])
inp = sess.get_inputs()[0].name
x = np.asarray(data, dtype=np.float32) # shape/dtype your model expects
(out,) = sess.run(None, {inp: x})Run it off the UI threadLoading a session and running inference are CPU-bound and can take a moment — do them in Notes for good results on mobile
Let me know if you face any issues! |
onnxruntime1.27.0 is now supported on Android and iOS: https://pypi.flet.dev/onnxruntimeIt's a CPU-only build — the CPU execution provider (MLAS, NEON-optimized). The NNAPI (Android) and CoreML (iOS) accelerator backends are off in this first release, which keeps Android and iOS running the exact same dependable baseline. Everything runs offline; the only network you need is a one-time model download.
Install
Add it to your deps:
Note this is 64-bit only (
arm64-v8a/x86_64) — wheels forarmeabi-v7aarch/devices aren't built (at least, for now). To prevent your Android builds from failing, you will have to e…