Spaces:
Running
Running
move model files outside the folder
Browse files- app.py +28 -1
- model/depth_estimation.py → depth_estimation.py +0 -0
- model/__init__.py +0 -28
- model/segmentation.py → segmentation.py +0 -0
app.py
CHANGED
|
@@ -1,5 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
color_maps = [
|
| 5 |
'viridis', 'plasma', 'inferno', 'magma', 'cividis',
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from segmentation import predict as segmentation_predict
|
| 6 |
+
from depth_estimation import predict as depth_estimation_predict
|
| 7 |
+
|
| 8 |
+
def predict(image, color_map):
|
| 9 |
+
# inference
|
| 10 |
+
|
| 11 |
+
mask_image = segmentation_predict(image)
|
| 12 |
+
|
| 13 |
+
segmented_image = Image.composite(
|
| 14 |
+
image,
|
| 15 |
+
Image.new("RGB", image.size, (0, 0, 0)),
|
| 16 |
+
mask_image.convert("L")
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
depth_image = depth_estimation_predict(segmented_image)
|
| 20 |
+
|
| 21 |
+
# apply matplotlib colormap (e.g., viridis)
|
| 22 |
+
depth_array = np.array(depth_image) # Convert PIL image to NumPy array
|
| 23 |
+
colormap = plt.get_cmap(color_map) # Choose a colormap
|
| 24 |
+
depth_colored = colormap(depth_array[:, :, 0] / 255.0) # Normalize and apply colormap
|
| 25 |
+
depth_colored = (depth_colored * 255).astype(np.uint8) # Convert to RGB (discard alpha)
|
| 26 |
+
|
| 27 |
+
depth_colored = Image.fromarray(depth_colored)
|
| 28 |
+
|
| 29 |
+
return depth_colored
|
| 30 |
|
| 31 |
color_maps = [
|
| 32 |
'viridis', 'plasma', 'inferno', 'magma', 'cividis',
|
model/depth_estimation.py → depth_estimation.py
RENAMED
|
File without changes
|
model/__init__.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
from PIL import Image
|
| 2 |
-
import numpy as np
|
| 3 |
-
import matplotlib.pyplot as plt
|
| 4 |
-
from segmentation import predict as segmentation_predict
|
| 5 |
-
from depth_estimation import predict as depth_estimation_predict
|
| 6 |
-
|
| 7 |
-
def predict(image, color_map):
|
| 8 |
-
# inference
|
| 9 |
-
|
| 10 |
-
mask_image = segmentation_predict(image)
|
| 11 |
-
|
| 12 |
-
segmented_image = Image.composite(
|
| 13 |
-
image,
|
| 14 |
-
Image.new("RGB", image.size, (0, 0, 0)),
|
| 15 |
-
mask_image.convert("L")
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
depth_image = depth_estimation_predict(segmented_image)
|
| 19 |
-
|
| 20 |
-
# apply matplotlib colormap (e.g., viridis)
|
| 21 |
-
depth_array = np.array(depth_image) # Convert PIL image to NumPy array
|
| 22 |
-
colormap = plt.get_cmap(color_map) # Choose a colormap
|
| 23 |
-
depth_colored = colormap(depth_array[:, :, 0] / 255.0) # Normalize and apply colormap
|
| 24 |
-
depth_colored = (depth_colored * 255).astype(np.uint8) # Convert to RGB (discard alpha)
|
| 25 |
-
|
| 26 |
-
depth_colored = Image.fromarray(depth_colored)
|
| 27 |
-
|
| 28 |
-
return depth_colored
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model/segmentation.py → segmentation.py
RENAMED
|
File without changes
|