A19grey commited on
Commit
4322221
1 Parent(s): 3f2f727

more debugging for CUDA being initialized outside of hugging space domain

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -22,7 +22,7 @@ subprocess.run(["bash", "get_pretrained_models.sh"])
22
 
23
  @spaces.GPU(duration=30)
24
  def load_model_and_predict(image_path):
25
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
26
  model, transform = depth_pro.create_model_and_transforms()
27
  model = model.to(device)
28
  model.eval()
@@ -219,6 +219,7 @@ def predict_depth(input_image):
219
  print(f"Resized image path: {temp_file}")
220
 
221
  depth, focallength_px = load_model_and_predict(temp_file)
 
222
 
223
  if depth.ndim != 2:
224
  depth = depth.squeeze()
@@ -236,9 +237,14 @@ def predict_depth(input_image):
236
  plt.close()
237
 
238
  raw_depth_path = "raw_depth_map.csv"
239
- np.savetxt(raw_depth_path, depth, delimiter=',')
 
 
 
 
240
 
241
  print("Depth map created!")
 
242
  return output_path, f"Focal length: {focallength_px:.2f} pixels", raw_depth_path, temp_file, focallength_px
243
  except Exception as e:
244
  import traceback
@@ -248,6 +254,7 @@ def predict_depth(input_image):
248
  finally:
249
  if temp_file and os.path.exists(temp_file):
250
  os.remove(temp_file)
 
251
 
252
  @spaces.GPU(duration=30)
253
  def create_3d_model(depth_csv, image_path, focallength_px, simplification_factor, smoothing_iterations, thin_threshold):
 
22
 
23
  @spaces.GPU(duration=30)
24
  def load_model_and_predict(image_path):
25
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
26
  model, transform = depth_pro.create_model_and_transforms()
27
  model = model.to(device)
28
  model.eval()
 
219
  print(f"Resized image path: {temp_file}")
220
 
221
  depth, focallength_px = load_model_and_predict(temp_file)
222
+ print(f"Raw depth type: {type(depth)}, focallength_px type: {type(focallength_px)}")
223
 
224
  if depth.ndim != 2:
225
  depth = depth.squeeze()
 
237
  plt.close()
238
 
239
  raw_depth_path = "raw_depth_map.csv"
240
+ np.savetxt(raw_depth_path, depth.cpu().numpy() if isinstance(depth, torch.Tensor) else depth, delimiter=',')
241
+ print(f"Saved raw depth map to {raw_depth_path}")
242
+
243
+ focallength_px = float(focallength_px)
244
+ print(f"Converted focallength_px to float: {focallength_px}")
245
 
246
  print("Depth map created!")
247
+ print(f"Returning - output_path: {output_path}, focallength_px: {focallength_px}, raw_depth_path: {raw_depth_path}, temp_file: {temp_file}")
248
  return output_path, f"Focal length: {focallength_px:.2f} pixels", raw_depth_path, temp_file, focallength_px
249
  except Exception as e:
250
  import traceback
 
254
  finally:
255
  if temp_file and os.path.exists(temp_file):
256
  os.remove(temp_file)
257
+ print(f"Removed temporary file: {temp_file}")
258
 
259
  @spaces.GPU(duration=30)
260
  def create_3d_model(depth_csv, image_path, focallength_px, simplification_factor, smoothing_iterations, thin_threshold):