Instructions to use litert-community/YOLACT-ResNet50-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/YOLACT-ResNet50-LiteRT with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: litert
|
| 4 |
+
pipeline_tag: image-segmentation
|
| 5 |
+
tags:
|
| 6 |
+
- litert
|
| 7 |
+
- tflite
|
| 8 |
+
- android
|
| 9 |
+
- on-device
|
| 10 |
+
- gpu
|
| 11 |
+
- instance-segmentation
|
| 12 |
+
- yolact
|
| 13 |
+
- coco
|
| 14 |
+
- real-time
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# YOLACT-ResNet50 — LiteRT (real-time instance segmentation, GPU)
|
| 18 |
+
|
| 19 |
+
On-device **real-time instance segmentation** running **fully on the LiteRT
|
| 20 |
+
`CompiledModel` GPU** delegate (no CPU fallback). [YOLACT](https://arxiv.org/abs/1904.02689)
|
| 21 |
+
(ICCV 2019) predicts per-instance COCO masks. The network (ResNet50 + FPN +
|
| 22 |
+
protonet + heads) runs on the GPU; the lightweight decode (NMS + linear-combination
|
| 23 |
+
masks) runs host-side. ~41 ms/graph on a Pixel 8a.
|
| 24 |
+
|
| 25 |
+
- **Architecture:** YOLACT-ResNet50 (base, no deformable conv) — pure CNN.
|
| 26 |
+
- **Weights:** [dbolya/yolact](https://github.com/dbolya/yolact) (`yolact_resnet50_54_800000`) · MIT.
|
| 27 |
+
- **Size:** 125 MB.
|
| 28 |
+
|
| 29 |
+

|
| 30 |
+
|
| 31 |
+
## Files
|
| 32 |
+
|
| 33 |
+
- `yolact.tflite` — the GPU graph (input `[1,3,550,550]` NCHW).
|
| 34 |
+
- `priors.bin` — 19248 SSD priors `[cx,cy,w,h]` (float32) used by the host-side box decode.
|
| 35 |
+
|
| 36 |
+
## I/O
|
| 37 |
+
|
| 38 |
+
- **Input:** `[1, 3, 550, 550]` NCHW, **BGR**, normalized `(x - [103.94,116.78,123.68]) / [57.38,57.12,58.40]`
|
| 39 |
+
(no /255).
|
| 40 |
+
- **Raw outputs:** `loc [1,19248,4]`, `conf [1,19248,81]` (softmax, incl. background),
|
| 41 |
+
`mask [1,19248,32]` (coefficients), `proto [1,138,138,32]` (prototype masks).
|
| 42 |
+
|
| 43 |
+
## Host-side decode
|
| 44 |
+
|
| 45 |
+
1. **Boxes:** SSD `decode(loc, priors, variances=[0.1,0.2])`.
|
| 46 |
+
2. **NMS:** per-class, score-threshold ~0.3, IoU 0.5, top-k.
|
| 47 |
+
3. **Masks (lincomb):** for each kept detection, `mask = sigmoid(proto @ coeff)` → crop
|
| 48 |
+
to the box → threshold 0.5 → upscale.
|
| 49 |
+
|
| 50 |
+
## GPU conversion
|
| 51 |
+
|
| 52 |
+
Base YOLACT is a pure CNN, so the graph converts fully GPU-compatible (**138/138
|
| 53 |
+
nodes on the delegate, 1 partition**; device corr 0.99999–1.0 vs PyTorch on all four
|
| 54 |
+
raw outputs) with **one patch**: the ResNet50 stem `MaxPool2d(padding=1)` lowers to a
|
| 55 |
+
`-inf` PADV2 (rejected by Mali), replaced by a 0-pad + unpadded maxpool (exact
|
| 56 |
+
post-ReLU). The scripted FPN is made traceable by disabling YOLACT's JIT
|
| 57 |
+
(`use_jit=False`). CPU-exact vs PyTorch (corr 1.0).
|
| 58 |
+
|
| 59 |
+
## Minimal usage (Python, LiteRT / ai-edge-litert)
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
import numpy as np
|
| 63 |
+
from ai_edge_litert.interpreter import Interpreter
|
| 64 |
+
|
| 65 |
+
it = Interpreter(model_path="yolact.tflite"); it.allocate_tensors()
|
| 66 |
+
inp, out = it.get_input_details(), it.get_output_details()
|
| 67 |
+
it.set_tensor(inp[0]["index"], x) # [1,3,550,550] BGR, normalized (see above)
|
| 68 |
+
it.invoke()
|
| 69 |
+
outs = {tuple(o["shape"][1:]): it.get_tensor(o["index"])[0] for o in out}
|
| 70 |
+
loc = outs[(19248, 4)]; conf = outs[(19248, 81)]
|
| 71 |
+
mask = outs[(19248, 32)]; proto = outs[(138, 138, 32)]
|
| 72 |
+
|
| 73 |
+
priors = np.fromfile("priors.bin", np.float32).reshape(-1, 4)
|
| 74 |
+
cxy = priors[:, :2] + loc[:, :2] * 0.1 * priors[:, 2:]
|
| 75 |
+
wh = priors[:, 2:] * np.exp(loc[:, 2:] * 0.2)
|
| 76 |
+
boxes = np.concatenate([cxy - wh / 2, cxy + wh / 2], 1) # x1y1x2y2 (0..1)
|
| 77 |
+
# then per-class NMS on conf, and mask_i = sigmoid(proto @ mask[i]) cropped to boxes[i]
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
A full Android decode is in the sample app (`YolactSegmenter.kt`).
|
| 81 |
+
|
| 82 |
+
## License
|
| 83 |
+
|
| 84 |
+
MIT (YOLACT / dbolya/yolact). COCO class taxonomy.
|