xiank he commited on
Commit
89a1e10
Β·
1 Parent(s): 33a65b5

distill-any-depth

Browse files
This view is limited to 50 files because it contains too many changes. Β  See raw diff
Files changed (50) hide show
  1. app.py +9 -9
  2. {geobench β†’ distillanydepth}/depth_anything_v2/__pycache__/dinov2.cpython-310.pyc +0 -0
  3. {geobench β†’ distillanydepth}/depth_anything_v2/__pycache__/dpt.cpython-310.pyc +0 -0
  4. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2.py +0 -0
  5. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__init__.py +0 -0
  6. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/__init__.cpython-310.pyc +0 -0
  7. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/attention.cpython-310.pyc +0 -0
  8. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/block.cpython-310.pyc +0 -0
  9. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/drop_path.cpython-310.pyc +0 -0
  10. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/layer_scale.cpython-310.pyc +0 -0
  11. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/mlp.cpython-310.pyc +0 -0
  12. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/patch_embed.cpython-310.pyc +0 -0
  13. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/__pycache__/swiglu_ffn.cpython-310.pyc +0 -0
  14. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/attention.py +0 -0
  15. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/block.py +0 -0
  16. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/drop_path.py +0 -0
  17. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/layer_scale.py +0 -0
  18. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/mlp.py +0 -0
  19. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/patch_embed.py +0 -0
  20. {geobench β†’ distillanydepth}/depth_anything_v2/dinov2_layers/swiglu_ffn.py +0 -0
  21. {geobench β†’ distillanydepth}/depth_anything_v2/dpt.py +0 -0
  22. {geobench β†’ distillanydepth}/depth_anything_v2/util/__pycache__/blocks.cpython-310.pyc +0 -0
  23. {geobench β†’ distillanydepth}/depth_anything_v2/util/__pycache__/transform.cpython-310.pyc +0 -0
  24. {geobench β†’ distillanydepth}/depth_anything_v2/util/blocks.py +0 -0
  25. {geobench β†’ distillanydepth}/depth_anything_v2/util/transform.py +0 -0
  26. {geobench β†’ distillanydepth}/midas/__pycache__/base_model.cpython-310.pyc +0 -0
  27. {geobench β†’ distillanydepth}/midas/__pycache__/blocks.cpython-310.pyc +0 -0
  28. {geobench β†’ distillanydepth}/midas/__pycache__/dpt_depth.cpython-310.pyc +0 -0
  29. {geobench β†’ distillanydepth}/midas/__pycache__/midas_net.cpython-310.pyc +0 -0
  30. {geobench β†’ distillanydepth}/midas/__pycache__/midas_net_custom.cpython-310.pyc +0 -0
  31. {geobench β†’ distillanydepth}/midas/__pycache__/model_loader.cpython-310.pyc +0 -0
  32. {geobench β†’ distillanydepth}/midas/__pycache__/transforms.cpython-310.pyc +0 -0
  33. {geobench β†’ distillanydepth}/midas/backbones/__pycache__/beit.cpython-310.pyc +0 -0
  34. {geobench β†’ distillanydepth}/midas/backbones/__pycache__/levit.cpython-310.pyc +0 -0
  35. {geobench β†’ distillanydepth}/midas/backbones/__pycache__/swin.cpython-310.pyc +0 -0
  36. {geobench β†’ distillanydepth}/midas/backbones/__pycache__/swin2.cpython-310.pyc +0 -0
  37. {geobench β†’ distillanydepth}/midas/backbones/__pycache__/swin_common.cpython-310.pyc +0 -0
  38. {geobench β†’ distillanydepth}/midas/backbones/__pycache__/utils.cpython-310.pyc +0 -0
  39. {geobench β†’ distillanydepth}/midas/backbones/__pycache__/vit.cpython-310.pyc +0 -0
  40. {geobench β†’ distillanydepth}/midas/backbones/beit.py +0 -0
  41. {geobench β†’ distillanydepth}/midas/backbones/levit.py +0 -0
  42. {geobench β†’ distillanydepth}/midas/backbones/next_vit.py +0 -0
  43. {geobench β†’ distillanydepth}/midas/backbones/swin.py +0 -0
  44. {geobench β†’ distillanydepth}/midas/backbones/swin2.py +0 -0
  45. {geobench β†’ distillanydepth}/midas/backbones/swin_common.py +0 -0
  46. {geobench β†’ distillanydepth}/midas/backbones/utils.py +0 -0
  47. {geobench β†’ distillanydepth}/midas/backbones/vit.py +0 -0
  48. {geobench β†’ distillanydepth}/midas/base_model.py +0 -0
  49. {geobench β†’ distillanydepth}/midas/blocks.py +0 -0
  50. {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 geobench.modeling.archs.dam.dam import DepthAnything
7
- from geobench.utils.image_util import colorize_depth_maps
8
- from geobench.midas.transforms import Resize, NormalizeImage, PrepareForNet
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, mode='rel_depth'):
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" if mode != 'metric' else '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, mode='rel_depth'):
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, mode)
57
 
58
  # Create Gradio interface
59
  iface = gr.Interface(
60
  fn=gradio_interface,
61
- inputs=[gr.Image(type="pil"), gr.Dropdown(choices=['rel_depth', 'metric_depth', 'disparity'], label="Mode")],
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