Predictor#

The DepthPredictor class provides fine-grained control over depth prediction.

For most use cases, the top-level panodac.predict() function is sufficient. Use DepthPredictor directly when you need to:

  • Reuse a loaded model across multiple predictions
  • Access the underlying PyTorch model
  • Customize preprocessing behavior

DepthPredictor#

DepthPredictor #

DepthPredictor(model: str = 'outdoor-resnet101', device: Union[str, None] = None, fix_panorama_seam: bool = True)

High-level interface for depth prediction.

Handles model loading, preprocessing, and inference for any camera type.

Parameters:

Name Type Description Default
model str

Model name ('outdoor-resnet101', 'outdoor-swinl', etc.)

'outdoor-resnet101'
device Union[str, None]

Device to use ('cuda', 'mps', 'cpu', or None for auto)

None
fix_panorama_seam bool

If True, apply Poisson blending to correct left-right seam artifacts in ERP panorama depth outputs.

True
Source code in src/panodac/predictor.py
def __init__(
    self,
    model: str = "outdoor-resnet101",
    device: Union[str, None] = None,
    fix_panorama_seam: bool = True,
):
    self.model_name = model
    self.device = get_device(device)
    self.fix_panorama_seam = fix_panorama_seam

    # Download model files
    config_path, weights_path = download_model(model)
    self.config = load_config(config_path)

    # Build and load model
    self._model = self._build_model()
    self._model.load_pretrained(str(weights_path))
    self._model.to(self.device)
    self._model.eval()

    # Get canonical size from config
    self.cano_sz = self.config["model"].get("cano_sz", [1400, 1400])
    self.img_size = self.config["model"]["pixel_encoder"]["img_size"]

__call__ #

__call__(image: Union[str, Path, ndarray, Image]) -> np.ndarray

Predict depth from an image.

Parameters:

Name Type Description Default
image Union[str, Path, ndarray, Image]

Input image (path, numpy array, or PIL Image)

required

Returns:

Type Description
ndarray

Depth map as numpy array (H, W) in meters

Source code in src/panodac/predictor.py
def __call__(
    self,
    image: Union[str, Path, np.ndarray, Image.Image],
) -> np.ndarray:
    """Predict depth from an image.

    Args:
        image: Input image (path, numpy array, or PIL Image)

    Returns:
        Depth map as numpy array (H, W) in meters
    """
    # Load image
    img_np = load_image(image)
    original_h, original_w = img_np.shape[:2]

    # Check if panorama and use appropriate processing
    if is_panorama(img_np):
        return self._predict_panorama(img_np)
    else:
        return self._predict_perspective(img_np)

Usage#

from panodac import DepthPredictor

# Create predictor (model loads once)
predictor = DepthPredictor(model="outdoor-swinl", device="cuda")

# Reuse for multiple images
for image_path in image_paths:
    depth = predictor(image_path)

The top-level panodac.predict() function caches predictors internally, so this is mainly useful when you need direct access to the predictor instance.