Spaces:
Running on Zero
Running on Zero
New model id and weight file name (l-dpt_large_depth_zeroshot)
Browse files- README.md +5 -4
- ldpt/models/l_dpt/api.py +28 -13
- ldpt/models/l_dpt/convert.py +14 -11
- ldpt/models/l_dpt/presets.py +46 -20
- ldpt/models/l_dpt/weights.py +3 -2
- models.json +4 -4
- space_utils.py +10 -10
README.md
CHANGED
|
@@ -26,10 +26,11 @@ output is relative depth: larger = farther, up to a scale and shift.
|
|
| 26 |
|
| 27 |
## Model
|
| 28 |
|
| 29 |
-
L-DPT-L zero-shot
|
|
|
|
| 30 |
DINOv3 ViT-7B/16 (frozen) + a 271 M-parameter decoder, trained at 768 px on synthetic and
|
| 31 |
-
multi-view data only. `models.json` can list more release files (e.g.
|
| 32 |
-
with more than one the UI offers a choice.
|
| 33 |
|
| 34 |
## Setup
|
| 35 |
|
|
@@ -46,7 +47,7 @@ Optional variables:
|
|
| 46 |
| `LDPT_DINOV3` | a local DINOv3 ViT-7B: the official `.pth` or a transformers-format folder |
|
| 47 |
| `LDPT_DINOV3_REPO`, `LDPT_DINOV3_FILE` (+ `LDPT_DINOV3_REVISION`) | a repo holding the official `.pth` instead |
|
| 48 |
| `LDPT_DINOV3_HF_REPO`, `LDPT_DINOV3_HF_REVISION` | another transformers-format repo / commit |
|
| 49 |
-
| `LDPT_MODEL_<ID>` | a local release file for a `models.json` entry (`
|
| 50 |
| `LDPT_MAX_MP` | largest input (default 105) |
|
| 51 |
| `LDPT_MAX_INFER_MP` | largest inference resolution (default 105) |
|
| 52 |
| `LDPT_PRELOAD=1` | load the default model at startup (on ZeroGPU every model is loaded at startup) |
|
|
|
|
| 26 |
|
| 27 |
## Model
|
| 28 |
|
| 29 |
+
L-DPT-L zero-shot
|
| 30 |
+
([`l-dpt_large_depth_zeroshot.pth`](https://huggingface.co/pointcept-bot/L-DPT)):
|
| 31 |
DINOv3 ViT-7B/16 (frozen) + a 271 M-parameter decoder, trained at 768 px on synthetic and
|
| 32 |
+
multi-view data only. `models.json` can list more release files (e.g.
|
| 33 |
+
`l-dpt_large_depth_mixed.pth`); with more than one the UI offers a choice.
|
| 34 |
|
| 35 |
## Setup
|
| 36 |
|
|
|
|
| 47 |
| `LDPT_DINOV3` | a local DINOv3 ViT-7B: the official `.pth` or a transformers-format folder |
|
| 48 |
| `LDPT_DINOV3_REPO`, `LDPT_DINOV3_FILE` (+ `LDPT_DINOV3_REVISION`) | a repo holding the official `.pth` instead |
|
| 49 |
| `LDPT_DINOV3_HF_REPO`, `LDPT_DINOV3_HF_REVISION` | another transformers-format repo / commit |
|
| 50 |
+
| `LDPT_MODEL_<ID>` | a local release file for a `models.json` entry (`LDPT_MODEL_L_DPT_LARGE_DEPTH_ZEROSHOT`) |
|
| 51 |
| `LDPT_MAX_MP` | largest input (default 105) |
|
| 52 |
| `LDPT_MAX_INFER_MP` | largest inference resolution (default 105) |
|
| 53 |
| `LDPT_PRELOAD=1` | load the default model at startup (on ZeroGPU every model is loaded at startup) |
|
ldpt/models/l_dpt/api.py
CHANGED
|
@@ -3,15 +3,20 @@ Inference API: ``load`` a ready-to-run L-DPT, ``predict`` relative depth of an i
|
|
| 3 |
|
| 4 |
from ldpt.models.l_dpt import api
|
| 5 |
|
| 6 |
-
model = api.load(
|
|
|
|
|
|
|
|
|
|
| 7 |
depth = api.predict(model, image) # HxWx3 uint8 (or float in [0, 1]) -> HxW float32
|
| 8 |
|
| 9 |
``depth`` is positive relative depth: larger = farther, affine-invariant (the metric
|
| 10 |
-
depth is about s * depth + t with s > 0 per image). The release models
|
| 11 |
-
"l-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
``load`` builds the model on the meta device, reads the checkpoints memory-mapped and
|
| 17 |
assigns them tensor by tensor on the target device (the 7B encoder in bf16 storage by
|
|
@@ -27,7 +32,7 @@ as torchvision's Resize), ImageNet normalisation; the model pads to the patch gr
|
|
| 27 |
the output is resized bilinearly to the input size. ``size=None`` runs at the native
|
| 28 |
resolution (high-res inputs); for tens of megapixels load with the inference memory
|
| 29 |
options of LatentDPT (model kwargs, or set later as attributes), e.g.
|
| 30 |
-
``api.load("l-
|
| 31 |
|
| 32 |
``load`` builds the model as its release file or preset states it (decoder precision
|
| 33 |
too, unless ``precision`` is passed) and refuses weights that were trained with another
|
|
@@ -53,7 +58,14 @@ from torch import Tensor
|
|
| 53 |
from .convert import FORMATS, build_meta, check_decoder_state, load_release
|
| 54 |
from .l_dpt_v1m1_base import PRECISIONS, LatentDPT, _resolve_attn_dtype
|
| 55 |
from .modules import check_choice
|
| 56 |
-
from .presets import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
from .weights import (
|
| 58 |
PathLike,
|
| 59 |
decoder_state,
|
|
@@ -84,10 +96,13 @@ def load(
|
|
| 84 |
"""A LatentDPT with its weights, on ``device``, in eval mode.
|
| 85 |
|
| 86 |
Args:
|
| 87 |
-
name_or_path: a preset with released weights
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
encoder_weights: the official DINOv3 file (default ``$LDPT_DINOV3``); its sha256
|
| 92 |
prefix is checked once (``verify``). Or a folder in the transformers format
|
| 93 |
(a download of Meta's gated Hugging Face repo, e.g.
|
|
@@ -195,7 +210,7 @@ def load(
|
|
| 195 |
path = Path(name).expanduser()
|
| 196 |
if not path.is_file():
|
| 197 |
raise ValueError(
|
| 198 |
-
f"{name!r} is neither a preset{
|
| 199 |
f"({sorted(PRESETS)}) nor a file"
|
| 200 |
)
|
| 201 |
if weights is not None or run_config not in (None, False):
|
|
|
|
| 3 |
|
| 4 |
from ldpt.models.l_dpt import api
|
| 5 |
|
| 6 |
+
model = api.load(
|
| 7 |
+
"l-dpt_large_depth_mixed",
|
| 8 |
+
encoder_weights="dinov3_vit7b16_pretrain_lvd1689m-a955f4ea.pth",
|
| 9 |
+
)
|
| 10 |
depth = api.predict(model, image) # HxWx3 uint8 (or float in [0, 1]) -> HxW float32
|
| 11 |
|
| 12 |
``depth`` is positive relative depth: larger = farther, affine-invariant (the metric
|
| 13 |
+
depth is about s * depth + t with s > 0 per image). The release models
|
| 14 |
+
("l-dpt_large_depth_zeroshot", "l-dpt_large_depth_mixed") have an exponential head:
|
| 15 |
+
values in [exp(-30), exp(30)]; a sigmoid-head model gives (0, 1).
|
| 16 |
+
``api.load("l-dpt_large_depth_mixed", ...)`` downloads the pinned release file from
|
| 17 |
+
Hugging Face once; a local copy loads by path
|
| 18 |
+
(``api.load("l-dpt_large_depth_mixed.pth", ...)``) or with ``weights=``
|
| 19 |
+
(``api.load("l-dpt_large_depth_mixed", weights="l-dpt_large_depth_mixed.pth", ...)``).
|
| 20 |
|
| 21 |
``load`` builds the model on the meta device, reads the checkpoints memory-mapped and
|
| 22 |
assigns them tensor by tensor on the target device (the 7B encoder in bf16 storage by
|
|
|
|
| 32 |
the output is resized bilinearly to the input size. ``size=None`` runs at the native
|
| 33 |
resolution (high-res inputs); for tens of megapixels load with the inference memory
|
| 34 |
options of LatentDPT (model kwargs, or set later as attributes), e.g.
|
| 35 |
+
``api.load("l-dpt_large_depth_mixed", selection_impl="stream", chunk_tokens=32768)``.
|
| 36 |
|
| 37 |
``load`` builds the model as its release file or preset states it (decoder precision
|
| 38 |
too, unless ``precision`` is passed) and refuses weights that were trained with another
|
|
|
|
| 58 |
from .convert import FORMATS, build_meta, check_decoder_state, load_release
|
| 59 |
from .l_dpt_v1m1_base import PRECISIONS, LatentDPT, _resolve_attn_dtype
|
| 60 |
from .modules import check_choice
|
| 61 |
+
from .presets import (
|
| 62 |
+
IMAGE_MEAN,
|
| 63 |
+
IMAGE_STD,
|
| 64 |
+
INPUT_SIZE,
|
| 65 |
+
PRESETS,
|
| 66 |
+
get_preset,
|
| 67 |
+
suggest_preset,
|
| 68 |
+
)
|
| 69 |
from .weights import (
|
| 70 |
PathLike,
|
| 71 |
decoder_state,
|
|
|
|
| 96 |
"""A LatentDPT with its weights, on ``device``, in eval mode.
|
| 97 |
|
| 98 |
Args:
|
| 99 |
+
name_or_path: a preset with released weights
|
| 100 |
+
(``"l-dpt_large_depth_zeroshot"``, ``"l-dpt_large_depth_mixed"``; their
|
| 101 |
+
files come from Hugging Face once published, or from
|
| 102 |
+
``$LDPT_CKPT_LARGE_DEPTH_ZEROSHOT`` / ``$LDPT_CKPT_LARGE_DEPTH_MIXED``),
|
| 103 |
+
or a release file written by convert.py (it carries its config; the preset
|
| 104 |
+
name stored in a file converted before the rename is read as the current
|
| 105 |
+
one).
|
| 106 |
encoder_weights: the official DINOv3 file (default ``$LDPT_DINOV3``); its sha256
|
| 107 |
prefix is checked once (``verify``). Or a folder in the transformers format
|
| 108 |
(a download of Meta's gated Hugging Face repo, e.g.
|
|
|
|
| 210 |
path = Path(name).expanduser()
|
| 211 |
if not path.is_file():
|
| 212 |
raise ValueError(
|
| 213 |
+
f"{name!r} is neither a preset{suggest_preset(name)} "
|
| 214 |
f"({sorted(PRESETS)}) nor a file"
|
| 215 |
)
|
| 216 |
if weights is not None or run_config not in (None, False):
|
ldpt/models/l_dpt/convert.py
CHANGED
|
@@ -4,7 +4,8 @@ Dev training checkpoint -> L-DPT release file, and back.
|
|
| 4 |
A release file (``torch.save``, loadable with ``weights_only=True``) holds:
|
| 5 |
format "l-dpt-release/2"
|
| 6 |
model "L-DPT-v1m1"
|
| 7 |
-
preset preset name or None
|
|
|
|
| 8 |
config the LatentDPT kwargs without the training loss (a preset dict, or the
|
| 9 |
``model`` of a config file, minus ``criterion``)
|
| 10 |
state_dict decoder keys only (no ``module.`` prefix, no frozen encoder, no loss
|
|
@@ -17,8 +18,8 @@ criterion) still load: the criterion is ignored. Both directions check the decod
|
|
| 17 |
strictly: every key of the model built from ``config`` filled once, with its shape.
|
| 18 |
|
| 19 |
CLI:
|
| 20 |
-
python -m ldpt.models.l_dpt.convert SRC DST --preset l-
|
| 21 |
-
python -m ldpt.models.l_dpt.convert SRC DST --config exp/
|
| 22 |
|
| 23 |
Author: Xiaoyang Wu (xiaoyang.wu.cs@gmail.com)
|
| 24 |
Please cite our work if the code is helpful to you.
|
|
@@ -34,7 +35,7 @@ import torch
|
|
| 34 |
from torch import Tensor
|
| 35 |
|
| 36 |
from ..builder import build_model
|
| 37 |
-
from .presets import get_preset
|
| 38 |
from .weights import PathLike, decoder_state, read_checkpoint, verified_sha256
|
| 39 |
|
| 40 |
__all__ = [
|
|
@@ -147,8 +148,9 @@ def convert(
|
|
| 147 |
kwargs without the criterion (``release_kwargs``)."""
|
| 148 |
if (preset is None) == (config is None):
|
| 149 |
raise ValueError(
|
| 150 |
-
"pass exactly one of preset= (e.g. 'l-
|
| 151 |
-
"a training checkpoint does not record
|
|
|
|
| 152 |
)
|
| 153 |
kwargs = release_kwargs(get_preset(preset) if preset is not None else config)
|
| 154 |
ckpt = read_checkpoint(src)
|
|
@@ -222,7 +224,7 @@ def ensure_release(
|
|
| 222 |
)
|
| 223 |
if differ:
|
| 224 |
stale.append(f"config differs in {differ}")
|
| 225 |
-
if old.get("preset") != preset:
|
| 226 |
stale.append(f"preset {old.get('preset')!r}, not {preset!r}")
|
| 227 |
del old
|
| 228 |
if not stale:
|
|
@@ -246,15 +248,15 @@ def load_release(
|
|
| 246 |
raise ConvertError(
|
| 247 |
f"{path} is not an L-DPT release file ({FORMAT}): convert the training "
|
| 248 |
f"checkpoint first (python -m ldpt.models.l_dpt.convert SRC DST "
|
| 249 |
-
f"--preset l-
|
| 250 |
-
f"api.load('l-
|
| 251 |
)
|
| 252 |
if ckpt.get("model") != MODEL:
|
| 253 |
raise ConvertError(f"{path} holds {ckpt.get('model')!r}, not {MODEL!r}")
|
| 254 |
config, state = release_kwargs(ckpt["config"]), decoder_state(ckpt)
|
| 255 |
check_decoder_state(config, state)
|
| 256 |
info = dict(
|
| 257 |
-
preset=ckpt.get("preset"),
|
| 258 |
provenance=ckpt.get("provenance", {}),
|
| 259 |
format=ckpt["format"],
|
| 260 |
)
|
|
@@ -284,7 +286,8 @@ def main(argv=None) -> None:
|
|
| 284 |
parser.add_argument("dst", help="release file to write")
|
| 285 |
group = parser.add_mutually_exclusive_group(required=True)
|
| 286 |
group.add_argument(
|
| 287 |
-
"--preset",
|
|
|
|
| 288 |
)
|
| 289 |
group.add_argument("--config", help="the run's config file (its `model` dict)")
|
| 290 |
args = parser.parse_args(argv)
|
|
|
|
| 4 |
A release file (``torch.save``, loadable with ``weights_only=True``) holds:
|
| 5 |
format "l-dpt-release/2"
|
| 6 |
model "L-DPT-v1m1"
|
| 7 |
+
preset preset name or None (the names of LEGACY_PRESETS, stored by the
|
| 8 |
+
first conversions, read as the current ones)
|
| 9 |
config the LatentDPT kwargs without the training loss (a preset dict, or the
|
| 10 |
``model`` of a config file, minus ``criterion``)
|
| 11 |
state_dict decoder keys only (no ``module.`` prefix, no frozen encoder, no loss
|
|
|
|
| 18 |
strictly: every key of the model built from ``config`` filled once, with its shape.
|
| 19 |
|
| 20 |
CLI:
|
| 21 |
+
python -m ldpt.models.l_dpt.convert SRC DST --preset l-dpt_large_depth_zeroshot
|
| 22 |
+
python -m ldpt.models.l_dpt.convert SRC DST --config exp/hybrid/<run>/config.py
|
| 23 |
|
| 24 |
Author: Xiaoyang Wu (xiaoyang.wu.cs@gmail.com)
|
| 25 |
Please cite our work if the code is helpful to you.
|
|
|
|
| 35 |
from torch import Tensor
|
| 36 |
|
| 37 |
from ..builder import build_model
|
| 38 |
+
from .presets import PRESETS, canonical_preset, get_preset
|
| 39 |
from .weights import PathLike, decoder_state, read_checkpoint, verified_sha256
|
| 40 |
|
| 41 |
__all__ = [
|
|
|
|
| 148 |
kwargs without the criterion (``release_kwargs``)."""
|
| 149 |
if (preset is None) == (config is None):
|
| 150 |
raise ValueError(
|
| 151 |
+
"pass exactly one of preset= (e.g. 'l-dpt_large_depth_zeroshot') or "
|
| 152 |
+
"config= (the run's model dict); a training checkpoint does not record "
|
| 153 |
+
"its model kwargs"
|
| 154 |
)
|
| 155 |
kwargs = release_kwargs(get_preset(preset) if preset is not None else config)
|
| 156 |
ckpt = read_checkpoint(src)
|
|
|
|
| 224 |
)
|
| 225 |
if differ:
|
| 226 |
stale.append(f"config differs in {differ}")
|
| 227 |
+
if canonical_preset(old.get("preset")) != preset:
|
| 228 |
stale.append(f"preset {old.get('preset')!r}, not {preset!r}")
|
| 229 |
del old
|
| 230 |
if not stale:
|
|
|
|
| 248 |
raise ConvertError(
|
| 249 |
f"{path} is not an L-DPT release file ({FORMAT}): convert the training "
|
| 250 |
f"checkpoint first (python -m ldpt.models.l_dpt.convert SRC DST "
|
| 251 |
+
f"--preset l-dpt_large_depth_zeroshot), or load it with its preset: "
|
| 252 |
+
f"api.load('l-dpt_large_depth_zeroshot', weights=path)"
|
| 253 |
)
|
| 254 |
if ckpt.get("model") != MODEL:
|
| 255 |
raise ConvertError(f"{path} holds {ckpt.get('model')!r}, not {MODEL!r}")
|
| 256 |
config, state = release_kwargs(ckpt["config"]), decoder_state(ckpt)
|
| 257 |
check_decoder_state(config, state)
|
| 258 |
info = dict(
|
| 259 |
+
preset=canonical_preset(ckpt.get("preset")),
|
| 260 |
provenance=ckpt.get("provenance", {}),
|
| 261 |
format=ckpt["format"],
|
| 262 |
)
|
|
|
|
| 286 |
parser.add_argument("dst", help="release file to write")
|
| 287 |
group = parser.add_mutually_exclusive_group(required=True)
|
| 288 |
group.add_argument(
|
| 289 |
+
"--preset",
|
| 290 |
+
help=f"preset of the run (presets.PRESETS: {', '.join(PRESETS)})",
|
| 291 |
)
|
| 292 |
group.add_argument("--config", help="the run's config file (its `model` dict)")
|
| 293 |
args = parser.parse_args(argv)
|
ldpt/models/l_dpt/presets.py
CHANGED
|
@@ -2,12 +2,14 @@
|
|
| 2 |
Named L-DPT configurations: one class (L-DPT-v1m1), the released models as presets.
|
| 3 |
|
| 4 |
A preset is the full constructor kwargs of LatentDPT as a plain dict (every option
|
| 5 |
-
spelled out, so it does not move when a default changes)
|
|
|
|
| 6 |
|
| 7 |
-
"l-
|
| 8 |
-
|
| 9 |
-
"l-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
Both share one architecture (RELEASE_L) and differ only in their weights: frozen DINOv3
|
| 13 |
ViT-7B/16 tapped at blocks [9, 19, 29, 39], latent decoder 1024 / 16 heads / (4, 4, 4,
|
|
@@ -15,12 +17,14 @@ ViT-7B/16 tapped at blocks [9, 19, 29, 39], latent decoder 1024 / 16 heads / (4,
|
|
| 15 |
last decoder stage, an attention-logit bound of 1000, trained at short side 768 with
|
| 16 |
loss v5. Inference only (criterion=False): the training losses live in the configs. In
|
| 17 |
a config:
|
| 18 |
-
model = dict(type="L-DPT-v1m1", **get_preset("l-
|
| 19 |
|
| 20 |
WEIGHTS pins the released decoder checkpoints (Hugging Face repo, revision, file,
|
| 21 |
sha256; a slot not published yet would say TBD); DINOv3 weights are not
|
| 22 |
redistributed: weights.encoder_weights() takes a local file and checks the sha256 prefix
|
| 23 |
-
in its official name.
|
|
|
|
|
|
|
| 24 |
|
| 25 |
Author: Xiaoyang Wu (xiaoyang.wu.cs@gmail.com)
|
| 26 |
Please cite our work if the code is helpful to you.
|
|
@@ -36,17 +40,19 @@ __all__ = [
|
|
| 36 |
"IMAGE_MEAN",
|
| 37 |
"IMAGE_STD",
|
| 38 |
"INPUT_SIZE",
|
|
|
|
| 39 |
"PRESETS",
|
| 40 |
"RELEASE_L",
|
| 41 |
"WEIGHTS",
|
| 42 |
"WeightSource",
|
|
|
|
| 43 |
"get_preset",
|
| 44 |
]
|
| 45 |
|
| 46 |
TAPS_7B = [9, 19, 29, 39]
|
| 47 |
|
| 48 |
# the release architecture, shared by both release models (they differ only in their
|
| 49 |
-
# weights): the model of configs/
|
| 50 |
RELEASE_L: Dict[str, Any] = dict(
|
| 51 |
encoder=dict(type="dinov3_vit7b"),
|
| 52 |
encoder_inter_layers=TAPS_7B,
|
|
@@ -84,14 +90,21 @@ RELEASE_L: Dict[str, Any] = dict(
|
|
| 84 |
)
|
| 85 |
|
| 86 |
PRESETS: Dict[str, Dict[str, Any]] = {
|
| 87 |
-
"l-
|
| 88 |
-
"l-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
|
| 91 |
# short side of the val pipeline (bicubic resize), per preset: the training resolution
|
| 92 |
INPUT_SIZE: Dict[str, int] = {
|
| 93 |
-
"l-
|
| 94 |
-
"l-
|
| 95 |
}
|
| 96 |
IMAGE_MEAN = (0.485, 0.456, 0.406)
|
| 97 |
IMAGE_STD = (0.229, 0.224, 0.225)
|
|
@@ -132,24 +145,24 @@ class WeightSource:
|
|
| 132 |
|
| 133 |
# the released decoder checkpoints (convert.py files) on Hugging Face
|
| 134 |
RELEASE_REPO = "pointcept-bot/L-DPT"
|
| 135 |
-
RELEASE_REVISION = "
|
| 136 |
WEIGHTS: Dict[str, WeightSource] = {
|
| 137 |
-
"l-
|
| 138 |
repo=RELEASE_REPO,
|
| 139 |
-
file="l-
|
| 140 |
revision=RELEASE_REVISION,
|
| 141 |
sha256="b4e7e95301fda7557760f787e7992f4ccca3c03cb70e46eadeb48e227b1b31ca",
|
| 142 |
size=1_084_064_148,
|
| 143 |
-
env="
|
| 144 |
format="release",
|
| 145 |
),
|
| 146 |
-
"l-
|
| 147 |
repo=RELEASE_REPO,
|
| 148 |
-
file="l-
|
| 149 |
revision=RELEASE_REVISION,
|
| 150 |
sha256="4852b823c68fea30b3360a249e71daf72a9c6c2c74f747602a117b42f35d36fa",
|
| 151 |
size=1_084_064_405,
|
| 152 |
-
env="
|
| 153 |
format="release",
|
| 154 |
),
|
| 155 |
}
|
|
@@ -161,12 +174,25 @@ def suggest(name: str, choices) -> str:
|
|
| 161 |
return f" (did you mean {close[0]!r}?)" if close else ""
|
| 162 |
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
def get_preset(name: str, **overrides: Any) -> Dict[str, Any]:
|
| 165 |
"""A deep copy of preset ``name`` with ``overrides`` applied (unknown keys of the
|
| 166 |
model raise when it is built)."""
|
| 167 |
if name not in PRESETS:
|
| 168 |
raise ValueError(
|
| 169 |
-
f"unknown L-DPT preset {name!r}{
|
| 170 |
f"available: {sorted(PRESETS)}"
|
| 171 |
)
|
| 172 |
kwargs = copy.deepcopy(PRESETS[name])
|
|
|
|
| 2 |
Named L-DPT configurations: one class (L-DPT-v1m1), the released models as presets.
|
| 3 |
|
| 4 |
A preset is the full constructor kwargs of LatentDPT as a plain dict (every option
|
| 5 |
+
spelled out, so it does not move when a default changes). The names (and the weight
|
| 6 |
+
files, <name>.pth) read l-dpt_<decoder size>_<task>_<training data>:
|
| 7 |
|
| 8 |
+
"l-dpt_large_depth_zeroshot" L-DPT-L zero-shot: trained on synthetic / multi-view
|
| 9 |
+
data only (configs/hybrid/depth-l-dpt-v1m1-0-large-zeroshot.py)
|
| 10 |
+
"l-dpt_large_depth_mixed" L-DPT-L mixed-domain: + the NYUv2 / KITTI / DIODE
|
| 11 |
+
training splits (configs/hybrid/depth-l-dpt-v1m1-1-large-mixed.py,
|
| 12 |
+
depth-l-dpt-v1m1-1a-large-mixed-anneal.py)
|
| 13 |
|
| 14 |
Both share one architecture (RELEASE_L) and differ only in their weights: frozen DINOv3
|
| 15 |
ViT-7B/16 tapped at blocks [9, 19, 29, 39], latent decoder 1024 / 16 heads / (4, 4, 4,
|
|
|
|
| 17 |
last decoder stage, an attention-logit bound of 1000, trained at short side 768 with
|
| 18 |
loss v5. Inference only (criterion=False): the training losses live in the configs. In
|
| 19 |
a config:
|
| 20 |
+
model = dict(type="L-DPT-v1m1", **get_preset("l-dpt_large_depth_zeroshot"))
|
| 21 |
|
| 22 |
WEIGHTS pins the released decoder checkpoints (Hugging Face repo, revision, file,
|
| 23 |
sha256; a slot not published yet would say TBD); DINOv3 weights are not
|
| 24 |
redistributed: weights.encoder_weights() takes a local file and checks the sha256 prefix
|
| 25 |
+
in its official name. LEGACY_PRESETS maps the preset names stored in release files
|
| 26 |
+
converted before the rename ("l-zs", "l-mix": the published files) to the current
|
| 27 |
+
names. This module imports no torch.
|
| 28 |
|
| 29 |
Author: Xiaoyang Wu (xiaoyang.wu.cs@gmail.com)
|
| 30 |
Please cite our work if the code is helpful to you.
|
|
|
|
| 40 |
"IMAGE_MEAN",
|
| 41 |
"IMAGE_STD",
|
| 42 |
"INPUT_SIZE",
|
| 43 |
+
"LEGACY_PRESETS",
|
| 44 |
"PRESETS",
|
| 45 |
"RELEASE_L",
|
| 46 |
"WEIGHTS",
|
| 47 |
"WeightSource",
|
| 48 |
+
"canonical_preset",
|
| 49 |
"get_preset",
|
| 50 |
]
|
| 51 |
|
| 52 |
TAPS_7B = [9, 19, 29, 39]
|
| 53 |
|
| 54 |
# the release architecture, shared by both release models (they differ only in their
|
| 55 |
+
# weights): the model of configs/hybrid/*.py (tests/test_configs.py checks it)
|
| 56 |
RELEASE_L: Dict[str, Any] = dict(
|
| 57 |
encoder=dict(type="dinov3_vit7b"),
|
| 58 |
encoder_inter_layers=TAPS_7B,
|
|
|
|
| 90 |
)
|
| 91 |
|
| 92 |
PRESETS: Dict[str, Dict[str, Any]] = {
|
| 93 |
+
"l-dpt_large_depth_zeroshot": RELEASE_L,
|
| 94 |
+
"l-dpt_large_depth_mixed": RELEASE_L,
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
# the preset names of the first conversions, stored in the published release files
|
| 98 |
+
# (their "preset" field): read as the current names, never accepted as a preset
|
| 99 |
+
LEGACY_PRESETS: Dict[str, str] = {
|
| 100 |
+
"l-zs": "l-dpt_large_depth_zeroshot",
|
| 101 |
+
"l-mix": "l-dpt_large_depth_mixed",
|
| 102 |
}
|
| 103 |
|
| 104 |
# short side of the val pipeline (bicubic resize), per preset: the training resolution
|
| 105 |
INPUT_SIZE: Dict[str, int] = {
|
| 106 |
+
"l-dpt_large_depth_zeroshot": 768,
|
| 107 |
+
"l-dpt_large_depth_mixed": 768,
|
| 108 |
}
|
| 109 |
IMAGE_MEAN = (0.485, 0.456, 0.406)
|
| 110 |
IMAGE_STD = (0.229, 0.224, 0.225)
|
|
|
|
| 145 |
|
| 146 |
# the released decoder checkpoints (convert.py files) on Hugging Face
|
| 147 |
RELEASE_REPO = "pointcept-bot/L-DPT"
|
| 148 |
+
RELEASE_REVISION = "0b212646e6bf7f2e0007c98ba5ed902408bfc27c"
|
| 149 |
WEIGHTS: Dict[str, WeightSource] = {
|
| 150 |
+
"l-dpt_large_depth_zeroshot": WeightSource(
|
| 151 |
repo=RELEASE_REPO,
|
| 152 |
+
file="l-dpt_large_depth_zeroshot.pth",
|
| 153 |
revision=RELEASE_REVISION,
|
| 154 |
sha256="b4e7e95301fda7557760f787e7992f4ccca3c03cb70e46eadeb48e227b1b31ca",
|
| 155 |
size=1_084_064_148,
|
| 156 |
+
env="LDPT_CKPT_LARGE_DEPTH_ZEROSHOT",
|
| 157 |
format="release",
|
| 158 |
),
|
| 159 |
+
"l-dpt_large_depth_mixed": WeightSource(
|
| 160 |
repo=RELEASE_REPO,
|
| 161 |
+
file="l-dpt_large_depth_mixed.pth",
|
| 162 |
revision=RELEASE_REVISION,
|
| 163 |
sha256="4852b823c68fea30b3360a249e71daf72a9c6c2c74f747602a117b42f35d36fa",
|
| 164 |
size=1_084_064_405,
|
| 165 |
+
env="LDPT_CKPT_LARGE_DEPTH_MIXED",
|
| 166 |
format="release",
|
| 167 |
),
|
| 168 |
}
|
|
|
|
| 174 |
return f" (did you mean {close[0]!r}?)" if close else ""
|
| 175 |
|
| 176 |
|
| 177 |
+
def suggest_preset(name: str) -> str:
|
| 178 |
+
"""``suggest`` among the presets; for a name of LEGACY_PRESETS, its new name."""
|
| 179 |
+
if name in LEGACY_PRESETS:
|
| 180 |
+
return f" (renamed {LEGACY_PRESETS[name]!r})"
|
| 181 |
+
return suggest(name, PRESETS)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def canonical_preset(name: Optional[str]) -> Optional[str]:
|
| 185 |
+
"""The current name of a preset name stored in a release file (LEGACY_PRESETS),
|
| 186 |
+
else ``name`` unchanged (None stays None)."""
|
| 187 |
+
return LEGACY_PRESETS.get(name, name) if name is not None else None
|
| 188 |
+
|
| 189 |
+
|
| 190 |
def get_preset(name: str, **overrides: Any) -> Dict[str, Any]:
|
| 191 |
"""A deep copy of preset ``name`` with ``overrides`` applied (unknown keys of the
|
| 192 |
model raise when it is built)."""
|
| 193 |
if name not in PRESETS:
|
| 194 |
raise ValueError(
|
| 195 |
+
f"unknown L-DPT preset {name!r}{suggest_preset(name)}; "
|
| 196 |
f"available: {sorted(PRESETS)}"
|
| 197 |
)
|
| 198 |
kwargs = copy.deepcopy(PRESETS[name])
|
ldpt/models/l_dpt/weights.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
| 2 |
Weights of L-DPT: find or download a decoder checkpoint, check it, read it.
|
| 3 |
|
| 4 |
- Decoder: ``fetch(preset)`` returns a local, sha256-checked copy of the preset's pinned
|
| 5 |
-
file: the path in the preset's environment variable
|
|
|
|
| 6 |
``huggingface_hub.hf_hub_download`` at the pinned revision (HF_HOME, HF_HUB_OFFLINE
|
| 7 |
work as usual). Dev training checkpoints (``module.`` prefix, optimizer state) and
|
| 8 |
release files (convert.py) both read through ``decoder_state``.
|
|
@@ -106,7 +107,7 @@ def fetch(name: str, *, revision: Optional[str] = None, verify: bool = True) ->
|
|
| 106 |
if source is None:
|
| 107 |
raise ValueError(
|
| 108 |
f"preset {name!r} has no released weights; pass weights=<path> to "
|
| 109 |
-
f"api.load, or train it (configs/
|
| 110 |
)
|
| 111 |
pinned = revision is None or revision == source.revision
|
| 112 |
local = os.environ.get(source.env)
|
|
|
|
| 2 |
Weights of L-DPT: find or download a decoder checkpoint, check it, read it.
|
| 3 |
|
| 4 |
- Decoder: ``fetch(preset)`` returns a local, sha256-checked copy of the preset's pinned
|
| 5 |
+
file: the path in the preset's environment variable
|
| 6 |
+
(``LDPT_CKPT_LARGE_DEPTH_ZEROSHOT``) when set, else
|
| 7 |
``huggingface_hub.hf_hub_download`` at the pinned revision (HF_HOME, HF_HUB_OFFLINE
|
| 8 |
work as usual). Dev training checkpoints (``module.`` prefix, optimizer state) and
|
| 9 |
release files (convert.py) both read through ``decoder_state``.
|
|
|
|
| 107 |
if source is None:
|
| 108 |
raise ValueError(
|
| 109 |
f"preset {name!r} has no released weights; pass weights=<path> to "
|
| 110 |
+
f"api.load, or train it (configs/hybrid/*.py)"
|
| 111 |
)
|
| 112 |
pinned = revision is None or revision == source.revision
|
| 113 |
local = os.environ.get(source.env)
|
models.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
{
|
| 2 |
-
"_note": "Release files written by `python -m ldpt.models.l_dpt.convert SRC DST --preset l-
|
| 3 |
"models": [
|
| 4 |
{
|
| 5 |
-
"id": "l-
|
| 6 |
"label": "L-DPT-L zero-shot",
|
| 7 |
"description": "Trained without the NYUv2, KITTI and DIODE training sets. The sharpest separation of thin foreground (leaves, branches, hair) from the background on everyday photos.",
|
| 8 |
"recommended": true,
|
| 9 |
"source": {
|
| 10 |
"repo": "pointcept-bot/L-DPT",
|
| 11 |
-
"filename": "l-
|
| 12 |
-
"revision": "
|
| 13 |
"sha256": "b4e7e95301fda7557760f787e7992f4ccca3c03cb70e46eadeb48e227b1b31ca"
|
| 14 |
},
|
| 15 |
"expect": {
|
|
|
|
| 1 |
{
|
| 2 |
+
"_note": "Release files written by `python -m ldpt.models.l_dpt.convert SRC DST --preset l-dpt_large_depth_zeroshot` (or `--preset l-dpt_large_depth_mixed`) from the training checkpoints of configs/hybrid/ (README.md, Models), pinned to a commit of the model repo. The default is the first recommended entry; with one entry the UI shows no model choice. LDPT_MODEL_<ID> (ID upper-cased, '-' -> '_') replaces a source by a local release file. 'expect' pins release-config values checked before loading; 'sha256' is checked after a download.",
|
| 3 |
"models": [
|
| 4 |
{
|
| 5 |
+
"id": "l-dpt_large_depth_zeroshot",
|
| 6 |
"label": "L-DPT-L zero-shot",
|
| 7 |
"description": "Trained without the NYUv2, KITTI and DIODE training sets. The sharpest separation of thin foreground (leaves, branches, hair) from the background on everyday photos.",
|
| 8 |
"recommended": true,
|
| 9 |
"source": {
|
| 10 |
"repo": "pointcept-bot/L-DPT",
|
| 11 |
+
"filename": "l-dpt_large_depth_zeroshot.pth",
|
| 12 |
+
"revision": "0b212646e6bf7f2e0007c98ba5ed902408bfc27c",
|
| 13 |
"sha256": "b4e7e95301fda7557760f787e7992f4ccca3c03cb70e46eadeb48e227b1b31ca"
|
| 14 |
},
|
| 15 |
"expect": {
|
space_utils.py
CHANGED
|
@@ -6,7 +6,7 @@ DepthService (the loaded models, sharing one DINOv3 encoder, with the high-res m
|
|
| 6 |
options of api.load).
|
| 7 |
|
| 8 |
models.json:
|
| 9 |
-
{"models": [{"id": "l-
|
| 10 |
"label": "...", "description": "...",
|
| 11 |
"recommended": true, # optional; the default is the first
|
| 12 |
# recommended entry, else the first
|
|
@@ -20,15 +20,15 @@ models.json:
|
|
| 20 |
$LDPT_MODEL_<ID> (ID upper-cased, other characters -> "_") names a local release
|
| 21 |
file that replaces the source (not hashed).
|
| 22 |
|
| 23 |
-
Release files come from `python -m ldpt.models.l_dpt.convert SRC DST --preset
|
| 24 |
-
`--config <the run's config.py>`); they carry the model
|
| 25 |
-
weights are not redistributable; resolve_dinov3 takes, in
|
| 26 |
-
local official .pth file or a local transformers-format
|
| 27 |
-
$LDPT_DINOV3_FILE (a Hugging Face repo holding the .pth),
|
| 28 |
-
transformers-format repo (DINOV3_HF_REPO at DINOV3_HF_REVISION;
|
| 29 |
-
_REVISION override, "none" turns it off), downloaded with
|
| 30 |
-
access to it). api.load reads a transformers folder into
|
| 31 |
-
same tensors).
|
| 32 |
"""
|
| 33 |
|
| 34 |
import dataclasses
|
|
|
|
| 6 |
options of api.load).
|
| 7 |
|
| 8 |
models.json:
|
| 9 |
+
{"models": [{"id": "l-dpt_large_depth_zeroshot", # [a-z0-9][a-z0-9_-]*
|
| 10 |
"label": "...", "description": "...",
|
| 11 |
"recommended": true, # optional; the default is the first
|
| 12 |
# recommended entry, else the first
|
|
|
|
| 20 |
$LDPT_MODEL_<ID> (ID upper-cased, other characters -> "_") names a local release
|
| 21 |
file that replaces the source (not hashed).
|
| 22 |
|
| 23 |
+
Release files come from `python -m ldpt.models.l_dpt.convert SRC DST --preset
|
| 24 |
+
l-dpt_large_depth_zeroshot` (or `--config <the run's config.py>`); they carry the model
|
| 25 |
+
kwargs. The DINOv3 ViT-7B weights are not redistributable; resolve_dinov3 takes, in
|
| 26 |
+
this order: $LDPT_DINOV3 (a local official .pth file or a local transformers-format
|
| 27 |
+
folder), $LDPT_DINOV3_REPO + $LDPT_DINOV3_FILE (a Hugging Face repo holding the .pth),
|
| 28 |
+
else Meta's gated transformers-format repo (DINOV3_HF_REPO at DINOV3_HF_REVISION;
|
| 29 |
+
$LDPT_DINOV3_HF_REPO / _REVISION override, "none" turns it off), downloaded with
|
| 30 |
+
$HF_TOKEN (an account granted access to it). api.load reads a transformers folder into
|
| 31 |
+
the original key layout (the same tensors).
|
| 32 |
"""
|
| 33 |
|
| 34 |
import dataclasses
|