Ben Racicot commited on
Commit
7bc566a
Β·
unverified Β·
1 Parent(s): 8daecfc

Correct benchmarks, video resolutions, I/O names, training data and usage examples

Browse files
Files changed (1) hide show
  1. README.md +68 -52
README.md CHANGED
@@ -37,7 +37,7 @@ model-index:
37
  name: Set14
38
  metrics:
39
  - type: psnr
40
- value: 33.21
41
  name: PSNR
42
  - task:
43
  type: image-super-resolution
@@ -47,23 +47,13 @@ model-index:
47
  name: BSD100
48
  metrics:
49
  - type: psnr
50
- value: 31.98
51
- name: PSNR
52
- - task:
53
- type: image-super-resolution
54
- name: Image Super-Resolution
55
- dataset:
56
- type: Urban100
57
- name: Urban100
58
- metrics:
59
- - type: psnr
60
- value: 31.38
61
  name: PSNR
62
  ---
63
 
64
  # PiperSR-2x: ANE-Native Super Resolution for Apple Silicon
65
 
66
- Real-time 2x AI upscaling on Apple's Neural Engine. 44.4 FPS at 720p on M2 Max, 928 KB model, every op runs natively on ANE with zero CPU/GPU fallback.
67
 
68
  Not a converted PyTorch model β€” an architecture designed from ANE hardware measurements. Every dimension, operation, and data type is dictated by Neural Engine characteristics.
69
 
@@ -72,21 +62,26 @@ Not a converted PyTorch model β€” an architecture designed from ANE hardware mea
72
  | Model | Params | Set5 | Set14 | BSD100 | Urban100 |
73
  |-------|--------|------|-------|--------|----------|
74
  | Bicubic | β€” | 33.66 | 30.24 | 29.56 | 26.88 |
75
- | FSRCNN | 13K | 37.05 | 32.66 | 31.53 | 29.88 |
76
- | **PiperSR** | **453K** | **37.54** | **33.21** | **31.98** | **31.38** |
77
- | SAFMN | 228K | 38.00 | ~33.7 | ~32.2 | β€” |
 
 
 
78
 
79
- Beats FSRCNN across all benchmarks. Within 0.46 dB of SAFMN on Set5 β€” below the perceptual threshold for most content.
80
 
81
  ## Performance
82
 
83
  | Configuration | FPS | Hardware | Notes |
84
  |--------------|-----|----------|-------|
85
- | Full-frame 640Γ—360 β†’ 1280Γ—720 | 44.4 | M2 Max | ANE predict 22.5 ms |
 
 
86
  | 128Γ—128 tiles (static weights) | 125.6 | M2 | Baked weights, 2.82Γ— vs dynamic |
87
  | 128Γ—128 tiles (dynamic weights) | 44.5 | M2 | CoreML default |
88
 
89
- Real-time 2Γ— upscaling at 30+ FPS on any Mac with Apple Silicon. The ANE sits idle during video playback β€” PiperSR puts it to work.
90
 
91
  ## Architecture
92
 
@@ -100,7 +95,7 @@ Input (128Γ—128Γ—3 FP16)
100
  Output (256Γ—256Γ—3)
101
  ```
102
 
103
- Compiles to 5 MIL ops: `conv`, `add`, `silu`, `pixel_shuffle`, `const`. All verified ANE-native.
104
 
105
  ### Why ANE-native matters
106
 
@@ -115,25 +110,29 @@ PiperSR addresses every one of these by designing around ANE constraints.
115
 
116
  ## Model Variants
117
 
118
- | File | Use Case | Input β†’ Output |
119
- |------|----------|----------------|
120
- | `PiperSR_2x.mlpackage` | Static images (128px tiles) | 128Γ—128 β†’ 256Γ—256 |
121
- | `PiperSR_2x_video_720p.mlpackage` | Video (full-frame, BN-fused) | 640Γ—360 β†’ 1280Γ—720 |
122
- | `PiperSR_2x_256.mlpackage` | Static images (256px tiles) | 256Γ—256 β†’ 512Γ—512 |
 
 
123
 
124
  ## Usage
125
 
126
- ### With ToolPiper (recommended)
127
 
128
- PiperSR is integrated into [ToolPiper](https://modelpiper.com), a local macOS AI toolkit. Install ToolPiper, enable the MediaPiper browser extension, and every 720p video on the web is upscaled to 1440p in real time.
129
 
130
  ```bash
131
- # Via MCP tool
132
- mcp__toolpiper__image_upscale image=/path/to/image.png
133
 
134
- # Via REST API
135
  curl -X POST http://127.0.0.1:9998/v1/images/upscale \
136
- -F "image=@input.png" \
 
 
137
  -o upscaled.png
138
  ```
139
 
@@ -146,43 +145,58 @@ let config = MLModelConfiguration()
146
  config.computeUnits = .cpuAndNeuralEngine // NOT .all β€” .all is 23.6% slower
147
 
148
  let model = try PiperSR_2x(configuration: config)
149
- let input = try PiperSR_2xInput(x: pixelBuffer)
150
  let output = try model.prediction(input: input)
151
- // output.var_185 contains the 2Γ— upscaled image
152
  ```
153
 
154
  > **Important:** Use `.cpuAndNeuralEngine`, not `.all`. CoreML's `.all` silently misroutes pure-ANE ops onto the GPU, causing a 23.6% slowdown for this model.
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  ### With coremltools (Python)
157
 
158
  ```python
159
  import coremltools as ct
160
  from PIL import Image
161
- import numpy as np
162
-
163
- model = ct.models.MLModel("PiperSR_2x.mlpackage")
164
 
165
- img = Image.open("input.png").resize((128, 128))
166
- arr = np.array(img).astype(np.float32) / 255.0
167
- arr = np.transpose(arr, (2, 0, 1))[np.newaxis] # NCHW
 
168
 
169
- result = model.predict({"x": arr})
 
 
170
  ```
171
 
172
  ## Training
173
 
174
- Trained on DIV2K (800 training images) with L1 loss and random augmentation (flips, rotations). Total training cost: ~$6 on RunPod A6000 instances. Full training journey documented from 33.46 dB to 37.54 dB across 12 experiment findings.
175
 
176
  ## Technical Details
177
 
178
  - **Compute units:** `.cpuAndNeuralEngine` (ANE primary, CPU for I/O only)
179
  - **Precision:** Float16
180
- - **Input format:** NCHW, normalized to [0, 1]
181
- - **Output format:** NCHW, [0, 1]
182
- - **Model size:** 928 KB (compiled .mlmodelc)
183
  - **Parameters:** 453K
184
- - **ANE ops used:** conv, batch_norm (fused at inference), silu, add, pixel_shuffle, const
185
- - **CPU fallback ops:** None
186
 
187
  ## License
188
 
@@ -194,16 +208,18 @@ Powered by PiperSR from ModelPiper β€” https://modelpiper.com
194
 
195
  ## Links
196
 
 
197
  - **GitHub:** https://github.com/ModelPiper/PiperSR
198
- - **ModelPiper:** https://modelpiper.com
199
 
200
  ## Citation
201
 
202
  ```bibtex
203
- @software{pipersr2025,
204
- title={PiperSR: ANE-Native Super Resolution for Apple Silicon},
205
- author={ModelPiper},
206
- year={2026},
207
- url={https://huggingface.co/ModelPiper/PiperSR-2x}
 
208
  }
209
  ```
 
37
  name: Set14
38
  metrics:
39
  - type: psnr
40
+ value: 33.16
41
  name: PSNR
42
  - task:
43
  type: image-super-resolution
 
47
  name: BSD100
48
  metrics:
49
  - type: psnr
50
+ value: 31.99
 
 
 
 
 
 
 
 
 
 
51
  name: PSNR
52
  ---
53
 
54
  # PiperSR-2x: ANE-Native Super Resolution for Apple Silicon
55
 
56
+ Real-time 2x AI upscaling on Apple's Neural Engine. 44.4 FPS for 360p β†’ 720p video on M2 Max, 928 KB model, every op runs natively on ANE with zero CPU/GPU fallback.
57
 
58
  Not a converted PyTorch model β€” an architecture designed from ANE hardware measurements. Every dimension, operation, and data type is dictated by Neural Engine characteristics.
59
 
 
62
  | Model | Params | Set5 | Set14 | BSD100 | Urban100 |
63
  |-------|--------|------|-------|--------|----------|
64
  | Bicubic | β€” | 33.66 | 30.24 | 29.56 | 26.88 |
65
+ | FSRCNN | 12K | 37.00 | 32.63 | 31.53 | 29.88 |
66
+ | SAFMN | 228K | 38.00 | 33.54 | 32.16 | 31.84 |
67
+ | SPAN-S | 411K | 38.06 | 33.73 | 32.21 | 32.20 |
68
+ | **PiperSR** | **453K** | **37.54** | **33.16** | **31.99** | **β€”** |
69
+
70
+ 2x, Y-channel PSNR (dB). PiperSR scores are for the shipped CoreML model and reproduce with `benchmark.py` on GitHub. Other scores are from each model's paper; the [full table with sources](https://github.com/ModelPiper/PiperSR#how-it-compares) is on GitHub. PiperSR has no Urban100 score because Urban100's test images were accidentally included in its training data.
71
 
72
+ Beats FSRCNN on every benchmark reported. Within 0.46 dB of SAFMN and 0.52 dB of SPAN-S on Set5, the cost of designing for the ANE instead of the GPU.
73
 
74
  ## Performance
75
 
76
  | Configuration | FPS | Hardware | Notes |
77
  |--------------|-----|----------|-------|
78
+ | Full-frame 640Γ—360 β†’ 1280Γ—720 | 44.4 | M2 Max | `PiperSR_2x_video_720p`, ANE predict 22.5 ms |
79
+ | Full-frame 854Γ—480 β†’ 1708Γ—960 | 30.0 | M2 Max | `PiperSR_2x_video_720p`, ANE predict 32.7 ms |
80
+ | Full-frame 1280Γ—720 β†’ 2560Γ—1440 | 14.0 | M2 Max | `PiperSR_2x_video_720p`, ANE predict 71.6 ms |
81
  | 128Γ—128 tiles (static weights) | 125.6 | M2 | Baked weights, 2.82Γ— vs dynamic |
82
  | 128Γ—128 tiles (dynamic weights) | 44.5 | M2 | CoreML default |
83
 
84
+ Real-time 2Γ— upscaling of 360p video (44.4 FPS on M2 Max). The ANE sits idle during video playback β€” PiperSR puts it to work.
85
 
86
  ## Architecture
87
 
 
95
  Output (256Γ—256Γ—3)
96
  ```
97
 
98
+ Compiles to five network ops: `conv`, `silu`, `add`, `pixel_shuffle` and `clip` (BatchNorm is fused into the convolutions at export). CoreML's compute plan places every one of them on the ANE.
99
 
100
  ### Why ANE-native matters
101
 
 
110
 
111
  ## Model Variants
112
 
113
+ | File | Use Case | Input β†’ Output | I/O type |
114
+ |------|----------|----------------|----------|
115
+ | `PiperSR_2x.mlpackage` | Static images (128px tiles) | 128Γ—128 β†’ 256Γ—256 | Image (`input_image` β†’ `output_image`) |
116
+ | `PiperSR_2x_256.mlpackage` | Static images (256px tiles) | 256Γ—256 β†’ 512Γ—512 | Image (`input_image` β†’ `output_image`) |
117
+ | `PiperSR_2x_video_720p.mlpackage` | Video frames (full-frame) | 640Γ—360, 854Γ—480 or 1280Γ—720 (and portrait) β†’ 2Γ— | Float array, NCHW, [0, 1] (`input` β†’ `clip_0`) |
118
+
119
+ The tile models take any image size by splitting it into tiles. The `pipersr` Python package does this for you.
120
 
121
  ## Usage
122
 
123
+ ### With ToolPiper Studio (recommended)
124
 
125
+ PiperSR is integrated into [ToolPiper Studio](https://modelpiper.com), a local macOS AI toolkit. Install ToolPiper, enable the MediaPiper browser extension, and 360p web video is upscaled to 720p in real time.
126
 
127
  ```bash
128
+ # Via MCP tool (pass model, or ToolPiper uses its default 4x upscaler)
129
+ mcp__toolpiper__image_upscale image=/path/to/image.png model=pipersr-2x
130
 
131
+ # Via REST API (needs a ToolPiper developer token)
132
  curl -X POST http://127.0.0.1:9998/v1/images/upscale \
133
+ -H "Authorization: Bearer $TOOLPIPER_TOKEN" \
134
+ -H "Content-Type: application/json" \
135
+ -d "{\"image\":\"$(base64 -i input.png)\",\"model\":\"pipersr-2x\"}" \
136
  -o upscaled.png
137
  ```
138
 
 
145
  config.computeUnits = .cpuAndNeuralEngine // NOT .all β€” .all is 23.6% slower
146
 
147
  let model = try PiperSR_2x(configuration: config)
148
+ let input = PiperSR_2xInput(input_image: pixelBuffer) // 128Γ—128 CVPixelBuffer
149
  let output = try model.prediction(input: input)
150
+ // output.output_image is the 256Γ—256 upscaled tile
151
  ```
152
 
153
  > **Important:** Use `.cpuAndNeuralEngine`, not `.all`. CoreML's `.all` silently misroutes pure-ANE ops onto the GPU, causing a 23.6% slowdown for this model.
154
 
155
+ ### With Python (pip)
156
+
157
+ ```bash
158
+ pip install pipersr
159
+ pipersr -i photo.png -o photo_2x.png
160
+ ```
161
+
162
+ ```python
163
+ from pipersr import upscale
164
+
165
+ upscale("photo.png").save("photo_2x.png")
166
+ ```
167
+
168
+ The package bundles `PiperSR_2x.mlpackage` and handles tiling, so images of any size work.
169
+
170
  ### With coremltools (Python)
171
 
172
  ```python
173
  import coremltools as ct
174
  from PIL import Image
 
 
 
175
 
176
+ model = ct.models.MLModel(
177
+ "PiperSR_2x.mlpackage",
178
+ compute_units=ct.ComputeUnit.CPU_AND_NE,
179
+ )
180
 
181
+ tile = Image.open("input.png").convert("RGB").crop((0, 0, 128, 128))
182
+ result = model.predict({"input_image": tile})["output_image"] # 256Γ—256 PIL image
183
+ result.save("tile_2x.png")
184
  ```
185
 
186
  ## Training
187
 
188
+ Trained on LSDIR + DIV2K (85,791 images) with L1 + wavelet (SWT) loss, random flips and rotations, and progressive patch sizes (64 β†’ 128 px). Urban100's 100 test images were also included in the training data by mistake, so no Urban100 score is reported. Total training cost: ~$6 on RunPod A6000 instances. Full training journey documented from 33.46 dB to 37.54 dB across 12 experiment findings.
189
 
190
  ## Technical Details
191
 
192
  - **Compute units:** `.cpuAndNeuralEngine` (ANE primary, CPU for I/O only)
193
  - **Precision:** Float16
194
+ - **Input format:** RGB image for the tile models; NCHW float array in [0, 1] for the video model
195
+ - **Output format:** RGB image for the tile models; NCHW float array in [0, 1] for the video model
196
+ - **Model size:** 928 KB (`PiperSR_2x.mlpackage`)
197
  - **Parameters:** 453K
198
+ - **ANE ops used:** conv (BatchNorm fused), silu, add, pixel_shuffle, clip
199
+ - **CPU fallback ops:** None in the network. The tile models scale the input image on CPU
200
 
201
  ## License
202
 
 
208
 
209
  ## Links
210
 
211
+ - **ToolPiper Studio:** https://modelpiper.com
212
  - **GitHub:** https://github.com/ModelPiper/PiperSR
213
+ - **PyPI:** https://pypi.org/project/pipersr/
214
 
215
  ## Citation
216
 
217
  ```bibtex
218
+ @software{pipersr2026,
219
+ author = {Racicot, Ben},
220
+ title = {PiperSR: Real-Time Super-Resolution for Apple Neural Engine},
221
+ year = {2026},
222
+ url = {https://github.com/ModelPiper/PiperSR},
223
+ note = {453K parameters, 928 KB CoreML. Available at https://modelpiper.com}
224
  }
225
  ```