pablovela5620 commited on
Commit
feead7a
·
verified ·
1 Parent(s): cdfdf9c

Upload gradio_app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. gradio_app.py +18 -10
gradio_app.py CHANGED
@@ -1,15 +1,6 @@
1
  import gradio as gr
2
  import numpy as np
3
-
4
- try:
5
- import spaces # type: ignore
6
-
7
- IN_SPACES = True
8
- except ImportError:
9
- print("Not running on Zero")
10
- IN_SPACES = False
11
  import torch
12
-
13
  from monopriors.relative_depth_models import (
14
  RelativeDepthPrediction,
15
  get_relative_predictor,
@@ -27,6 +18,15 @@ from typing import Literal, get_args
27
  import gc
28
 
29
  from jaxtyping import UInt8
 
 
 
 
 
 
 
 
 
30
 
31
  title = "# Depth Comparison"
32
  description1 = """Demo to help compare different depth models. Including both Scale | Shift Invariant and Metric Depth types."""
@@ -38,7 +38,7 @@ DEVICE: Literal["cuda"] | Literal["cpu"] = (
38
  MODELS_TO_SKIP: list[str] = []
39
  if gr.NO_RELOAD:
40
  MODEL_1 = get_relative_predictor("DepthAnythingV2Predictor")(device=DEVICE)
41
- MODEL_2 = get_relative_predictor("Metric3DRelativePredictor")(device=DEVICE)
42
 
43
 
44
  def predict_depth(
@@ -95,6 +95,14 @@ def on_submit(rgb: UInt8[np.ndarray, "h w 3"]):
95
  models_list = [MODEL_1, MODEL_2]
96
  blueprint = create_depth_comparison_blueprint(models_list)
97
  rr.send_blueprint(blueprint)
 
 
 
 
 
 
 
 
98
  try:
99
  for model in models_list:
100
  # get the name of the model
 
1
  import gradio as gr
2
  import numpy as np
 
 
 
 
 
 
 
 
3
  import torch
 
4
  from monopriors.relative_depth_models import (
5
  RelativeDepthPrediction,
6
  get_relative_predictor,
 
18
  import gc
19
 
20
  from jaxtyping import UInt8
21
+ import mmcv
22
+
23
+ try:
24
+ import spaces # type: ignore
25
+
26
+ IN_SPACES = True
27
+ except ImportError:
28
+ print("Not running on Zero")
29
+ IN_SPACES = False
30
 
31
  title = "# Depth Comparison"
32
  description1 = """Demo to help compare different depth models. Including both Scale | Shift Invariant and Metric Depth types."""
 
38
  MODELS_TO_SKIP: list[str] = []
39
  if gr.NO_RELOAD:
40
  MODEL_1 = get_relative_predictor("DepthAnythingV2Predictor")(device=DEVICE)
41
+ MODEL_2 = get_relative_predictor("UniDepthRelativePredictor")(device=DEVICE)
42
 
43
 
44
  def predict_depth(
 
95
  models_list = [MODEL_1, MODEL_2]
96
  blueprint = create_depth_comparison_blueprint(models_list)
97
  rr.send_blueprint(blueprint)
98
+
99
+ # resize the image to have a max dim of 1024
100
+ max_dim = 1024
101
+ current_dim = max(rgb.shape[0], rgb.shape[1])
102
+ if current_dim > max_dim:
103
+ scale_factor = max_dim / current_dim
104
+ rgb = mmcv.imrescale(img=rgb, scale=scale_factor)
105
+
106
  try:
107
  for model in models_list:
108
  # get the name of the model