Update app.py
Browse files
app.py
CHANGED
|
@@ -60,20 +60,21 @@ def predict_depth(input_image):
|
|
| 60 |
if depth.ndim != 2:
|
| 61 |
depth = depth.squeeze()
|
| 62 |
|
| 63 |
-
#
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
| 68 |
# Create a color map
|
| 69 |
plt.figure(figsize=(10, 10))
|
| 70 |
-
plt.imshow(
|
| 71 |
-
plt.colorbar(label='Depth')
|
| 72 |
-
plt.title('Predicted Depth Map')
|
| 73 |
plt.axis('off')
|
| 74 |
|
| 75 |
# Save the plot to a file
|
| 76 |
-
output_path = "
|
| 77 |
plt.savefig(output_path)
|
| 78 |
plt.close()
|
| 79 |
|
|
@@ -89,9 +90,9 @@ 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
|
|
|
|
| 60 |
if depth.ndim != 2:
|
| 61 |
depth = depth.squeeze()
|
| 62 |
|
| 63 |
+
# Calculate inverse depth
|
| 64 |
+
inverse_depth = 1.0 / depth
|
| 65 |
+
|
| 66 |
+
# Clip inverse depth to 0-10 range
|
| 67 |
+
inverse_depth_clipped = np.clip(inverse_depth, 0, 10)
|
| 68 |
+
|
| 69 |
# Create a color map
|
| 70 |
plt.figure(figsize=(10, 10))
|
| 71 |
+
plt.imshow(inverse_depth_clipped, cmap='viridis')
|
| 72 |
+
plt.colorbar(label='Inverse Depth')
|
| 73 |
+
plt.title('Predicted Inverse Depth Map')
|
| 74 |
plt.axis('off')
|
| 75 |
|
| 76 |
# Save the plot to a file
|
| 77 |
+
output_path = "inverse_depth_map.png"
|
| 78 |
plt.savefig(output_path)
|
| 79 |
plt.close()
|
| 80 |
|
|
|
|
| 90 |
iface = gr.Interface(
|
| 91 |
fn=predict_depth,
|
| 92 |
inputs=gr.Image(type="filepath"),
|
| 93 |
+
outputs=[gr.Image(type="filepath", label="Inverse Depth Map"), gr.Textbox(label="Focal Length or Error Message")],
|
| 94 |
title="DepthPro Demo",
|
| 95 |
+
description="[DepthPro](https://huggingface.co/apple/DepthPro) is a fast metric depth prediction model. Simply upload an image to predict its inverse depth map and focal length. Large images will be automatically resized."
|
| 96 |
)
|
| 97 |
|
| 98 |
# Launch the interface
|