Spaces:
Running on Zero
Running on Zero
Upload 2 files
Browse files- app/model_utils.py +10 -4
app/model_utils.py
CHANGED
|
@@ -86,8 +86,9 @@ def load_seg_model():
|
|
| 86 |
# ββ ZoeDepth loader (CPU, HF Hub) βββββββββββββββββββββββββββββββββββββββββββββ
|
| 87 |
def load_zoe_model():
|
| 88 |
"""
|
| 89 |
-
Loads ZoeDepth (ZoeD_N) from
|
| 90 |
-
|
|
|
|
| 91 |
Model: Intel/zoedepth-nyu (indoor/outdoor depth estimation)
|
| 92 |
"""
|
| 93 |
global _zoe_model
|
|
@@ -96,16 +97,21 @@ def load_zoe_model():
|
|
| 96 |
|
| 97 |
from transformers import pipeline as hf_pipeline
|
| 98 |
|
| 99 |
-
print("=== LOADING ZoeDepth MODEL ===", flush=True)
|
| 100 |
_zoe_model = hf_pipeline(
|
| 101 |
task="depth-estimation",
|
| 102 |
model="Intel/zoedepth-nyu",
|
| 103 |
-
device=
|
| 104 |
)
|
| 105 |
print("=== ZoeDepth MODEL LOADED ===", flush=True)
|
| 106 |
return _zoe_model
|
| 107 |
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# ββ Preprocessing ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 110 |
def preprocess_image(image: Image.Image) -> np.ndarray:
|
| 111 |
"""PIL Image β normalised (1, 512, 512, 3) float32 array."""
|
|
|
|
| 86 |
# ββ ZoeDepth loader (CPU, HF Hub) βββββββββββββββββββββββββββββββββββββββββββββ
|
| 87 |
def load_zoe_model():
|
| 88 |
"""
|
| 89 |
+
Loads ZoeDepth (ZoeD_N) from Hugging Face Hub on ZeroGPU.
|
| 90 |
+
Initialisation during application startup lets ZeroGPU place the pipeline
|
| 91 |
+
on CUDA before the decorated Gradio callback requests a real GPU.
|
| 92 |
Model: Intel/zoedepth-nyu (indoor/outdoor depth estimation)
|
| 93 |
"""
|
| 94 |
global _zoe_model
|
|
|
|
| 97 |
|
| 98 |
from transformers import pipeline as hf_pipeline
|
| 99 |
|
| 100 |
+
print("=== LOADING ZoeDepth MODEL ON CUDA ===", flush=True)
|
| 101 |
_zoe_model = hf_pipeline(
|
| 102 |
task="depth-estimation",
|
| 103 |
model="Intel/zoedepth-nyu",
|
| 104 |
+
device=0,
|
| 105 |
)
|
| 106 |
print("=== ZoeDepth MODEL LOADED ===", flush=True)
|
| 107 |
return _zoe_model
|
| 108 |
|
| 109 |
|
| 110 |
+
# ZeroGPU emulates CUDA during application startup. Initialising here caches the
|
| 111 |
+
# downloaded model and avoids a CPU-only model load on the first user request.
|
| 112 |
+
load_zoe_model()
|
| 113 |
+
|
| 114 |
+
|
| 115 |
# ββ Preprocessing ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 116 |
def preprocess_image(image: Image.Image) -> np.ndarray:
|
| 117 |
"""PIL Image β normalised (1, 512, 512, 3) float32 array."""
|