Skip to content

modosaic.depth.generators.impl.depth_pro

modosaic.depth.generators.impl.depth_pro

DepthPro

DepthPro()

Bases: DepthGenerator

Apple Depth Pro generator.

Load the pinned Depth Pro model and processor.

Source code in modosaic/depth/generators/impl/depth_pro.py
23
24
25
26
27
28
29
30
31
32
33
def __init__(self):
    """Load the pinned Depth Pro model and processor."""
    super().__init__()
    self.model_specs = HFModelSpec(
        model_id="apple/DepthPro-hf",
        revision="de816c8ce7168afcb231f96d501d72b869d0beda",
        dtype=self.dtype,
    )
    self.model = self._load_model()
    self.model = self.model.to(self.device)
    self.processor = self._load_processor()

generate

generate(record)

Generate a normalized depth map for one image record.

Source code in modosaic/depth/generators/impl/depth_pro.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@override
@torch.no_grad()
def generate(self, record: ImageRecord) -> np.ndarray:
    """Generate a normalized depth map for one image record."""
    logger.debug(f"Generating depth for record sample {record.sample_id}")
    img = ImageService.bytes_to_pil(record.image_bytes)
    inputs = self.processor(images=img, return_tensors="pt").to(self.device)
    outputs = self.model(**inputs)

    post_processed_output = self.processor.post_process_depth_estimation(
        outputs, target_sizes=[(img.height, img.width)],
    )
    depth_tensor = post_processed_output[0]["predicted_depth"]
    return DepthPro._post_process(depth_tensor)