| 8 | from models.fastmodel import MoGe |
| 9 | |
| 10 | def infer_monodepth(file: str, model: MoGe, hydra_cfg: DictConfig): |
| 11 | device = hydra_cfg.device |
| 12 | |
| 13 | image = cv2.imread(file) |
| 14 | image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) |
| 15 | height, width = image.shape[:2] |
| 16 | if hasattr(hydra_cfg, 'load_img_size'): |
| 17 | resize_to = hydra_cfg.load_img_size |
| 18 | height, width = min(resize_to, int(resize_to * height / width)), min(resize_to, int(resize_to * width / height)) |
| 19 | image = cv2.resize(image, (width, height), cv2.INTER_AREA) |
| 20 | image_tensor = torch.tensor(image / 255, dtype=torch.float32, device=device).permute(2, 0, 1) |
| 21 | |
| 22 | # Inference |
| 23 | output = model.model.infer(image_tensor, apply_mask=False) |
| 24 | # points, depth, mask, intrinsics = output['points'].cpu().numpy(), output['depth'].cpu().numpy(), output['mask'].cpu().numpy(), output['intrinsics'].cpu().numpy() |
| 25 | return output['depth'] |