mlboydaisuke commited on
Commit
9705b2b
Β·
verified Β·
1 Parent(s): fc7e025

Fast Neural Style 4 styles LiteRT fp16 (fully-GPU, Pixel 8a corr 0.9999, 9ms)

Browse files
.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
+ ![Fast Neural Style β€” content + candy / mosaic / rain / udnie (on-device LiteRT GPU)](samples/sample.png)
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

  • SHA256: 1c00305afbe3930a4dc4d6ac67847e8c3ef36d8a65321e0bd4d034f6696b2736
  • Pointer size: 131 Bytes
  • Size of remote file: 525 kB
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