mlx3d.models¶
Pretrained 3D foundation models. Install the models extra to download
weights: pip install "mlx3d[models]".
mlx3d.models.depth_anything3.DepthAnything3
¶
Bases: Module
DA3 any-view geometry model (MLX port of ByteDance-Seed/Depth-Anything-3).
From one or more images of a static scene it predicts, in a single forward
pass, a depth map and confidence per view plus every view's intrinsics and
pose — the job usually done by structure-from-motion. Load pretrained
weights with :meth:from_pretrained and run :meth:predict.
The backbone may run in reduced precision (dtype); the dense head and
camera decoder always run in float32, as in the reference implementation.
Source code in src/mlx3d/models/depth_anything3/model.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
from_pretrained(name='da3-base', weights=None, dtype=mx.float32)
classmethod
¶
Build a preset and load its pretrained weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
a preset in :data: |
'da3-base'
|
weights
|
str | None
|
local |
None
|
dtype
|
Dtype
|
backbone compute dtype. |
float32
|
Source code in src/mlx3d/models/depth_anything3/model.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
encode(pixels, ref_view_strategy='saddle_balanced')
¶
Backbone taps for normalized (B, S, H, W, 3) pixels, in float32.
Source code in src/mlx3d/models/depth_anything3/model.py
88 89 90 91 92 93 94 95 96 | |
__call__(pixels, ref_view_strategy='saddle_balanced', with_rays=False)
¶
Full forward pass on normalized (B, S, H, W, 3) pixels.
Returns (B, S, ...) arrays: depth, depth_conf, R, t,
K (and ray, ray_conf with with_rays).
Source code in src/mlx3d/models/depth_anything3/model.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
predict(images, resolution=504, ref_view_strategy='saddle_balanced', with_rays=False, max_views=32, num_anchors=8, head_chunk=8)
¶
Predict depth and cameras for a set of views of one scene.
Up to max_views views are processed jointly in one forward pass.
Longer sequences run in chunks that all share num_anchors evenly
spaced anchor views; each chunk is mapped into the first chunk's frame
by the similarity that best aligns its anchor cameras, so cost grows
linearly instead of quadratically and nothing drifts along the sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Sequence[ImageInput]
|
file paths, PIL images, or |
required |
resolution
|
int
|
longest processing side (the model was trained at 504). |
504
|
ref_view_strategy
|
RefViewStrategy
|
how the view defining the world frame is chosen. |
'saddle_balanced'
|
with_rays
|
bool
|
also return DA3's per-pixel ray maps (joint pass only). |
False
|
max_views
|
int
|
most views per forward pass. |
32
|
num_anchors
|
int
|
views shared by every chunk of a long sequence. |
8
|
head_chunk
|
int
|
views decoded per dense-head pass; lower it to reduce peak memory. |
8
|
Source code in src/mlx3d/models/depth_anything3/model.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
mlx3d.models.depth_anything3.GeometryPrediction
dataclass
¶
Per-view depth, confidence and cameras for S views at processing size.
Cameras follow mlx3d's OpenCV convention (world-to-camera R, t); the
world frame is the reference view's camera frame, at an arbitrary but
consistent scale.
Attributes:
| Name | Type | Description |
|---|---|---|
depth |
array
|
|
depth_conf |
array
|
|
R, |
t
|
|
K |
array
|
|
rgb |
ndarray
|
|
original_sizes |
list[tuple[int, int]]
|
each input's |
ray, |
ray_conf
|
optional per-pixel ray maps, when requested. |
Source code in src/mlx3d/models/depth_anything3/prediction.py
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
image_size
property
¶
Processing (width, height).
camera(i, original_size=False)
¶
View i as a :class:~mlx3d.cameras.Camera.
With original_size the intrinsics are rescaled to the input image
resolution (e.g. for training on the full-resolution photos).
Source code in src/mlx3d/models/depth_anything3/prediction.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
confidence_mask(quantile=0.3)
¶
(S, H, W) mask keeping pixels above the global confidence quantile.
Source code in src/mlx3d/models/depth_anything3/prediction.py
78 79 80 81 | |
world_points(i)
¶
(H, W, 3) world-space points of view i (pixel-center unprojection).
Source code in src/mlx3d/models/depth_anything3/prediction.py
83 84 85 86 87 88 89 | |
point_cloud(conf_quantile=0.3, max_points=500000, seed=0)
¶
Fuse all views into one colored point cloud.
Pixels below the conf_quantile confidence quantile are dropped, then
the rest is uniformly subsampled to max_points.
Returns:
| Type | Description |
|---|---|
ndarray
|
|
ndarray
|
float32 colors in |
Source code in src/mlx3d/models/depth_anything3/prediction.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
to_pointclouds(**kwargs)
¶
:meth:point_cloud as a single-element :class:~mlx3d.structures.Pointclouds.
Source code in src/mlx3d/models/depth_anything3/prediction.py
111 112 113 114 | |
mlx3d.models.depth_anything3.DA3Config
dataclass
¶
Hyperparameters of a DA3 network (DINOv2 backbone + DualDPT head).
Attributes:
| Name | Type | Description |
|---|---|---|
repo_id |
str
|
Hugging Face repository holding the pretrained weights. |
license |
str
|
license of those weights (the MLX code itself is MIT). |
embed_dim, |
(depth, num_heads)
|
ViT width, number of blocks, attention heads. |
out_layers |
tuple[int, ...]
|
blocks whose tokens feed the dense head (and camera decoder). |
alt_start |
int
|
first block that alternates frame-local and cross-view (global) attention; odd blocks from here on are global. |
qknorm_start, |
rope_start
|
first block using QK-LayerNorm / 2D RoPE. |
head_features |
int
|
DPT fusion width. |
head_out_channels |
tuple[int, int, int, int]
|
per-stage DPT projection widths. |
Source code in src/mlx3d/models/depth_anything3/config.py
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 46 | |
pretrain_grid = 37
class-attribute
instance-attribute
¶
Side length of the patch grid the positional embedding was trained at (518 px / 14).
mlx3d.models.depth_anything3.convert_checkpoint(weights)
¶
Convert a DA3 model.safetensors dict to MLX parameter names/layouts.
Linear weights keep PyTorch's (out, in) layout; convolution kernels move
from (out, in, kh, kw) to MLX's (out, kh, kw, in) and transposed
convolutions from (in, out, kh, kw) to (out, kh, kw, in).
Source code in src/mlx3d/models/depth_anything3/convert.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |