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