Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / photos / src / main / assets / README.md

README.md4.2 KiBRenderedCodeRaw
1# `:photos` bundled model assets
2
3## `u2netp.maml` — salient-object detection
4
5Apache-2.0, from https://huggingface.co/BritishWerewolf/U-2-Netp
6@ `7112208dbac3a3642496c8d54e2f0f9bb3dc1dc8` (`onnx/model.onnx`, 4,574,861 B fp32,
7SHA-256 `309c8469…4c76f4ddd8`) — U²-Net *portable*, the small variant of the
8salient-object detector.
9
10Not the ONNX itself: `scripts/ml/fetch_and_convert.sh` converts it to the fp16
11`.maml` weights container that `:library:ml` reads. The source ONNX SHA-256 is in
12the `.maml` header, so a shipped asset traces back to this line.
13
14Run at 320×320 RGB, ImageNet mean/std, output a 320×320 saliency map through a
15sigmoid. Consumed by `SubjectSegmenter` from `MlSegmentation.kt` for
16auto-select-subject.
17
18This replaces `u2netp.ncnn.{param,bin}`, which was added in `72dde80df` with no
19upstream URL or license. Its op inventory (Convolution 119, Pooling 33, Interp 38)
20matches this ONNX exactly (Conv 119, MaxPool 33, Resize 38), so it is the same
21network re-sourced from a licensed export rather than a different model. The
22upstream export is dynamic-shape; we keep the straight resize to 320×320 that the
23ncnn path already used, **not** the HuggingFace processor's `keep_aspect_ratio`
24letterbox, which would change existing behaviour.
25
26## The face models
27
28`scrfd_500m.maml` (face detection) and `w600k_mbf.maml` (face embedding) are
29InsightFace's **buffalo_s** pack, from
30https://huggingface.co/immich-app/buffalo_s @ `0ff1751885575e62e084dff70549ce24a11fa5dc`:
31
32| asset | source ONNX | SHA-256 |
33|---|---|---|
34| `scrfd_500m.maml` | `detection/model.onnx`, 2,524,817 B | `5e4447f5…d8b4ea3a` |
35| `w600k_mbf.maml` | `recognition/model.onnx`, 13,616,099 B | `9cc6e4a7…b319eb4f` |
36
37**Licence: InsightFace's own, which permits non-commercial research use only** —
38https://github.com/deepinsight/insightface/tree/master/python-package#license. This is
39*not* Apache-2.0 like the two models above, and it is the one licence constraint among
40the bundled weights. These are the same weights the repo already shipped as
41`scrfd_500m_kps-opt2.{param,bin}` and `w600k_mbf.ncnn.{param,bin}`, which arrived with
42no upstream URL and no licence recorded at all; re-sourcing them from a licensed ONNX
43export makes the constraint visible rather than introducing it.
44
45SCRFD runs at 640 on the long side with the short side padded to a multiple of 32, so
46its `.maml` is the only one whose graph is dynamically shaped. MobileFaceNet runs at a
47fixed 112×112 and returns a 512-d embedding.
48
49Two nodes are rewritten during conversion rather than needing a shader — see
50`scripts/ml/maml_convert.py`: MobileFaceNet's final `Gemm` becomes a `[512, 64, 7, 7]`
51convolution kernel, and the `BatchNormalization` after it is folded into that layer's
52weight and bias.
53
54The ncnn `.param`/`.bin` files these replace (`scrfd_500m_kps-opt2.*`,
55`w600k_mbf.ncnn.*`, 7.9 MB together) are gone. `libncnn_android.so` is still in this
56APK, but only because `:library:ocr` pulls it in for PP-OCRv5 text recognition — nothing
57in `:photos` itself uses ncnn any more.
58
59## `clip/`
60
61TinyCLIP-ViT-8M/16 Text-3M, read by `ClipEmbedder` through `:library:ml`. It has a README
62of its own — `clip/README.md` — because it is the one asset here whose provenance had to be
63written from scratch: until `scripts/ml/fetch_tinyclip.py` existed it was the only bundled
64model in the tree with no pinned upstream SHA-256 and no fetch recipe. Rebuild it with that
65script rather than with `fetch_and_convert.sh`.
66
67`model_int8.onnx` and the `onnxruntime-reduced-android` AAR that ran it are both gone, which
68is 10,466,856 bytes of arm64 native code out of this APK. `libmodelrunner.so` was already here
69for the four models above, and there is now no third-party inference runtime in `:photos` at all.
70
71## Keeping these current
72
73Update: `./scripts/ml/fetch_and_convert.sh --update`, which reports the moved
74SHA-256 to re-pin. If the ordered layer table changed too, the converter says so
75and the hardcoded forward pass in
76`library/ml/src/main/rust/src/nets/u2netp.rs` has to be updated with it.
77
78This file is inside `assets/`, so it is packaged into the APK. That is deliberate
79rather than overlooked: it is ~1 KB, and Apache-2.0 §4 asks that attribution
80notices travel with the distributed work, which here is the weights next to it.