Image-to-Image
LiteRT
LiteRT
LiteRT
on-device
android
gpu
style-transfer
neural-style
fast-neural-style
Instructions to use litert-community/Fast-Neural-Style-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/Fast-Neural-Style-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
Fast Neural Style 4 styles LiteRT fp16 (fully-GPU, Pixel 8a corr 0.9999, 9ms)
Browse files- .gitattributes +1 -0
- README.md +51 -0
- samples/sample.png +3 -0
- style_candy_fp16.tflite +3 -0
- style_mosaic_fp16.tflite +3 -0
- style_rain_princess_fp16.tflite +3 -0
- style_udnie_fp16.tflite +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
samples/sample.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: bsd-3-clause
|
| 3 |
+
library_name: LiteRT
|
| 4 |
+
pipeline_tag: image-to-image
|
| 5 |
+
tags: [litert, tflite, on-device, android, gpu, style-transfer, neural-style, fast-neural-style]
|
| 6 |
+
base_model: pytorch/examples
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# Fast Neural Style Transfer β LiteRT (on-device, fully-GPU, 4 styles)
|
| 10 |
+
|
| 11 |
+
Fast neural **style transfer** ([PyTorch examples](https://github.com/pytorch/examples/tree/main/fast_neural_style)
|
| 12 |
+
`TransformerNet`, Johnson et al.), converted to **LiteRT** and running **fully on the `CompiledModel` GPU**
|
| 13 |
+
(ML Drift) on Android. Applies an artistic style to a photo β **4 styles** (candy / mosaic / rain_princess /
|
| 14 |
+
udnie), each a **3.5 MB** fp16 graph.
|
| 15 |
+
|
| 16 |
+

|
| 17 |
+
|
| 18 |
+
## On-device (Pixel 8a, Tensor G3 β verified)
|
| 19 |
+
|
| 20 |
+
| | |
|
| 21 |
+
|---|---|
|
| 22 |
+
| nodes on GPU | **350 / 350** LITERT_CL (full residency) |
|
| 23 |
+
| inference | **~9 ms** (256Γ256) |
|
| 24 |
+
| size | 3.5 MB per style (fp16) |
|
| 25 |
+
| accuracy | device-vs-PyTorch corr **0.9998β0.9999** (all 4 styles) |
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
image[1,3,256,256] (RGB 0-255) β[GPU: TransformerNet]β stylized[1,3,256,256] (RGB 0-255)
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
## How it converts (litert-torch) β three numerically-exact re-authorings
|
| 32 |
+
|
| 33 |
+
1. **`ReflectionPad2d` β zero-pad** (`GATHER_ND` β `PAD`; border-only difference).
|
| 34 |
+
2. **Large conv activations β conv-weight scaling.** The conv outputs reach β |5000|, where the Mali delegate's
|
| 35 |
+
fp16 conv accumulation loses precision β garbage (device corr 0.34 at full residency β *residency β
|
| 36 |
+
correctness*). Each conv is followed by an `InstanceNorm` (which is **scale-invariant**), so scaling those
|
| 37 |
+
conv weights down so the output is β |10| is **exact** (IN output unchanged) and keeps the fp16 accumulation
|
| 38 |
+
precise β corr 1.0.
|
| 39 |
+
3. **`InstanceNorm` β SafeInstanceNorm** (down-scaled-domain spatial reduction, fp16-safe; SafeLayerNorm class).
|
| 40 |
+
|
| 41 |
+
Upsample is `interpolate(nearest)` (no transposed conv β no ZeroStuff). Result: banned ops NONE, β€4D,
|
| 42 |
+
tflite-vs-torch corr **1.0**, device-vs-torch corr **0.9999**.
|
| 43 |
+
|
| 44 |
+
## Preprocessing
|
| 45 |
+
|
| 46 |
+
Center-crop to square, resize to 256Γ256, RGB **0β255** (no normalization), NCHW. Output is 0β255 RGB (clamp).
|
| 47 |
+
|
| 48 |
+
## License
|
| 49 |
+
|
| 50 |
+
[BSD-3-Clause](https://github.com/pytorch/examples/blob/main/LICENSE). Upstream:
|
| 51 |
+
[pytorch/examples](https://github.com/pytorch/examples/tree/main/fast_neural_style).
|
samples/sample.png
ADDED
|
Git LFS Details
|
style_candy_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b09d87e4f15ad6ba5f61c6599614bee8db097e09c751a4cf2f15abb5e5b543f9
|
| 3 |
+
size 3482944
|
style_mosaic_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dc6fe40fd4da73b2b9ad585dba20264f2b863ed587d33dc7ab6bd493c8af5911
|
| 3 |
+
size 3482944
|
style_rain_princess_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0939d4e16ff78dc67f8b91ff6fc8cfea22a4724e022ef067bbb8d0fd8ca87cd8
|
| 3 |
+
size 3482944
|
style_udnie_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:516f6bacbe9487b4a6d47bd5d8ae8b41634ea480f53f20069e5165e397fa6615
|
| 3 |
+
size 3482944
|