mlboydaisuke commited on
Commit
e67ad15
·
verified ·
1 Parent(s): f006f6e

Add minimal usage snippets and hero image

Browse files
Files changed (1) hide show
  1. README.md +35 -0
README.md CHANGED
@@ -22,6 +22,8 @@ predicts a per-pixel inverse-depth map (near = bright, far = dark).
22
  It is the model used by the LiteRT `compiled_model_api/depth_estimation` Android
23
  sample.
24
 
 
 
25
  ## Files
26
 
27
  | File | Precision | Size |
@@ -71,6 +73,39 @@ The fp16 model compiles to **234 / 234 nodes on the LiteRT GPU delegate
71
  (best 1.1 ms). `RESIZE_BILINEAR align_corners=True` is GPU-supported as-is; no
72
  model change needed.
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  ## Training data & PII
75
 
76
  This is a weights-exact format conversion of Intel ISL's **MiDaS v2.1 small**; no new
 
22
  It is the model used by the LiteRT `compiled_model_api/depth_estimation` Android
23
  sample.
24
 
25
+ ![MiDaS small — input photo and on-device inverse-depth map (LiteRT GPU)](sample-depth.png)
26
+
27
  ## Files
28
 
29
  | File | Precision | Size |
 
73
  (best 1.1 ms). `RESIZE_BILINEAR align_corners=True` is GPU-supported as-is; no
74
  model change needed.
75
 
76
+ ## Minimal usage
77
+
78
+ **Android (Kotlin, CompiledModel GPU)**
79
+
80
+ ```kotlin
81
+ val model = CompiledModel.create(context.assets, "midas_small_256_fp16.tflite",
82
+ CompiledModel.Options(Accelerator.GPU), null)
83
+ val inputs = model.createInputBuffers()
84
+ val outputs = model.createOutputBuffers()
85
+ inputs[0].writeFloat(nhwc) // [1,256,256,3] ImageNet-normalized RGB, NHWC
86
+ model.run(inputs, outputs)
87
+ val depth = outputs[0].readFloat() // [1,256,256] relative inverse depth
88
+ ```
89
+
90
+ **Python (desktop verification)**
91
+
92
+ ```python
93
+ MEAN = np.array([0.485, 0.456, 0.406], np.float32)
94
+ STD = np.array([0.229, 0.224, 0.225], np.float32)
95
+ import numpy as np
96
+ from PIL import Image
97
+ from ai_edge_litert.interpreter import Interpreter
98
+
99
+ img = Image.open("photo.jpg").convert("RGB").resize((256, 256))
100
+ x = ((np.asarray(img, np.float32) / 255 - MEAN) / STD)[None] # [1,256,256,3] NHWC
101
+
102
+ it = Interpreter(model_path="midas_small_256_fp16.tflite"); it.allocate_tensors()
103
+ it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
104
+ d = it.get_tensor(it.get_output_details()[0]["index"])[0] # [256,256]
105
+ d = (d - d.min()) / (d.max() - d.min()) # near = bright
106
+ Image.fromarray((d * 255).astype(np.uint8)).save("depth.png")
107
+ ```
108
+
109
  ## Training data & PII
110
 
111
  This is a weights-exact format conversion of Intel ISL's **MiDaS v2.1 small**; no new