File size: 1,503 Bytes
2b156ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# ---------------------------------------------------------------------
# Copyright (c) 2026 Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
# ---------------------------------------------------------------------

from __future__ import annotations

import numpy as np

from qai_hub_models.utils.asset_loaders import load_image

from .app import DepthProApp
from .demo import INPUT_IMAGE_ADDRESS
from .demo import main as demo_main
from .model import DepthPro


def test_task() -> None:
    """Run torch DepthPro end-to-end on the sample fixture.

    Sanity-checks that the pipeline resolves the HF weights, produces a
    depth map at the network's native 1536x1536 unpadded to the original
    input resolution, and yields a plausible field of view (roughly the
    range Apple demos on natural imagery, 30-100 degrees).
    """
    model = DepthPro.from_pretrained()
    (_, _, height, width) = model.get_input_spec()["image"][0]
    app = DepthProApp(model, height, width)
    image = load_image(INPUT_IMAGE_ADDRESS)
    prediction = app.estimate_depth(image)

    assert prediction.depth.ndim == 2
    assert prediction.depth.shape == (image.size[1], image.size[0])
    assert np.all(np.isfinite(prediction.depth))
    assert prediction.depth.min() > 0

    assert 10.0 < prediction.field_of_view < 170.0
    assert prediction.focal_length_px > 0

    assert prediction.heatmap.size == image.size


def test_demo() -> None:
    demo_main(is_test=True)