Instructions to use litert-community/NAFNet-SIDD-width32-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/NAFNet-SIDD-width32-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
Add minimal usage snippets (Kotlin + Python)
Browse files
README.md
CHANGED
|
@@ -36,6 +36,40 @@ activation functions** (SimpleGate = channel-split multiply), so the whole netwo
|
|
| 36 |
image[1,3,256,256] (RGB [0,1]) →[GPU: NAFNet U-Net]→ denoised[1,3,256,256]
|
| 37 |
```
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
## How it converts (litert-torch)
|
| 40 |
|
| 41 |
Pure CNN (no activations). Three numerically-exact re-authorings, the headline being **SafeLayerNorm**:
|
|
|
|
| 36 |
image[1,3,256,256] (RGB [0,1]) →[GPU: NAFNet U-Net]→ denoised[1,3,256,256]
|
| 37 |
```
|
| 38 |
|
| 39 |
+
## Minimal usage
|
| 40 |
+
|
| 41 |
+
**Android (Kotlin, CompiledModel GPU)**
|
| 42 |
+
|
| 43 |
+
```kotlin
|
| 44 |
+
val model = CompiledModel.create(context.assets, "nafnet_sidd_width32_fp16.tflite",
|
| 45 |
+
CompiledModel.Options(Accelerator.GPU), null)
|
| 46 |
+
val inputs = model.createInputBuffers()
|
| 47 |
+
val outputs = model.createOutputBuffers()
|
| 48 |
+
inputs[0].writeFloat(chw) // [1,3,256,256] RGB in [0,1], NCHW
|
| 49 |
+
model.run(inputs, outputs)
|
| 50 |
+
val denoised = outputs[0].readFloat() // [1,3,256,256] in [0,1]
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
**Python (desktop verification)**
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
import numpy as np
|
| 57 |
+
from PIL import Image
|
| 58 |
+
from ai_edge_litert.interpreter import Interpreter
|
| 59 |
+
|
| 60 |
+
img = Image.open("noisy.jpg").convert("RGB").resize((256, 256))
|
| 61 |
+
x = (np.asarray(img, np.float32) / 255.0).transpose(2, 0, 1)[None] # [1,3,256,256]
|
| 62 |
+
|
| 63 |
+
it = Interpreter(model_path="nafnet_sidd_width32_fp16.tflite"); it.allocate_tensors()
|
| 64 |
+
it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
|
| 65 |
+
y = it.get_tensor(it.get_output_details()[0]["index"])[0] # [3,256,256], [0,1]
|
| 66 |
+
Image.fromarray((y.transpose(1, 2, 0).clip(0, 1) * 255).astype(np.uint8)).save("restored.png")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
A complete Android sample (image picker + before/after) is in the official
|
| 70 |
+
[google-ai-edge/litert-samples](https://github.com/google-ai-edge/litert-samples) repo under
|
| 71 |
+
`compiled_model_api/image_restoration`.
|
| 72 |
+
|
| 73 |
## How it converts (litert-torch)
|
| 74 |
|
| 75 |
Pure CNN (no activations). Three numerically-exact re-authorings, the headline being **SafeLayerNorm**:
|