Skip to content

modosaic.depth.generators.impl.depth_anything_v2_small

modosaic.depth.generators.impl.depth_anything_v2_small

DepthAnythingV2Small

DepthAnythingV2Small()

Bases: DepthGenerator

Depth Anything V2 Small generator.

Load the pinned Hugging Face depth-estimation pipeline.

Source code in modosaic/depth/generators/impl/depth_anything_v2_small.py
20
21
22
23
24
25
26
27
28
def __init__(self):
    """Load the pinned Hugging Face depth-estimation pipeline."""
    super().__init__()
    self.model_specs = HFModelSpec(
        model_id="depth-anything/Depth-Anything-V2-Small-hf",
        revision="5426e4f0f36572d16453bbda7a8389317b1bef99",
        dtype=self.pipeline_dtype,
    )
    self.pipeline = self._load_pipeline()

generate

generate(record)

Generate a depth map for one image record.

Source code in modosaic/depth/generators/impl/depth_anything_v2_small.py
40
41
42
43
44
45
46
47
48
@override
def generate(self, record: ImageRecord) -> np.ndarray:
    """Generate a depth map for one image record."""
    logger.debug(f"Generating depth anything small image for record sample {record.sample_id}")
    img = ImageService.bytes_to_pil(record.image_bytes)
    depth_tensor = self.pipeline(img)["predicted_depth"]

    np_depth = depth_tensor.detach().cpu().float().numpy()
    return np_depth