Spaces:
Running
Running
Update app.py
Browse files372 unmodified lines373374375376377378379380381382383384385386387388389390372 unmodified linesf"conf is None: {prediction.conf is None}; "f"intrinsics is None: {prediction.intrinsics is None}")depth = prediction.depth[0]# conf is a robustness aid, not a hard requirement -- degrade gracefully# to uniform confidence (median+MAD outlier rejection still applies)# rather than crashing if this build of DA3 doesn't return it.if prediction.conf is not None:conf = prediction.conf[0]else:gr.Warning("Depth confidence map was unavailable from this DA3 build — ""falling back to uniform confidence (outlier rejection still applies).")conf = np.ones_like(depth)# Addition 2: prefer EXIF-derived intrinsics over DA3's estimated ones# when available and requested — a known camera beats a network guess.# Intrinsics are required for 3D back-projection; if DA3 didn't return372 unmodified lines373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405372 unmodified linesf"conf is None: {prediction.conf is None}; "f"intrinsics is None: {prediction.intrinsics is None}")def _to_numpy(t):return t.cpu().numpy() if hasattr(t, "cpu") else np.asarray(t)depth = np.squeeze(_to_numpy(prediction.depth[0])).astype(np.float32)# conf is a robustness aid, not a hard requirement -- degrade gracefully# to uniform confidence (median+MAD outlier rejection still applies)# rather than crashing if this build of DA3 doesn't return it.if prediction.conf is not None:conf = np.squeeze(_to_numpy(prediction.conf[0])).astype(np.float32)else:gr.Warning("Depth confidence map was unavailable from this DA3 build — ""falling back to uniform confidence (outlier rejection still applies).")conf = np.ones_like(depth)# DA3 internally resizes images before its forward pass (see the# "Processed Images" log line), so depth/conf come back at that internal# resolution -- not the original image's. Masks (from SAM3, via# segment_batch's target_sizes=original_sizes) and intrinsics are both in# original-image pixel space, so upsample depth/conf to match before# indexing with the masks below (otherwise mask/depth shapes mismatch and# boolean indexing raises IndexError).target_w, target_h = primary_image.sizeif depth.shape[:2] != (target_h, target_w):depth = cv2.resize(depth, (target_w, target_h), interpolation=cv2.INTER_LINEAR)conf = cv2.resize(conf, (target_w, target_h), interpolation=cv2.INTER_LINEAR)# Addition 2: prefer EXIF-derived intrinsics over DA3's estimated ones# when available and requested — a known camera beats a network guess.# Intrinsics are required for 3D back-projection; if DA3 didn't return
app.py+17-2