Spaces:
Running
on
Zero
Running
on
Zero
xiank he
commited on
Commit
Β·
89a1e10
1
Parent(s):
33a65b5
distill-any-depth
Browse filesThis view is limited to 50 files because it contains too many changes. Β
See raw diff
- app.py +9 -9
- {geobench β distillanydepth}/depth_anything_v2/__pycache__/dinov2.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/__pycache__/dpt.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__init__.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/__init__.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/attention.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/block.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/drop_path.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/layer_scale.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/mlp.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/patch_embed.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/swiglu_ffn.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/attention.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/block.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/drop_path.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/layer_scale.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/mlp.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/patch_embed.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dinov2_layers/swiglu_ffn.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/dpt.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/util/__pycache__/blocks.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/util/__pycache__/transform.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/depth_anything_v2/util/blocks.py +0 -0
- {geobench β distillanydepth}/depth_anything_v2/util/transform.py +0 -0
- {geobench β distillanydepth}/midas/__pycache__/base_model.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/__pycache__/blocks.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/__pycache__/dpt_depth.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/__pycache__/midas_net.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/__pycache__/midas_net_custom.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/__pycache__/model_loader.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/__pycache__/transforms.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/__pycache__/beit.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/__pycache__/levit.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/__pycache__/swin.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/__pycache__/swin2.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/__pycache__/swin_common.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/__pycache__/utils.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/__pycache__/vit.cpython-310.pyc +0 -0
- {geobench β distillanydepth}/midas/backbones/beit.py +0 -0
- {geobench β distillanydepth}/midas/backbones/levit.py +0 -0
- {geobench β distillanydepth}/midas/backbones/next_vit.py +0 -0
- {geobench β distillanydepth}/midas/backbones/swin.py +0 -0
- {geobench β distillanydepth}/midas/backbones/swin2.py +0 -0
- {geobench β distillanydepth}/midas/backbones/swin_common.py +0 -0
- {geobench β distillanydepth}/midas/backbones/utils.py +0 -0
- {geobench β distillanydepth}/midas/backbones/vit.py +0 -0
- {geobench β distillanydepth}/midas/base_model.py +0 -0
- {geobench β distillanydepth}/midas/blocks.py +0 -0
- {geobench β distillanydepth}/midas/dpt_depth.py +0 -0
app.py
CHANGED
|
@@ -3,9 +3,9 @@ import torch
|
|
| 3 |
from PIL import Image
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
| 6 |
-
from
|
| 7 |
-
from
|
| 8 |
-
from
|
| 9 |
from torchvision.transforms import Compose
|
| 10 |
import os
|
| 11 |
|
|
@@ -21,7 +21,7 @@ def load_model_by_name(arch_name, checkpoint_path, device):
|
|
| 21 |
return model
|
| 22 |
|
| 23 |
# Image processing function (same as your original code, modified for Gradio)
|
| 24 |
-
def process_image(image, model, device
|
| 25 |
# Preprocess the image
|
| 26 |
image_np = np.array(image)[..., ::-1] / 255
|
| 27 |
transform = Compose([
|
|
@@ -39,7 +39,7 @@ def process_image(image, model, device, mode='rel_depth'):
|
|
| 39 |
pred_disp = (pred_disp_np - pred_disp_np.min()) / (pred_disp_np.max() - pred_disp_np.min())
|
| 40 |
|
| 41 |
# Colorize depth map
|
| 42 |
-
cmap = "Spectral_r"
|
| 43 |
depth_colored = colorize_depth_maps(pred_disp[None, ...], 0, 1, cmap=cmap).squeeze()
|
| 44 |
depth_colored = (depth_colored * 255).astype(np.uint8)
|
| 45 |
|
|
@@ -47,22 +47,22 @@ def process_image(image, model, device, mode='rel_depth'):
|
|
| 47 |
return depth_image
|
| 48 |
|
| 49 |
# Gradio interface function
|
| 50 |
-
def gradio_interface(image
|
| 51 |
# Set device to CPU explicitly
|
| 52 |
device = torch.device("cpu") # Force using CPU
|
| 53 |
model = load_model_by_name("depthanything", "your_checkpoint_path_here", device)
|
| 54 |
|
| 55 |
# Process image and return output
|
| 56 |
-
return process_image(image, model, device
|
| 57 |
|
| 58 |
# Create Gradio interface
|
| 59 |
iface = gr.Interface(
|
| 60 |
fn=gradio_interface,
|
| 61 |
-
inputs=
|
| 62 |
outputs=gr.Image(type="pil"),
|
| 63 |
title="Depth Estimation Demo",
|
| 64 |
description="Upload an image to see the depth estimation results."
|
| 65 |
)
|
| 66 |
|
| 67 |
# Launch the Gradio interface
|
| 68 |
-
iface.launch()
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
| 6 |
+
from distillanydepth.modeling.archs.dam.dam import DepthAnything
|
| 7 |
+
from distillanydepth.utils.image_util import colorize_depth_maps
|
| 8 |
+
from distillanydepth.midas.transforms import Resize, NormalizeImage, PrepareForNet
|
| 9 |
from torchvision.transforms import Compose
|
| 10 |
import os
|
| 11 |
|
|
|
|
| 21 |
return model
|
| 22 |
|
| 23 |
# Image processing function (same as your original code, modified for Gradio)
|
| 24 |
+
def process_image(image, model, device):
|
| 25 |
# Preprocess the image
|
| 26 |
image_np = np.array(image)[..., ::-1] / 255
|
| 27 |
transform = Compose([
|
|
|
|
| 39 |
pred_disp = (pred_disp_np - pred_disp_np.min()) / (pred_disp_np.max() - pred_disp_np.min())
|
| 40 |
|
| 41 |
# Colorize depth map
|
| 42 |
+
cmap = "Spectral_r" # Default colormap for relative depth
|
| 43 |
depth_colored = colorize_depth_maps(pred_disp[None, ...], 0, 1, cmap=cmap).squeeze()
|
| 44 |
depth_colored = (depth_colored * 255).astype(np.uint8)
|
| 45 |
|
|
|
|
| 47 |
return depth_image
|
| 48 |
|
| 49 |
# Gradio interface function
|
| 50 |
+
def gradio_interface(image):
|
| 51 |
# Set device to CPU explicitly
|
| 52 |
device = torch.device("cpu") # Force using CPU
|
| 53 |
model = load_model_by_name("depthanything", "your_checkpoint_path_here", device)
|
| 54 |
|
| 55 |
# Process image and return output
|
| 56 |
+
return process_image(image, model, device)
|
| 57 |
|
| 58 |
# Create Gradio interface
|
| 59 |
iface = gr.Interface(
|
| 60 |
fn=gradio_interface,
|
| 61 |
+
inputs=gr.Image(type="pil"), # Only image input, no mode selection
|
| 62 |
outputs=gr.Image(type="pil"),
|
| 63 |
title="Depth Estimation Demo",
|
| 64 |
description="Upload an image to see the depth estimation results."
|
| 65 |
)
|
| 66 |
|
| 67 |
# Launch the Gradio interface
|
| 68 |
+
iface.launch()
|
{geobench β distillanydepth}/depth_anything_v2/__pycache__/dinov2.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/__pycache__/dpt.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__init__.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/__init__.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/attention.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/block.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/drop_path.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/layer_scale.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/mlp.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/patch_embed.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/swiglu_ffn.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/attention.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/block.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/drop_path.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/layer_scale.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/mlp.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/patch_embed.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dinov2_layers/swiglu_ffn.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/dpt.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/util/__pycache__/blocks.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/util/__pycache__/transform.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/util/blocks.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/depth_anything_v2/util/transform.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/__pycache__/base_model.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/__pycache__/blocks.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/__pycache__/dpt_depth.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/__pycache__/midas_net.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/__pycache__/midas_net_custom.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/__pycache__/model_loader.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/__pycache__/transforms.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/__pycache__/beit.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/__pycache__/levit.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/__pycache__/swin.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/__pycache__/swin2.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/__pycache__/swin_common.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/__pycache__/utils.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/__pycache__/vit.cpython-310.pyc
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/beit.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/levit.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/next_vit.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/swin.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/swin2.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/swin_common.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/utils.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/backbones/vit.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/base_model.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/blocks.py
RENAMED
|
File without changes
|
{geobench β distillanydepth}/midas/dpt_depth.py
RENAMED
|
File without changes
|