A19grey commited on
Commit
d59dba7
·
1 Parent(s): 40c89eb

force depth map to same dims as image

Browse files
Files changed (1) hide show
  1. app.py +13 -25
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
- # **Downsample depth map and image to improve processing speed**
154
- downscale_factor = 2 # Factor by which to downscale (e.g., 2 reduces dimensions by half)
155
- depth = depth[::downscale_factor, ::downscale_factor]
156
- # Convert image tensor to CPU and NumPy for slicing
157
- image_np = image.cpu().detach().numpy()[0].transpose(1, 2, 0)
158
- image_ds = image_np[::downscale_factor, ::downscale_factor, :]
159
- # Update focal length based on downscaling
160
- focallength_px = focallength_px / downscale_factor
161
 
162
- # **Note:** The downscaled image is saved back to the temporary file for consistency
163
- downscaled_image = Image.fromarray((image_ds * 255).astype(np.uint8))
164
- downscaled_image.save(temp_file)
 
 
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)