File size: 2,774 Bytes
fd67b9a
 
 
 
 
 
 
 
 
 
5d9e51d
fd67b9a
 
 
 
 
 
7f0b00f
 
 
 
5d9e51d
7f0b00f
 
 
5d9e51d
 
 
 
4c6a6d0
 
 
 
 
7f0b00f
 
 
fd67b9a
5d9e51d
88903a0
310226f
88903a0
7f0b00f
 
 
 
fd67b9a
 
 
7f0b00f
fd67b9a
7f0b00f
fd67b9a
 
 
5d9e51d
73931b3
35ce9df
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
license: apache-2.0
tags:
- executorch
- xnnpack
- pte
- on-device
- image-segmentation
- portrait-matting
---
# modnet_portrait_matting — ExecuTorch

- **Source**: ZHKKKe/MODNet + DavG25/modnet-pretrained-models ckpt
- **License**: Apache-2.0
- **Input**: [[1, 3, 512, 512]] — RGB [-1,1], 512x512
- **Output**: alpha matte [1,1,512,512] 0-1

## Variants

All variants take and return fp32 tensors — swap the `.pte` file, keep your app code.

| build | file | size (MB) | parity vs fp32 eager (worst corr) | Mac median (ms)* |
|-----------|------|-----------|------------------------------------|------------------|
| fp32 | `modnet_portrait_matting_xnnpack_fp32.pte` | 26.1 | 1.000000 | 64.9 |
| fp16 | `modnet_portrait_matting_xnnpack_fp16.pte` | 24.4 | 1.000000 | 107.8 |
| Core ML (fp16, iOS) | `modnet_portrait_matting_coreml_all.pte` | 13.8 | 0.999997 | 6.8 |


The Core ML build is the same graph lowered to Apple's Neural Engine instead of
XNNPACK, which is CPU-only. Measured on an iPhone 17 Pro across seven models, it
runs **3.5x to 13.9x faster (median 12x)** at roughly half the file size — for
example Depth-Anything-V2-Small at 500.8 ms against 42.7 ms, and MODNet at 81.7 ms
against 5.9 ms. It computes in fp16 and is iOS-only; the XNNPACK files stay the
portable option and are what runs on Android.

\*Mac arm64, single process, median of 10 — a reference point for relative cost
only, not a device number (torch eager fp32 on the same machine: 120.1 ms).

### Builds that did not earn a slot

- **int8 is not shipped**: measured in the units that matter for this model — mask IoU at 0.5: median 0.9864 over 10 real images, worst 0.5970.

## Verification (executorch 1.4.0, torch 2.13.0)

Parity is measured against the fp32 eager model on real image input; `corr` is
the correlation over all elements of each output tensor.

| output | shape | max_abs_diff | corr |
|--------|-------|--------------|------|
| 0 | [1, 1, 512, 512] | 1.476e-04 | 1.000000 |

XNNPACK delegate coverage (fp32): 94.7% (302/319 ops); ops left on the portable kernels: `aten._native_batch_norm_legit.no_stats` x16, `aten.expand_copy.default` x1

## Conversion

torch.export -> to_edge_transform_and_lower(partitioner) -> .pte
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))

<!-- funnel:v1 -->

---

**More models in this format:** [ExecuTorch Model Zoo](https://huggingface.co/collections/mlboydaisuke/executorch-model-zoo-6a7ff328390b63075ffeae5e) — 31 models, each with the recipe that produced it.

**Want a different model on-device?** [Open a request](https://github.com/john-rocky/on-device-requests) — free, open weights only; the export and its measured numbers get published publicly.

<!-- /funnel:v1 -->