mlboydaisuke commited on
Commit
401b639
·
verified ·
1 Parent(s): efef929

Mirror of mlboydaisuke/Depth-Anything-3-CoreAI

Browse files
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ base/da3-base_float16.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -text
37
+ base/da3-base_float32.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -text
38
+ small/da3-small_float16.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -text
39
+ small/da3-small_float32.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - depth-estimation
5
+ - monocular-depth
6
+ - core-ai
7
+ - coreai
8
+ - apple
9
+ - on-device
10
+ - depth-anything
11
+ pipeline_tag: depth-estimation
12
+ base_model:
13
+ - depth-anything/DA3-SMALL
14
+ - depth-anything/DA3-BASE
15
+ library_name: coreai
16
+ ---
17
+
18
+ > **Mirror** of [`mlboydaisuke/Depth-Anything-3-CoreAI`](https://huggingface.co/mlboydaisuke/Depth-Anything-3-CoreAI) — the canonical repo ([CoreAI Model Zoo](https://github.com/john-rocky/coreai-model-zoo)). Updates land there first.
19
+
20
+
21
+ # Depth Anything 3 — Core AI
22
+
23
+ **The [coreai-model-zoo](https://github.com/john-rocky/coreai-model-zoo)'s first depth model.**
24
+ Monocular (single-image) **relative depth** estimation running fully on-device on Apple's Core AI
25
+ runtime, as a single static `.aimodel`. A conversion of ByteDance's
26
+ [Depth Anything 3](https://github.com/ByteDance-Seed/depth-anything-3)
27
+ ([`depth-anything/DA3-SMALL`](https://huggingface.co/depth-anything/DA3-SMALL) /
28
+ [`DA3-BASE`](https://huggingface.co/depth-anything/DA3-BASE), Apache-2.0): a DINOv2 ViT backbone +
29
+ DPT-style head. Drop in an RGB image, get a depth map (and a confidence map). No NMS, no sampling —
30
+ host post-processing is just a colormap.
31
+
32
+ <!-- gen-cards:use-it begin id=depth-anything-3-small (managed by scripts/gen-cards — edit cards.json / QuickStart.swift, not this block) -->
33
+ ## Use it
34
+
35
+ ▶️ **Run it (source)** — the [DepthCamera runner](https://github.com/john-rocky/coreai-kit/tree/main/Examples/DepthCamera)
36
+ (live camera depth, one app for every depth model in the catalog):
37
+
38
+ ```bash
39
+ git clone https://github.com/john-rocky/coreai-kit
40
+ open coreai-kit/Examples/DepthCamera/DepthCamera.xcodeproj
41
+ # → Run, then pick "Depth Anything 3 Small" in the model picker
42
+
43
+ # agents / headless (macOS):
44
+ cd coreai-kit/Examples/DepthCamera
45
+ swift run depth-cli --model depth-anything-3-small --image sample.jpg --output depth.png
46
+ ```
47
+
48
+ 💻 **Build with it** — complete; the glue is kit API, copy-paste runs:
49
+
50
+ ```swift
51
+ import CoreAIKitVision
52
+
53
+ let estimator = try await DepthEstimator(catalog: "depth-anything-3-small")
54
+ let image = try ImageFile.load(imageURL) // any image file → CGImage + EXIF orientation
55
+ let depth = try await estimator.estimateDepth(for: image.cgImage)
56
+ // depth: DepthMap — .cgImage() renders it, .values are the raw floats
57
+ ```
58
+
59
+ The take-home is [`Examples/DepthCamera/Sources/QuickStart.swift`](https://github.com/john-rocky/coreai-kit/blob/main/Examples/DepthCamera/Sources/QuickStart.swift)
60
+ — this exact code as one typed function, no UI; the CLI is an argument shell over it, and
61
+ the GUI runs the same estimator on every camera frame (`CameraFeed`, ~10 lines).
62
+ Live camera? `CameraFeed` (kit API) streams frames — feed each one to
63
+ `estimateDepth(for:)`; the camera permission prompt is your app's own chrome.
64
+
65
+ **Integration checklist**
66
+
67
+ - SPM: `https://github.com/john-rocky/coreai-kit` → product **CoreAIKitVision**
68
+ - Info.plist: `NSCameraUsageDescription` — only for the live camera; the snippet needs none
69
+ - Entitlements: none needed
70
+ - First run downloads the model — 0.1 GB (Mac) / 0.1 GB (iPhone) — then it loads from the
71
+ local cache (Application Support; progress via the `downloadProgress` callback)
72
+ - Measure in Release — Debug is ~3× slower on per-token host work
73
+ <!-- gen-cards:use-it end -->
74
+
75
+ ## Bundles
76
+
77
+ | dir | variant | params | dtype | size | M4 Max GPU |
78
+ |---|---|---|---|---|---|
79
+ | `small/da3-small_float16.aimodel` | ViT-S | 34.3M | fp16 | **54 MB** | **65.7 FPS** |
80
+ | `small/da3-small_float32.aimodel` | ViT-S | 34.3M | fp32 | 105 MB | 56.5 FPS |
81
+ | `base/da3-base_float16.aimodel` | ViT-B | 135.4M | fp16 | 202 MB | 26.5 FPS |
82
+ | `base/da3-base_float32.aimodel` | ViT-B | 135.4M | fp32 | 402 MB | 23.0 FPS |
83
+
84
+ `small · fp16` is the on-device hero — 54 MB, 65 FPS at 504² on an M4 Max, comfortably real-time on
85
+ iPhone-class GPUs. Each `.aimodel` is a directory bundle (`main.mlirb` + `metadata.json`).
86
+
87
+ ## I/O contract
88
+
89
+ ```
90
+ input : image [1, 3, 504, 504] RGB, raw [0, 1] (ImageNet normalization is folded into the graph)
91
+ output: depth [1, 504, 504] relative depth (exp-activated; larger = nearer)
92
+ depth_conf [1, 504, 504] confidence
93
+ ```
94
+
95
+ Host: resize the RGB image to 504 × 504 (e.g. cv2 `INTER_AREA`), feed raw [0, 1], run, then resize
96
+ the depth map back to the original H × W. For display, the DA3 convention is inverse-depth →
97
+ percentile 2–98 normalize → `Spectral` colormap.
98
+
99
+ ## Fidelity
100
+
101
+ - **Bit-exact conversion:** the Core AI engine matches the PyTorch reference at **cos 1.000000** (≤
102
+ ~1e-5 / ~1e-2 per-pixel for fp32 / fp16) on both CPU and GPU, at any fixed input shape.
103
+ - **vs the official DA3 viewer:** **mean Pearson r ≈ 0.98** across diverse aspect ratios (square
104
+ inputs r = 1.000) — within DA3's own resolution sensitivity (its 504-vs-518 outputs differ by
105
+ r ≈ 0.975–0.984).
106
+
107
+ ## Usage (CoreAIKit / coreai.runtime)
108
+
109
+ ```python
110
+ import coreai.runtime as rt, numpy as np
111
+ from PIL import Image
112
+
113
+ m = await rt.AIModel.load("small/da3-small_float16.aimodel",
114
+ rt.SpecializationOptions.from_preferred_compute_unit_kind(rt.ComputeUnitKind.gpu()))
115
+ fn = m.load_function("main")
116
+
117
+ img = np.asarray(Image.open("photo.jpg").convert("RGB").resize((504, 504)))
118
+ x = (img.astype(np.float16) / 255.0).transpose(2, 0, 1)[None] # raw [0,1], NCHW
119
+ depth = (await fn({"image": rt.NDArray(x)}))["depth"].numpy().reshape(504, 504)
120
+ ```
121
+
122
+ ## Links
123
+
124
+ - Conversion script + model card: [coreai-model-zoo `zoo/depth-anything-3.md`](https://github.com/john-rocky/coreai-model-zoo/blob/main/zoo/depth-anything-3.md)
125
+ - Source: [Depth Anything 3](https://github.com/ByteDance-Seed/depth-anything-3) · Apache-2.0
126
+
127
+ ---
128
+
129
+ *On-device ML / Core ML / Core AI model porting — get in touch: open an issue on the
130
+ [zoo](https://github.com/john-rocky/coreai-model-zoo).*
base/da3-base_float16.aimodel/main.hash ADDED
@@ -0,0 +1 @@
 
 
1
+ �8\�I��V!��K�פѪ��J�P��Gg��
base/da3-base_float16.aimodel/main.mlirb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed385ced49b3e2975621b8d54bead7a410d1aa19d818bc4ac150a1c04767f7bb
3
+ size 201980350
base/da3-base_float16.aimodel/metadata.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "license" : "Apache-2.0",
3
+ "creationDate" : "20260623T154004Z",
4
+ "assetVersion" : "2.0",
5
+ "description" : "Depth Anything 3 (DINOv2 ViT-S backbone + DualDPT head), monocular depth. Input: RGB [0,1]; outputs: relative depth + confidence map. https:\/\/github.com\/ByteDance-Seed\/depth-anything-3",
6
+ "author" : "ByteDance (Depth Anything 3); Core AI export: coreai-model-zoo"
7
+ }
base/da3-base_float32.aimodel/main.hash ADDED
@@ -0,0 +1 @@
 
 
1
+ ����Z��,�]-T#�Uo���ZC� Ƀu .p
base/da3-base_float32.aimodel/main.mlirb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8896cd06d05ae7e12ca85d2d5423d7556ff0f8c15a43c10b07c983751f092e70
3
+ size 401763991
base/da3-base_float32.aimodel/metadata.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "creationDate" : "20260623T153804Z",
3
+ "license" : "Apache-2.0",
4
+ "assetVersion" : "2.0",
5
+ "description" : "Depth Anything 3 (DINOv2 ViT-S backbone + DualDPT head), monocular depth. Input: RGB [0,1]; outputs: relative depth + confidence map. https:\/\/github.com\/ByteDance-Seed\/depth-anything-3",
6
+ "author" : "ByteDance (Depth Anything 3); Core AI export: coreai-model-zoo"
7
+ }
small/da3-small_float16.aimodel/main.hash ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ `Iց�
2
+ iLm�&��I�?NP`�q�[���4&�
small/da3-small_float16.aimodel/main.mlirb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6049d6818a0a694c6ded26b38849ae3f4e5060ef71171f975bb29cfa3426e307
3
+ size 54518253
small/da3-small_float16.aimodel/metadata.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "author" : "ByteDance (Depth Anything 3); Core AI export: coreai-model-zoo",
3
+ "license" : "Apache-2.0",
4
+ "assetVersion" : "2.0",
5
+ "creationDate" : "20260623T153758Z",
6
+ "description" : "Depth Anything 3 (DINOv2 ViT-S backbone + DualDPT head), monocular depth. Input: RGB [0,1]; outputs: relative depth + confidence map. https:\/\/github.com\/ByteDance-Seed\/depth-anything-3"
7
+ }
small/da3-small_float32.aimodel/main.hash ADDED
@@ -0,0 +1 @@
 
 
1
+ ��fFhdG�%�Rb�[͵n�]�W[o��T� ?�
small/da3-small_float32.aimodel/main.mlirb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1aaaa46646686447e525b60752628a5bcdb56ecb5dd3575b6ffcb354f3093fab
3
+ size 104852846
small/da3-small_float32.aimodel/metadata.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "description" : "Depth Anything 3 (DINOv2 ViT-S backbone + DualDPT head), monocular depth. Input: RGB [0,1]; outputs: relative depth + confidence map. https:\/\/github.com\/ByteDance-Seed\/depth-anything-3",
3
+ "author" : "ByteDance (Depth Anything 3); Core AI export: coreai-model-zoo",
4
+ "creationDate" : "20260623T152907Z",
5
+ "license" : "Apache-2.0",
6
+ "assetVersion" : "2.0"
7
+ }