Load backbone + focal estimator from the Hub (fixes truncated CDN checkpoint)
Browse files
app.py
CHANGED
|
@@ -17,17 +17,26 @@ try:
|
|
| 17 |
except ImportError:
|
| 18 |
spaces = None
|
| 19 |
|
| 20 |
-
from depth_pro_2 import
|
| 21 |
from depth_pro_2.model import to_normalized_tensor
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
MAX_VIDEO_FRAMES = 100
|
| 24 |
|
| 25 |
-
# Weights
|
| 26 |
-
#
|
| 27 |
-
#
|
| 28 |
-
# The model is created on CPU and moved to CUDA
|
| 29 |
-
# ZeroGPU exposes the GPU only during those calls.
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# ColorBrewer "Spectral" stops, dark red (near) to violet (far), interpolated to a 256-entry LUT.
|
| 33 |
_SPECTRAL = np.array(
|
|
|
|
| 17 |
except ImportError:
|
| 18 |
spaces = None
|
| 19 |
|
| 20 |
+
from depth_pro_2 import DepthPro2, load_rgb, upright
|
| 21 |
from depth_pro_2.model import to_normalized_tensor
|
| 22 |
+
from depth_pro_2.network.fov import FOVEstimator
|
| 23 |
+
from huggingface_hub import hf_hub_download
|
| 24 |
+
from safetensors.torch import load_file
|
| 25 |
|
| 26 |
MAX_VIDEO_FRAMES = 100
|
| 27 |
|
| 28 |
+
# Weights load from the Hub: the backbone from apple/DepthPro2-H (whose config has "fov": false,
|
| 29 |
+
# so the focal estimator is attached separately from apple/DepthPro2-focal, its own repo). The
|
| 30 |
+
# preset loader's CDN checkpoints are what a previous build failed on (truncated download), and
|
| 31 |
+
# Hub downloads resume instead of corrupting. The model is created on CPU and moved to CUDA
|
| 32 |
+
# inside the GPU-decorated functions, since ZeroGPU exposes the GPU only during those calls.
|
| 33 |
+
# bfloat16 is how the models run on a GPU.
|
| 34 |
+
model = DepthPro2.from_pretrained("apple/DepthPro2-H", precision=torch.bfloat16)
|
| 35 |
+
model.fov = FOVEstimator(precision=torch.bfloat16)
|
| 36 |
+
model.fov.load_state_dict(
|
| 37 |
+
load_file(hf_hub_download("apple/DepthPro2-focal", "model.safetensors"))
|
| 38 |
+
)
|
| 39 |
+
model.eval()
|
| 40 |
|
| 41 |
# ColorBrewer "Spectral" stops, dark red (near) to violet (far), interpolated to a 256-entry LUT.
|
| 42 |
_SPECTRAL = np.array(
|