A19grey commited on
Commit
182cf21
1 Parent(s): 81f4be8

Added ability to save raw depth output in meters and updated title plot

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -61,15 +61,16 @@ def predict_depth(input_image):
61
  depth = depth.squeeze()
62
 
63
  # Normalize depth for visualization
 
64
  depth_min = np.min(depth)
65
  depth_max = np.max(depth)
66
- depth_normalized = (depth - depth_min) / (depth_max - depth_min)
67
 
68
  # Create a color map
69
  plt.figure(figsize=(10, 10))
70
  plt.imshow(depth_normalized, cmap='viridis')
71
- plt.colorbar(label='Depth')
72
- plt.title('Predicted Depth Map')
73
  plt.axis('off')
74
 
75
  # Save the plot to a file
@@ -77,9 +78,13 @@ def predict_depth(input_image):
77
  plt.savefig(output_path)
78
  plt.close()
79
 
80
- return output_path, f"Focal length: {focallength_px:.2f} pixels"
 
 
 
 
81
  except Exception as e:
82
- return None, f"An error occurred: {str(e)}"
83
  finally:
84
  # Clean up the temporary file
85
  if temp_file and os.path.exists(temp_file):
@@ -89,9 +94,13 @@ def predict_depth(input_image):
89
  iface = gr.Interface(
90
  fn=predict_depth,
91
  inputs=gr.Image(type="filepath"),
92
- outputs=[gr.Image(type="filepath", label="Depth Map"), gr.Textbox(label="Focal Length or Error Message")],
93
- title="DepthPro Demo",
94
- description="[DepthPro](https://huggingface.co/apple/DepthPro) is a fast metric depth prediction model. Simply upload an image to predict its depth map and focal length. Large images will be automatically resized."
 
 
 
 
95
  )
96
 
97
  # Launch the interface
 
61
  depth = depth.squeeze()
62
 
63
  # Normalize depth for visualization
64
+ # agk - No never normalize depth. It is already in meters. EMBRACE REALITY. TOUCH GRASS.
65
  depth_min = np.min(depth)
66
  depth_max = np.max(depth)
67
+ depth_normalized = depth #it is normal to have depth in meters. Normalize reality.
68
 
69
  # Create a color map
70
  plt.figure(figsize=(10, 10))
71
  plt.imshow(depth_normalized, cmap='viridis')
72
+ plt.colorbar(label='Depth [m]')
73
+ plt.title('Predicted Depth Map - Min: {depth_min:.1f}m, Max: {depth_max:.1f}m')
74
  plt.axis('off')
75
 
76
  # Save the plot to a file
 
78
  plt.savefig(output_path)
79
  plt.close()
80
 
81
+ # Save raw depth data as CSV
82
+ raw_depth_path = "raw_depth_map.csv"
83
+ np.savetxt(raw_depth_path, depth, delimiter=',')
84
+
85
+ return output_path, f"Focal length: {focallength_px:.2f} pixels", raw_depth_path
86
  except Exception as e:
87
+ return None, f"An error occurred: {str(e)}", None
88
  finally:
89
  # Clean up the temporary file
90
  if temp_file and os.path.exists(temp_file):
 
94
  iface = gr.Interface(
95
  fn=predict_depth,
96
  inputs=gr.Image(type="filepath"),
97
+ outputs=[
98
+ gr.Image(type="filepath", label="Depth Map"),
99
+ gr.Textbox(label="Focal Length or Error Message"),
100
+ gr.File(label="Download Raw Depth Map (CSV)")
101
+ ],
102
+ title="DepthPro Demo in Meters",
103
+ description="[DepthPro](https://huggingface.co/apple/DepthPro) is a fast metric depth prediction model. Simply upload an image to predict its depth map and focal length. Large images will be automatically resized. You can also download the raw depth map data as a CSV file."
104
  )
105
 
106
  # Launch the interface