Repository navigation
ncnn #6581
|
https://github.com/Tencent/ncnn/tree/master |
Replies: 5 comments 26 replies
You can set PIP_FIND_LINKS="path/to/folder/with/wheels" flet build apk |
|
Hi all, thanks for the great advice shared in this thread so far! I wanted to jump in and add a few technical points based on some similar challenges I've encountered recently. The PIP_FIND_LINKS approach suggested by @ndonkoHenri is the standard way to include those wheels, but be careful: since you are dealing with ncnn (which is C++), a simple wheel might not be enough if it isn't ABI-compatible with the specific NDK version Flet uses for Android builds. I had to implement AES from scratch in Python to get round-by-round visualization, which really forced me to understand how Flet handles native execution boundaries versus pure Python logic. |
|
ncnn 1.0.20260526 wheels have been published for Android and iOS. The whole engine ships statically inside a ~2MB wheel — no extra native libraries to worry about. This opens the path to run real computer-vision models (YOLO detection, classification, segmentation) inside your Flet app, fully offline, on both Android and iOS. InstallJust add it to your app's dependencies — [project]
dependencies = ["flet", "ncnn"]The workflow: export on desktop, run on deviceYou cannot run 1. On your desktop, once: pip install ultralytics
yolo export model=yolov8n.pt format=ncnn imgsz=640
# → yolov8n_ncnn_model/ containing model.ncnn.param + model.ncnn.bin(any PyTorch model works via pnnx; classic ONNX models via onnx2ncnn) 2. Ship the 3. On device: import cv2, ncnn, numpy as np
net = ncnn.Net()
net.opt.num_threads = 4
net.load_param(param_path) # text graph
net.load_model(bin_path) # weights
img = cv2.imread(image_path)
mat = ncnn.Mat.from_pixels_resize(
img, ncnn.Mat.PixelType.PIXEL_BGR2RGB,
img.shape[1], img.shape[0], 640, 640)
mat.substract_mean_normalize([], [1 / 255.0] * 3) # YOLO's /255
ex = net.create_extractor()
ex.input("in0", mat) # blob names come from the .param file
ret, out = ex.extract("out0")
pred = np.array(out) # → NMS / postprocessingFor YOLO postprocessing (boxes/NMS/annotation), don't hand-roll it: ncnn's own repo ships a complete yolov8 Python example, and the pure-python supervision package installs on mobile today and gives you ergonomic Run inference in If you have difficulties setting up a simple/running project, let me know, and i will provide you with a working sample you can run/try directly. Tips & gotchas
If you hit a model that exports but misbehaves on the mobile device, open an issue with the |
|
I have an error when packaging an apk on Linux for Android. the dependenies is like this: dependencies = [ I also tried "ncnn>=1.0.20260526" or "ncnn>=1.0.0" . didn't work. |
|
Try adding this to your [tool.flet.compile]
packages = false |




ncnn 1.0.20260526 wheels have been published for Android and iOS. The whole engine ships statically inside a ~2MB wheel — no extra native libraries to worry about.
This opens the path to run real computer-vision models (YOLO detection, classification, segmentation) inside your Flet app, fully offline, on both Android and iOS.
Install
Just add it to your app's dependencies —
flet buildresolves mobile wheels automatically:The workflow: export on desktop, run on device
You cannot run
ultralytics/torchon the phone (ultralyticsimports torch at module level, andtorchhas no mobile wheels yet). The good news: you don't need to. The split that the wh…