Skip to content

model

model #

Model — a learned depth model as a value: the driver that runs it and the weights it loads.

  1. Driver. A Driver is the capturegraph-free script itself, a file hashed by its bytes, so editing it invalidates every prediction it made.
  2. Weights. Weights names a Hugging Face repository at one commit, which is how the weights are content-addressed without hashing gigabytes; snapshot downloads them into the scratch.
  3. Model. The two together are the Model a page passes to predict and multiview; the built-in DA3_LARGE and PI3X are values like any a user constructs.

DA3_LARGE = Model(driver=(Driver(DRIVERS / 'depth_anything_3.py')), weights=(Weights(repo_id='depth-anything/DA3-LARGE', revision='c54c26b16ec04d218e8d584ecf4bce082a9fcc20'))) module-attribute #

Depth Anything 3, large: monocular and multi-view.

PI3X = Model(driver=(Driver(DRIVERS / 'pi3.py')), weights=(Weights(repo_id='yyfz233/Pi3X', revision='bb1deea4d7423de5b30691739cb451a3f57dc1d5'))) module-attribute #

Pi3X: multi-view, run one image at a time when monocular.

Driver #

Bases: FileScalar

A depth driver script, honouring the cgr.depth contract, hashed by its bytes.

Analysis-only: code, never captured, so it has no platform mirror and no place in a schema.

Source code in capturegraph-recipes/capturegraph_recipes/depth/models/model.py
class Driver(cg.FileScalar, name="edu.cornell.depth_driver", extensions=("py",)):
    """A depth driver script, honouring the ``cgr.depth`` contract, hashed by its bytes.

    Analysis-only: code, never captured, so it has no platform mirror and no
    place in a schema.
    """

    __slots__ = ()

    analysis_only = True

Model #

Bases: Struct

A learned depth model: its driver and its weights.

mine = cgr.depth.Model(
    driver=cgr.depth.Driver("my_driver.py"),
    weights=cgr.depth.Weights(repo_id="me/my-weights", revision="0123abcd…"),
)
Source code in capturegraph-recipes/capturegraph_recipes/depth/models/model.py
class Model(cg.Struct):
    """A learned depth model: its driver and its weights.

    ```python
    mine = cgr.depth.Model(
        driver=cgr.depth.Driver("my_driver.py"),
        weights=cgr.depth.Weights(repo_id="me/my-weights", revision="0123abcd…"),
    )
    ```
    """

    driver: Driver
    weights: Weights

Weights #

Bases: JSONScalar

A Hugging Face repository at one commit.

revision is a full commit hash, never a branch name: it is what identifies the weights everywhere they are cached, and a floating "main" would name the snapshot first downloaded forever.

Attributes:

Name Type Description
repo_id str

The repository, "owner/name".

revision str

The 40-hex commit hash of the weights.

Raises:

Type Description
ValueError

If repo_id is not "owner/name" or revision is not a full lowercase commit hash.

Source code in capturegraph-recipes/capturegraph_recipes/depth/models/model.py
class Weights(cg.JSONScalar, name="edu.cornell.hugging_face_weights"):
    """A Hugging Face repository at one commit.

    ``revision`` is a full commit hash, never a branch name: it is what
    identifies the weights everywhere they are cached, and a floating
    ``"main"`` would name the snapshot first downloaded forever.

    Attributes:
        repo_id: The repository, ``"owner/name"``.
        revision: The 40-hex commit hash of the weights.

    Raises:
        ValueError: If ``repo_id`` is not ``"owner/name"`` or ``revision`` is
            not a full lowercase commit hash.
    """

    repo_id: str
    revision: str

    analysis_only = True

    def __post_init__(self) -> None:
        """Reject a repository that is not ``owner/name`` or a revision that is not a commit."""
        if not isinstance(self.repo_id, str) or self.repo_id.count("/") != 1:
            raise ValueError(f"Weights.repo_id must be 'owner/name', got {self.repo_id!r}")
        if not isinstance(self.revision, str) or COMMIT_HASH.fullmatch(self.revision) is None:
            raise ValueError(
                f"Weights.revision must be a 40-hex commit hash, not a branch name; "
                f"got {self.revision!r}"
            )

__post_init__() #

Reject a repository that is not owner/name or a revision that is not a commit.

Source code in capturegraph-recipes/capturegraph_recipes/depth/models/model.py
def __post_init__(self) -> None:
    """Reject a repository that is not ``owner/name`` or a revision that is not a commit."""
    if not isinstance(self.repo_id, str) or self.repo_id.count("/") != 1:
        raise ValueError(f"Weights.repo_id must be 'owner/name', got {self.repo_id!r}")
    if not isinstance(self.revision, str) or COMMIT_HASH.fullmatch(self.revision) is None:
        raise ValueError(
            f"Weights.revision must be a 40-hex commit hash, not a branch name; "
            f"got {self.revision!r}"
        )