Spaces:
Running
on
Zero
Running
on
Zero
force depth map to same dims as image
Browse files
app.py
CHANGED
|
@@ -111,20 +111,6 @@ def generate_3d_model(depth, image_path, focallength_px):
|
|
| 111 |
|
| 112 |
@spaces.GPU(duration=20)
|
| 113 |
def predict_depth(input_image):
|
| 114 |
-
"""
|
| 115 |
-
Predict the depth map from the input image, generate visualizations and a 3D model.
|
| 116 |
-
|
| 117 |
-
Args:
|
| 118 |
-
input_image (str): Path to the input image file.
|
| 119 |
-
|
| 120 |
-
Returns:
|
| 121 |
-
tuple:
|
| 122 |
-
- str: Path to the depth map image.
|
| 123 |
-
- str: Focal length in pixels or an error message.
|
| 124 |
-
- str: Path to the raw depth data CSV file.
|
| 125 |
-
- str: Path to the generated 3D model file for viewing.
|
| 126 |
-
- str: Path to the downloadable 3D model file.
|
| 127 |
-
"""
|
| 128 |
temp_file = None
|
| 129 |
try:
|
| 130 |
# Resize the input image to a manageable size
|
|
@@ -150,18 +136,20 @@ def predict_depth(input_image):
|
|
| 150 |
if depth.ndim != 2:
|
| 151 |
depth = depth.squeeze()
|
| 152 |
|
| 153 |
-
#
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
| 165 |
|
| 166 |
# No normalization of depth map as it is already in meters
|
| 167 |
depth_min = np.min(depth)
|
|
|
|
| 111 |
|
| 112 |
@spaces.GPU(duration=20)
|
| 113 |
def predict_depth(input_image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
temp_file = None
|
| 115 |
try:
|
| 116 |
# Resize the input image to a manageable size
|
|
|
|
| 136 |
if depth.ndim != 2:
|
| 137 |
depth = depth.squeeze()
|
| 138 |
|
| 139 |
+
# Print debug information
|
| 140 |
+
print(f"Depth shape: {depth.shape}")
|
| 141 |
+
print(f"Image shape: {image.shape}")
|
| 142 |
+
|
| 143 |
+
# Ensure depth and image have the same dimensions
|
| 144 |
+
if depth.shape != image.shape[2:]:
|
| 145 |
+
# Resize depth to match image dimensions
|
| 146 |
+
depth = np.resize(depth, image.shape[2:])
|
| 147 |
|
| 148 |
+
# No downsampling
|
| 149 |
+
downscale_factor = 1
|
| 150 |
+
|
| 151 |
+
# Convert image tensor to CPU and NumPy
|
| 152 |
+
image_np = image.cpu().detach().numpy()[0].transpose(1, 2, 0)
|
| 153 |
|
| 154 |
# No normalization of depth map as it is already in meters
|
| 155 |
depth_min = np.min(depth)
|