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