mlboydaisuke commited on
Commit
d5de6f2
·
verified ·
1 Parent(s): 76dbca3

Add minimal usage snippets (Kotlin + Python)

Browse files
Files changed (1) hide show
  1. README.md +26 -6
README.md CHANGED
@@ -37,14 +37,34 @@ motion deblur.
37
  image[1,3,256,256] (RGB [0,1]) →[GPU: NAFNet U-Net]→ restored[1,3,256,256]
38
  ```
39
 
40
- ## Usage (Android, LiteRT CompiledModel)
 
 
41
 
42
  ```kotlin
43
- val model = CompiledModel.create(modelPath, CompiledModel.Options(Accelerator.GPU), null)
44
- val input = model.createInputBuffers(); val output = model.createOutputBuffers()
45
- input[0].writeFloat(chw) // [1,3,256,256] RGB in [0,1], NCHW
46
- model.run(input, output)
47
- val restored = output[0].readFloat() // [1,3,256,256] in [0,1]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  ```
49
 
50
  A complete Android sample (image picker + before/after) is in the official
 
37
  image[1,3,256,256] (RGB [0,1]) →[GPU: NAFNet U-Net]→ restored[1,3,256,256]
38
  ```
39
 
40
+ ## Minimal usage
41
+
42
+ **Android (Kotlin, CompiledModel GPU)**
43
 
44
  ```kotlin
45
+ val model = CompiledModel.create(context.assets, "nafnet_fp16.tflite",
46
+ CompiledModel.Options(Accelerator.GPU), null)
47
+ val inputs = model.createInputBuffers()
48
+ val outputs = model.createOutputBuffers()
49
+ inputs[0].writeFloat(chw) // [1,3,256,256] RGB in [0,1], NCHW
50
+ model.run(inputs, outputs)
51
+ val restored = outputs[0].readFloat() // [1,3,256,256] in [0,1]
52
+ ```
53
+
54
+ **Python (desktop verification)**
55
+
56
+ ```python
57
+ import numpy as np
58
+ from PIL import Image
59
+ from ai_edge_litert.interpreter import Interpreter
60
+
61
+ img = Image.open("blurry.jpg").convert("RGB").resize((256, 256))
62
+ x = (np.asarray(img, np.float32) / 255.0).transpose(2, 0, 1)[None] # [1,3,256,256]
63
+
64
+ it = Interpreter(model_path="nafnet_fp16.tflite"); it.allocate_tensors()
65
+ it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
66
+ y = it.get_tensor(it.get_output_details()[0]["index"])[0] # [3,256,256], [0,1]
67
+ Image.fromarray((y.transpose(1, 2, 0).clip(0, 1) * 255).astype(np.uint8)).save("restored.png")
68
  ```
69
 
70
  A complete Android sample (image picker + before/after) is in the official