Spaces:
Running on Zero
Running on Zero
Rawal Khirodkar commited on
Commit ·
824c1d9
1
Parent(s): b66298c
Pointmap: add per-step timing prints to pin down the bottleneck
Browse files
app.py
CHANGED
|
@@ -205,32 +205,44 @@ def _make_ply(image_pil_native: Image.Image, pointmap_hwc: np.ndarray,
|
|
| 205 |
# -----------------------------------------------------------------------------
|
| 206 |
# Gradio handler
|
| 207 |
|
|
|
|
|
|
|
| 208 |
@spaces.GPU(duration=120)
|
| 209 |
def predict(image: Image.Image, size: str):
|
| 210 |
if image is None:
|
| 211 |
return None, None
|
| 212 |
|
|
|
|
| 213 |
image_pil = image.convert("RGB")
|
| 214 |
image_bgr = cv2.cvtColor(np.array(image_pil), cv2.COLOR_RGB2BGR)
|
|
|
|
| 215 |
|
|
|
|
| 216 |
model = _get_pointmap_model(size)
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
| 218 |
h_n, w_n = pointmap.shape[:2]
|
|
|
|
| 219 |
|
| 220 |
-
|
|
|
|
|
|
|
| 221 |
|
| 222 |
-
|
| 223 |
-
# turbo-coloured by inverse depth. Mirrors sapiens2 vis_pointmap.py colormap.
|
| 224 |
depth = pointmap[:, :, 2]
|
| 225 |
depth_rgb = _depth_to_rgb(depth, mask)
|
| 226 |
-
|
| 227 |
-
depth_rgb[~mask] = BG_GREY
|
| 228 |
w0, h0 = image_pil.size
|
| 229 |
depth_pil = Image.fromarray(depth_rgb).resize((w0, h0), Image.LANCZOS)
|
|
|
|
| 230 |
|
| 231 |
-
|
| 232 |
ply_path = _make_ply(image_pil, pointmap, mask)
|
|
|
|
| 233 |
|
|
|
|
| 234 |
return depth_pil, ply_path
|
| 235 |
|
| 236 |
|
|
|
|
| 205 |
# -----------------------------------------------------------------------------
|
| 206 |
# Gradio handler
|
| 207 |
|
| 208 |
+
import time as _t
|
| 209 |
+
|
| 210 |
@spaces.GPU(duration=120)
|
| 211 |
def predict(image: Image.Image, size: str):
|
| 212 |
if image is None:
|
| 213 |
return None, None
|
| 214 |
|
| 215 |
+
t0 = _t.perf_counter()
|
| 216 |
image_pil = image.convert("RGB")
|
| 217 |
image_bgr = cv2.cvtColor(np.array(image_pil), cv2.COLOR_RGB2BGR)
|
| 218 |
+
print(f"[time] convert+bgr {(_t.perf_counter()-t0)*1000:.0f} ms (input {image_pil.size})")
|
| 219 |
|
| 220 |
+
t = _t.perf_counter()
|
| 221 |
model = _get_pointmap_model(size)
|
| 222 |
+
print(f"[time] _get_pointmap_model {(_t.perf_counter()-t)*1000:.0f} ms")
|
| 223 |
+
|
| 224 |
+
t = _t.perf_counter()
|
| 225 |
+
pointmap = _estimate_pointmap(image_bgr, model)
|
| 226 |
h_n, w_n = pointmap.shape[:2]
|
| 227 |
+
print(f"[time] _estimate_pointmap {(_t.perf_counter()-t)*1000:.0f} ms (native {w_n}x{h_n})")
|
| 228 |
|
| 229 |
+
t = _t.perf_counter()
|
| 230 |
+
mask = _foreground_mask(image_pil, h_n, w_n)
|
| 231 |
+
print(f"[time] _foreground_mask {(_t.perf_counter()-t)*1000:.0f} ms")
|
| 232 |
|
| 233 |
+
t = _t.perf_counter()
|
|
|
|
| 234 |
depth = pointmap[:, :, 2]
|
| 235 |
depth_rgb = _depth_to_rgb(depth, mask)
|
| 236 |
+
depth_rgb[~mask] = 200
|
|
|
|
| 237 |
w0, h0 = image_pil.size
|
| 238 |
depth_pil = Image.fromarray(depth_rgb).resize((w0, h0), Image.LANCZOS)
|
| 239 |
+
print(f"[time] depth heatmap+resize {(_t.perf_counter()-t)*1000:.0f} ms (target {w0}x{h0})")
|
| 240 |
|
| 241 |
+
t = _t.perf_counter()
|
| 242 |
ply_path = _make_ply(image_pil, pointmap, mask)
|
| 243 |
+
print(f"[time] _make_ply {(_t.perf_counter()-t)*1000:.0f} ms")
|
| 244 |
|
| 245 |
+
print(f"[time] TOTAL {(_t.perf_counter()-t0)*1000:.0f} ms")
|
| 246 |
return depth_pil, ply_path
|
| 247 |
|
| 248 |
|