ameythakur commited on
Commit
d0568d6
·
verified ·
1 Parent(s): 5af56ca

text2video

Browse files
Source Code/annotator/midas/__init__.py CHANGED
@@ -8,13 +8,14 @@ from .api import MiDaSInference
8
 
9
  class MidasDetector:
10
  def __init__(self):
11
- self.model = MiDaSInference(model_type="dpt_hybrid").cuda()
 
12
 
13
  def __call__(self, input_image, a=np.pi * 2.0, bg_th=0.1):
14
  assert input_image.ndim == 3
15
  image_depth = input_image
16
  with torch.no_grad():
17
- image_depth = torch.from_numpy(image_depth).float().cuda()
18
  image_depth = image_depth / 127.5 - 1.0
19
  image_depth = rearrange(image_depth, 'h w c -> 1 c h w')
20
  depth = self.model(image_depth)[0]
 
8
 
9
  class MidasDetector:
10
  def __init__(self):
11
+ self.device = "cuda" if torch.cuda.is_available() else "cpu"
12
+ self.model = MiDaSInference(model_type="dpt_hybrid").to(self.device)
13
 
14
  def __call__(self, input_image, a=np.pi * 2.0, bg_th=0.1):
15
  assert input_image.ndim == 3
16
  image_depth = input_image
17
  with torch.no_grad():
18
+ image_depth = torch.from_numpy(image_depth).float().to(self.device)
19
  image_depth = image_depth / 127.5 - 1.0
20
  image_depth = rearrange(image_depth, 'h w c -> 1 c h w')
21
  depth = self.model(image_depth)[0]
Source Code/annotator/midas/api.py CHANGED
@@ -89,8 +89,13 @@ def load_model(model_type):
89
  normalization = NormalizeImage(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
90
 
91
  elif model_type == "dpt_hybrid": # DPT-Hybrid
 
 
 
92
  if not os.path.exists(model_path):
93
- raise FileNotFoundError(f"MiDaS DPT Hybrid model not found at {model_path}. Please ensure dpt_hybrid-midas-501f0c75.pt is present in annotator/ckpts/.")
 
 
94
 
95
  model = DPTDepthModel(
96
  path=model_path,
 
89
  normalization = NormalizeImage(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
90
 
91
  elif model_type == "dpt_hybrid": # DPT-Hybrid
92
+ if not os.path.exists(annotator_ckpts_path):
93
+ os.makedirs(annotator_ckpts_path)
94
+
95
  if not os.path.exists(model_path):
96
+ from torch.hub import download_url_to_file
97
+ print(f"Downloading MiDaS DPT Hybrid from {remote_model_path}...")
98
+ download_url_to_file(remote_model_path, model_path)
99
 
100
  model = DPTDepthModel(
101
  path=model_path,