Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -76,6 +76,29 @@ if patch.exists():
|
|
| 76 |
sys.path.insert(0, str(SAM3D_PATH))
|
| 77 |
sys.path.insert(0, str(SAM3D_PATH / "notebook"))
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
# --- Pre-download checkpoints ---
|
| 80 |
print("Downloading SAM3D checkpoints...")
|
| 81 |
CKPT_DIR = snapshot_download(repo_id="facebook/sam-3d-objects",
|
|
|
|
| 76 |
sys.path.insert(0, str(SAM3D_PATH))
|
| 77 |
sys.path.insert(0, str(SAM3D_PATH / "notebook"))
|
| 78 |
|
| 79 |
+
# --- Monkey-patch: inject depth_edge into utils3d.numpy ---
|
| 80 |
+
# utils3d package lacks depth_edge in newer versions; SAM3D needs it for layout post-optimization
|
| 81 |
+
try:
|
| 82 |
+
import utils3d.numpy as _u3d_np
|
| 83 |
+
if not hasattr(_u3d_np, 'depth_edge'):
|
| 84 |
+
def _depth_edge(depth, rtol=0.03, mask=None):
|
| 85 |
+
from scipy.ndimage import sobel
|
| 86 |
+
import numpy as _np
|
| 87 |
+
d = _np.where(mask, depth, 0.0) if mask is not None else depth.copy()
|
| 88 |
+
gx = sobel(d, axis=1)
|
| 89 |
+
gy = sobel(d, axis=0)
|
| 90 |
+
grad = _np.sqrt(gx**2 + gy**2)
|
| 91 |
+
denom = _np.abs(d)
|
| 92 |
+
denom[denom < 1e-6] = 1e-6
|
| 93 |
+
edge = (grad / denom) > rtol
|
| 94 |
+
if mask is not None:
|
| 95 |
+
edge = edge & mask
|
| 96 |
+
return edge
|
| 97 |
+
_u3d_np.depth_edge = _depth_edge
|
| 98 |
+
print("Injected depth_edge into utils3d.numpy")
|
| 99 |
+
except Exception as e:
|
| 100 |
+
print(f"depth_edge patch skipped: {e}")
|
| 101 |
+
|
| 102 |
# --- Pre-download checkpoints ---
|
| 103 |
print("Downloading SAM3D checkpoints...")
|
| 104 |
CKPT_DIR = snapshot_download(repo_id="facebook/sam-3d-objects",
|