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

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

README.md3.2 KiBRenderedCodeRaw
1# `:camera` bundled model assets
2
3## `selfie_segmentation.maml`
4
5Apache-2.0, from https://huggingface.co/onnx-community/mediapipe_selfie_segmentation
6@ `be49485c8e027524be38591817fc5cd31bd9d00e` (`onnx/model.onnx`, 462,352 B fp32,
7SHA-256 `3241ac4a…4531aad`) — an ONNX export of Google's MediaPipe Selfie
8Segmentation, the model purpose-built for exactly this job.
9
10Not the ONNX itself: `scripts/ml/fetch_and_convert.sh` converts it to the fp16
11`.maml` weights container that `:library:ml` reads, which is half the size and the
12only form anything here loads. The source ONNX SHA-256 is in the `.maml` header, so
13a shipped asset traces back to this line without needing the ONNX on disk.
14
15Run at 256×256 RGB, rescale 1/255 and **no** mean/std (`do_normalize: false`
16upstream), output a single 256×256 alpha channel through a sigmoid. Consumed by
17`SelfieSegmenter` from `BokehAnalyzer` and `PortraitBokeh.StillBokehRenderer`.
18
19This replaces `erdnet.{param,bin}`, which was added in `72dde80df` with no upstream
20URL, license or conversion recipe. It was Caffe-derived from nihui's ncnn demo
21family, had no obtainable ONNX, and so could not be attributed or rebuilt — see
22`SUPPLY_CHAIN_RISKS.md`. The masks differ from erdnet's; this is a different model,
23not a port.
24
25Update: `./scripts/ml/fetch_and_convert.sh --update`, which reports the moved
26SHA-256 to re-pin. If the ordered layer table changed too, the converter says so
27and the hardcoded forward pass in
28`library/ml/src/main/rust/src/nets/selfie.rs` has to be updated with it.
29
30This file is inside `assets/`, so it is packaged into the APK. That is deliberate
31rather than overlooked: it is ~1 KB, and Apache-2.0 §4 asks that attribution
32notices travel with the distributed work, which here is the weights next to it.
33
34## `modnet.maml`
35
36Apache-2.0, from the official MODNet repository https://github.com/ZHKKKe/MODNet
37(MobileNetV2 backbone, `modnet_photographic_portrait_matting` weights), via the
38mirror https://huggingface.co/DavG25/modnet-pretrained-models
39(`models/modnet_photographic_portrait_matting.onnx`, 25,888,640 B fp32,
40SHA-256 `07c308cf…84df9`) — MODNet portrait matting, the model purpose-built
41for trimap-free portrait alpha with hair detail.
42
43Not the ONNX itself: `scripts/ml/modnet_fold.py` folds the export's Slice-fed
44batch norms into their convolutions and rewrites the SE block's MatMuls as 1x1
45convolutions, then converts to the fp16 `.maml` weights container that
46`:library:ml` reads. The source ONNX SHA-256 is in the `.maml` header, so
47a shipped asset traces back to this line without needing the ONNX on disk.
48
49Run at 512×512 RGB, `(value / 255 - 0.5) / 0.5` (the demo's
50`ToTensor` + `Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))`), output a single
51512×512 alpha channel through a sigmoid. Consumed by `ModnetSegmenter` from
52`PortraitBokeh.StillBokehRenderer` — still capture only; the 15 fps preview
53keeps `selfie_segmentation.maml` above.
54
55Update: re-download the mirror file, verify the SHA-256, then
56`./scripts/ml/modnet_fold.py model.onnx --graph modnet -o
57camera/src/main/assets/modnet.maml`, which reports a moved digest to re-pin.
58If the ordered layer table changed too, the converter says so
59and the hardcoded forward pass in
60`library/ml/src/main/rust/src/nets/modnet.rs` has to be updated with it.