linhaotong commited on
Commit
d55de36
·
1 Parent(s): ace4129

update examples

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .DS_Store +0 -0
  2. .gitattributes +8 -0
  3. EXAMPLES_DIRECTORY.md +286 -0
  4. UPLOAD_EXAMPLES.md +314 -0
  5. depth_anything_3/app/gradio_app.py +25 -1
  6. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00029.png +3 -0
  7. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00038.png +3 -0
  8. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00049.png +3 -0
  9. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00054.png +3 -0
  10. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00065.png +3 -0
  11. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00070.png +3 -0
  12. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00077.png +3 -0
  13. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00083.png +3 -0
  14. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00095.png +3 -0
  15. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00116.png +3 -0
  16. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00122.png +3 -0
  17. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00129.png +3 -0
  18. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00135.png +3 -0
  19. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00150.png +3 -0
  20. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00159.png +3 -0
  21. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00165.png +3 -0
  22. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00175.png +3 -0
  23. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00180.png +3 -0
  24. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00187.png +3 -0
  25. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00199.png +3 -0
  26. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00209.png +3 -0
  27. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00221.png +3 -0
  28. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00231.png +3 -0
  29. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00237.png +3 -0
  30. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00244.png +3 -0
  31. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00251.png +3 -0
  32. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00257.png +3 -0
  33. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00268.png +3 -0
  34. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00285.png +3 -0
  35. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00305.png +3 -0
  36. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00319.png +3 -0
  37. workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00345.png +3 -0
  38. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00001.png +3 -0
  39. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00015.png +3 -0
  40. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00028.png +3 -0
  41. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00041.png +3 -0
  42. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00050.png +3 -0
  43. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00062.png +3 -0
  44. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00081.png +3 -0
  45. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00093.png +3 -0
  46. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00100.png +3 -0
  47. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00106.png +3 -0
  48. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00113.png +3 -0
  49. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00119.png +3 -0
  50. workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00127.png +3 -0
.DS_Store DELETED
Binary file (6.15 kB)
 
.gitattributes CHANGED
@@ -33,3 +33,11 @@ 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
+
37
+ # Image files in examples directory (for Git LFS)
38
+ workspace/gradio/examples/**/*.png filter=lfs diff=lfs merge=lfs -text
39
+ workspace/gradio/examples/**/*.jpg filter=lfs diff=lfs merge=lfs -text
40
+ workspace/gradio/examples/**/*.jpeg filter=lfs diff=lfs merge=lfs -text
41
+ workspace/gradio/examples/**/*.bmp filter=lfs diff=lfs merge=lfs -text
42
+ workspace/gradio/examples/**/*.tiff filter=lfs diff=lfs merge=lfs -text
43
+ workspace/gradio/examples/**/*.tif filter=lfs diff=lfs merge=lfs -text
EXAMPLES_DIRECTORY.md ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 📁 Examples 目录配置指南
2
+
3
+ ## 📍 Examples 目录位置
4
+
5
+ ### 默认位置
6
+
7
+ Examples 目录应该放在:
8
+
9
+ ```
10
+ workspace/gradio/examples/
11
+ ```
12
+
13
+ ### 完整路径说明
14
+
15
+ 根据 `app.py` 的配置:
16
+
17
+ ```python
18
+ workspace_dir = os.environ.get("DA3_WORKSPACE_DIR", "workspace/gradio")
19
+ examples_dir = os.path.join(workspace_dir, "examples")
20
+ # 结果: workspace/gradio/examples/
21
+ ```
22
+
23
+ ## 📂 目录结构
24
+
25
+ Examples 目录应该按以下结构组织:
26
+
27
+ ```
28
+ workspace/gradio/examples/
29
+ ├── scene1/ # 场景 1
30
+ │ ├── 000.png # 图像文件
31
+ │ ├── 010.png
32
+ │ ├── 020.png
33
+ │ └── ...
34
+ ├── scene2/ # 场景 2
35
+ │ ├── 000.jpg
36
+ │ ├── 010.jpg
37
+ │ └── ...
38
+ └── scene3/ # 场景 3
39
+ ├── image1.png
40
+ ├── image2.png
41
+ └── ...
42
+ ```
43
+
44
+ ### 要求
45
+
46
+ 1. **每个场景一个文件夹**:每个场景应该有自己的文件夹
47
+ 2. **文件夹名称**:文件夹名称会显示为场景名称
48
+ 3. **图像文件**:支持 `.jpg`, `.jpeg`, `.png`, `.bmp`, `.tiff`, `.tif` 格式
49
+ 4. **第一张图像**:第一张图像(按文件名排序)会用作缩略图
50
+
51
+ ## 🔧 配置方式
52
+
53
+ ### 方式 1:使用默认路径(推荐)
54
+
55
+ 直接创建目录:
56
+
57
+ ```bash
58
+ mkdir -p workspace/gradio/examples
59
+ ```
60
+
61
+ 然后添加场景:
62
+
63
+ ```bash
64
+ # 创建场景文件夹
65
+ mkdir -p workspace/gradio/examples/my_scene
66
+
67
+ # 复制图像文件
68
+ cp your_images/* workspace/gradio/examples/my_scene/
69
+ ```
70
+
71
+ ### 方式 2:使用环境变量
72
+
73
+ 通过环境变量自定义位置:
74
+
75
+ ```bash
76
+ # 设置环境变量
77
+ export DA3_WORKSPACE_DIR="/path/to/your/workspace"
78
+
79
+ # 然后 examples 会在 /path/to/your/workspace/examples
80
+ ```
81
+
82
+ 或在 `app.py` 中修改:
83
+
84
+ ```python
85
+ workspace_dir = os.environ.get("DA3_WORKSPACE_DIR", "/custom/path/workspace")
86
+ ```
87
+
88
+ ### 方式 3:在 Hugging Face Spaces 中
89
+
90
+ 在 Spaces 中,可以通过以下方式添加 examples:
91
+
92
+ 1. **通过 Git 上传**:
93
+ ```bash
94
+ git add workspace/gradio/examples/
95
+ git commit -m "Add example scenes"
96
+ git push
97
+ ```
98
+
99
+ 2. **通过网页界面上传**:
100
+ - 在 Spaces 的文件浏览器中创建 `workspace/gradio/examples/` 目录
101
+ - 上传场景文件夹和图像
102
+
103
+ 3. **使用持久存储**:
104
+ - 如果使用持久存储,examples 会保存在持久存储中
105
+ - 路径仍然是 `workspace/gradio/examples/`
106
+
107
+ ## 📝 示例场景结构示例
108
+
109
+ ### 示例 1:简单场景
110
+
111
+ ```
112
+ workspace/gradio/examples/
113
+ └── indoor_room/
114
+ ├── 000.png
115
+ ├── 010.png
116
+ ├── 020.png
117
+ └── 030.png
118
+ ```
119
+
120
+ ### 示例 2:多个场景
121
+
122
+ ```
123
+ workspace/gradio/examples/
124
+ ├── outdoor_garden/
125
+ │ ├── frame_001.jpg
126
+ │ ├── frame_002.jpg
127
+ │ └── frame_003.jpg
128
+ ├── office_space/
129
+ │ ├── img_000.png
130
+ │ ├── img_010.png
131
+ │ └── img_020.png
132
+ └── street_scene/
133
+ ├── 000.png
134
+ ├── 010.png
135
+ └── 020.png
136
+ ```
137
+
138
+ ## 🔍 验证 Examples 目录
139
+
140
+ ### 检查目录是否存在
141
+
142
+ ```bash
143
+ # 检查默认位置
144
+ ls -la workspace/gradio/examples/
145
+
146
+ # 或使用 Python
147
+ python -c "
148
+ import os
149
+ workspace_dir = os.environ.get('DA3_WORKSPACE_DIR', 'workspace/gradio')
150
+ examples_dir = os.path.join(workspace_dir, 'examples')
151
+ print(f'Examples directory: {examples_dir}')
152
+ print(f'Exists: {os.path.exists(examples_dir)}')
153
+ if os.path.exists(examples_dir):
154
+ scenes = [d for d in os.listdir(examples_dir) if os.path.isdir(os.path.join(examples_dir, d))]
155
+ print(f'Found {len(scenes)} scenes: {scenes}')
156
+ "
157
+ ```
158
+
159
+ ### 检查场景信息
160
+
161
+ 应用启动时会自动扫描 examples 目录,并在日志中显示:
162
+
163
+ ```
164
+ Found 3 example scenes:
165
+ - scene1 (5 images)
166
+ - scene2 (10 images)
167
+ - scene3 (8 images)
168
+ ```
169
+
170
+ ## 🚀 快速开始
171
+
172
+ ### 1. 创建目录结构
173
+
174
+ ```bash
175
+ # 在项目根目录
176
+ mkdir -p workspace/gradio/examples
177
+ ```
178
+
179
+ ### 2. 添加示例场景
180
+
181
+ ```bash
182
+ # 创建场景文件夹
183
+ mkdir -p workspace/gradio/examples/my_first_scene
184
+
185
+ # 添加图像文件(复制你的图像)
186
+ cp /path/to/your/images/* workspace/gradio/examples/my_first_scene/
187
+ ```
188
+
189
+ ### 3. 验证
190
+
191
+ 启动应用后,你应该能在 UI 中看到示例场景网格。
192
+
193
+ ## 📊 在 Hugging Face Spaces 中
194
+
195
+ ### 上传方式
196
+
197
+ 1. **通过 Git**(推荐):
198
+ ```bash
199
+ # 在本地准备 examples
200
+ mkdir -p workspace/gradio/examples
201
+ # ... 添加场景 ...
202
+
203
+ # 提交并推送
204
+ git add workspace/gradio/examples/
205
+ git commit -m "Add example scenes"
206
+ git push
207
+ ```
208
+
209
+ 2. **通过网页界面**:
210
+ - 在 Spaces 的文件浏览器中
211
+ - 创建 `workspace/gradio/examples/` 目录
212
+ - 上传场景文件夹
213
+
214
+ ### 注意事项
215
+
216
+ - **文件大小限制**:确保图像文件不超过 Spaces 的文件大小限制
217
+ - **持久存储**:如果使用持久存储,examples 会持久保存
218
+ - **缓存**:示例场景的结果会缓存在 `workspace/gradio/input_images/` 下
219
+
220
+ ## 🔗 相关配置
221
+
222
+ ### 环境变量
223
+
224
+ - `DA3_WORKSPACE_DIR`: 工作空间目录(默认:`workspace/gradio`)
225
+ - Examples 目录自动设置为:`{DA3_WORKSPACE_DIR}/examples`
226
+
227
+ ### 代码中的配置
228
+
229
+ - `depth_anything_3/app/gradio_app.py`: `cache_examples()` 方法
230
+ - `depth_anything_3/app/modules/utils.py`: `get_scene_info()` 函数
231
+ - `depth_anything_3/app/modules/event_handlers.py`: `load_example_scene()` 方法
232
+
233
+ ## ❓ 常见问题
234
+
235
+ ### Q: Examples 目录不存在怎么办?
236
+
237
+ A: 应用会自动创建 `workspace/gradio/` 目录,但不会自动创建 `examples/` 子目录。你需要手动创建:
238
+
239
+ ```bash
240
+ mkdir -p workspace/gradio/examples
241
+ ```
242
+
243
+ ### Q: 如何添加新的示例场景?
244
+
245
+ A: 只需在 `workspace/gradio/examples/` 下创建新文件夹并添加图像:
246
+
247
+ ```bash
248
+ mkdir -p workspace/gradio/examples/new_scene
249
+ cp images/* workspace/gradio/examples/new_scene/
250
+ ```
251
+
252
+ 应用会在下次启动时自动检测新场景。
253
+
254
+ ### Q: 场景名称如何显示?
255
+
256
+ A: 场景名称就是文件夹名称。例如:
257
+ - 文件夹:`workspace/gradio/examples/indoor_room/`
258
+ - 显示名称:`indoor_room`
259
+
260
+ ### Q: 缩略图如何选择?
261
+
262
+ A: 缩略图是文件夹中按文件名排序后的第一张图像。
263
+
264
+ ## 📝 总结
265
+
266
+ **Examples 目录位置:**
267
+ - **默认**:`workspace/gradio/examples/`
268
+ - **可通过环境变量**:`DA3_WORKSPACE_DIR` 自定义
269
+
270
+ **目录结构:**
271
+ ```
272
+ workspace/gradio/examples/
273
+ ├── scene1/
274
+ │ └── images...
275
+ ├── scene2/
276
+ │ └── images...
277
+ └── scene3/
278
+ └── images...
279
+ ```
280
+
281
+ **快速创建:**
282
+ ```bash
283
+ mkdir -p workspace/gradio/examples
284
+ # 然后添加场景文件夹和图像
285
+ ```
286
+
UPLOAD_EXAMPLES.md ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 📤 上传 Examples 到 Hugging Face Spaces 指南
2
+
3
+ ## 🚨 问题:二进制文件被拒绝
4
+
5
+ Hugging Face Spaces 会拒绝大文件(>100MB)或二进制文件,需要使用 **Git LFS** 来上传。
6
+
7
+ ## ✅ 解决方案
8
+
9
+ ### 方案 1:使用 Git LFS(推荐)⭐
10
+
11
+ #### 步骤 1:配置 Git LFS
12
+
13
+ 我已经为你创建了 `.gitattributes` 文件,配置了图片文件的 Git LFS:
14
+
15
+ ```gitattributes
16
+ # Images in examples directory
17
+ workspace/gradio/examples/**/*.png filter=lfs diff=lfs merge=lfs -text
18
+ workspace/gradio/examples/**/*.jpg filter=lfs diff=lfs merge=lfs -text
19
+ workspace/gradio/examples/**/*.jpeg filter=lfs diff=lfs merge=lfs -text
20
+ workspace/gradio/examples/**/*.bmp filter=lfs diff=lfs merge=lfs -text
21
+ workspace/gradio/examples/**/*.tiff filter=lfs diff=lfs merge=lfs -text
22
+ workspace/gradio/examples/**/*.tif filter=lfs diff=lfs merge=lfs -text
23
+ ```
24
+
25
+ #### 步骤 2:安装 Git LFS(如果还没有)
26
+
27
+ ```bash
28
+ # macOS
29
+ brew install git-lfs
30
+
31
+ # Linux
32
+ sudo apt-get install git-lfs
33
+
34
+ # Windows
35
+ # 下载安装:https://git-lfs.github.com/
36
+ ```
37
+
38
+ #### 步骤 3:初始化 Git LFS
39
+
40
+ ```bash
41
+ cd /Users/bytedance/depth-anything-3
42
+
43
+ # 初始化 Git LFS
44
+ git lfs install
45
+
46
+ # 验证配置
47
+ git lfs track
48
+ ```
49
+
50
+ #### 步骤 4:添加示例场景
51
+
52
+ ```bash
53
+ # 创建 examples 目录
54
+ mkdir -p workspace/gradio/examples/my_scene
55
+
56
+ # 添加图像文件
57
+ cp your_images/* workspace/gradio/examples/my_scene/
58
+
59
+ # 添加文件到 Git LFS
60
+ git add workspace/gradio/examples/
61
+ git add .gitattributes
62
+
63
+ # 提交
64
+ git commit -m "Add example scenes with Git LFS"
65
+
66
+ # 推送到 Spaces
67
+ git push origin main
68
+ ```
69
+
70
+ #### 步骤 5:验证
71
+
72
+ ```bash
73
+ # 检查哪些文件使用了 LFS
74
+ git lfs ls-files
75
+
76
+ # 应该看到你的图片文件
77
+ ```
78
+
79
+ ---
80
+
81
+ ### 方案 2:使用持久存储(推荐用于大量数据)⭐
82
+
83
+ 如果示例场景很大,可以使用 Hugging Face Spaces 的持久存储功能。
84
+
85
+ #### 步骤 1:在 Spaces 设置中启用持久存储
86
+
87
+ 1. 进入你的 Space 设置
88
+ 2. 启用 "Persistent storage"
89
+ 3. 设置存储大小(如 50GB)
90
+
91
+ #### 步骤 2:在应用启动时下载示例
92
+
93
+ 修改 `app.py`,在启动时从外部源下载示例:
94
+
95
+ ```python
96
+ import os
97
+ import subprocess
98
+
99
+ def download_examples():
100
+ """Download examples from external source if not exists"""
101
+ examples_dir = "workspace/gradio/examples"
102
+ if not os.path.exists(examples_dir) or not os.listdir(examples_dir):
103
+ print("Downloading example scenes...")
104
+ # 从 Hugging Face Dataset 下载
105
+ # 或从其他存储服务下载
106
+ # subprocess.run(["huggingface-cli", "download", "dataset/examples", ...])
107
+ pass
108
+
109
+ if __name__ == "__main__":
110
+ download_examples()
111
+ # ... 启动应用
112
+ ```
113
+
114
+ #### 步骤 3:上传到 Hugging Face Dataset
115
+
116
+ ```bash
117
+ # 安装依赖
118
+ pip install huggingface_hub datasets
119
+
120
+ # 上传到 Dataset
121
+ python -c "
122
+ from datasets import Dataset
123
+ from huggingface_hub import HfApi
124
+
125
+ # 创建 dataset 并上传
126
+ api = HfApi()
127
+ api.upload_folder(
128
+ folder_path='workspace/gradio/examples',
129
+ repo_id='your-username/your-examples-dataset',
130
+ repo_type='dataset'
131
+ )
132
+ "
133
+ ```
134
+
135
+ ---
136
+
137
+ ### 方案 3:压缩后上传(小文件)
138
+
139
+ 如果图片文件较小(<100MB),可以压缩后上传:
140
+
141
+ ```bash
142
+ # 压缩 examples 目录
143
+ tar -czf examples.tar.gz workspace/gradio/examples/
144
+
145
+ # 添加到 Git(作为普通文件)
146
+ git add examples.tar.gz
147
+ git commit -m "Add compressed examples"
148
+ git push
149
+
150
+ # 在应用启动时解压
151
+ # 在 app.py 中添加:
152
+ import tarfile
153
+ if not os.path.exists("workspace/gradio/examples"):
154
+ print("Extracting examples...")
155
+ tarfile.open("examples.tar.gz").extractall()
156
+ ```
157
+
158
+ ---
159
+
160
+ ### 方案 4:运行时下载(推荐用于生产)⭐
161
+
162
+ 在应用启动时从外部源下载示例场景:
163
+
164
+ #### 修改 `app.py`
165
+
166
+ ```python
167
+ import os
168
+ import subprocess
169
+ from huggingface_hub import hf_hub_download
170
+
171
+ def setup_examples():
172
+ """Setup examples directory by downloading if needed"""
173
+ examples_dir = "workspace/gradio/examples"
174
+ os.makedirs(examples_dir, exist_ok=True)
175
+
176
+ # 如果 examples 目录为空,从外部源下载
177
+ if not os.listdir(examples_dir):
178
+ print("📥 Downloading example scenes...")
179
+
180
+ # 方式 1: 从 Hugging Face Dataset 下载
181
+ try:
182
+ from datasets import load_dataset
183
+ dataset = load_dataset("your-username/your-examples-dataset")
184
+ # 处理并保存到 examples_dir
185
+ except:
186
+ pass
187
+
188
+ # 方式 2: 从 URL 下载压缩包
189
+ # import urllib.request
190
+ # urllib.request.urlretrieve("https://...", "examples.zip")
191
+ # 解压到 examples_dir
192
+
193
+ print("✅ Examples downloaded")
194
+
195
+ if __name__ == "__main__":
196
+ setup_examples()
197
+ # ... 启动应用
198
+ ```
199
+
200
+ ---
201
+
202
+ ## 🎯 推荐方案对比
203
+
204
+ | 方案 | 优点 | 缺点 | 适用场景 |
205
+ |------|------|------|----------|
206
+ | **Git LFS** | ✅ 简单直接<br>✅ 版���控制 | ⚠️ 需要 LFS 配额<br>⚠️ 大文件可能慢 | 小到中等示例(<1GB) |
207
+ | **持久存储** | ✅ 无大小限制<br>✅ 快速访问 | ⚠️ 需要手动上传<br>⚠️ 需要付费 | 大量示例(>1GB) |
208
+ | **运行时下载** | ✅ 不占用仓库空间<br>✅ 灵活 | ⚠️ 首次启动慢<br>⚠️ 需要网络 | 生产环境 |
209
+ | **压缩上传** | ✅ 简单 | ⚠️ 大小限制<br>⚠️ 需要解压 | 小文件(<100MB) |
210
+
211
+ ---
212
+
213
+ ## 📝 完整 Git LFS 设置步骤
214
+
215
+ ### 1. 确保 Git LFS 已安装
216
+
217
+ ```bash
218
+ git lfs version
219
+ # 如果未安装,按照上面的步骤安装
220
+ ```
221
+
222
+ ### 2. 初始化 Git LFS
223
+
224
+ ```bash
225
+ cd /Users/bytedance/depth-anything-3
226
+ git lfs install
227
+ ```
228
+
229
+ ### 3. 检查 .gitattributes
230
+
231
+ 确保 `.gitattributes` 包含图片文件配置(我已经添加了)。
232
+
233
+ ### 4. 添加示例场景
234
+
235
+ ```bash
236
+ # 创建场景
237
+ mkdir -p workspace/gradio/examples/scene1
238
+ cp your_images/* workspace/gradio/examples/scene1/
239
+
240
+ # 添加文件
241
+ git add workspace/gradio/examples/
242
+ git add .gitattributes
243
+
244
+ # 检查哪些文件会使用 LFS
245
+ git lfs ls-files
246
+
247
+ # 提交
248
+ git commit -m "Add example scenes with Git LFS"
249
+
250
+ # 推送
251
+ git push origin main
252
+ ```
253
+
254
+ ### 5. 验证上传
255
+
256
+ 在 Spaces 中检查文件是否成功上传,图片文件应该显示为 LFS 指针。
257
+
258
+ ---
259
+
260
+ ## 🔧 故障排除
261
+
262
+ ### 问题 1:Git LFS 配额不足
263
+
264
+ **解决方案:**
265
+ - 使用方案 2(持久存储)或方案 4(运行时下载)
266
+ - 压缩图片文件
267
+ - 只上传必要的示例
268
+
269
+ ### 问题 2:推送失败
270
+
271
+ **检查:**
272
+ ```bash
273
+ # 检查 LFS 文件
274
+ git lfs ls-files
275
+
276
+ # 检查 LFS 状态
277
+ git lfs status
278
+
279
+ # 重新推送
280
+ git push origin main --force
281
+ ```
282
+
283
+ ### 问题 3:文件仍然被拒绝
284
+
285
+ **可能原因:**
286
+ - `.gitattributes` 配置不正确
287
+ - 文件没有通过 LFS 添加
288
+
289
+ **解决:**
290
+ ```bash
291
+ # 移除并重新添加
292
+ git rm --cached workspace/gradio/examples/**/*.png
293
+ git add workspace/gradio/examples/
294
+ git commit -m "Fix: Add images via Git LFS"
295
+ git push
296
+ ```
297
+
298
+ ---
299
+
300
+ ## 💡 最佳实践
301
+
302
+ 1. **小示例(<100MB)**:使用 Git LFS
303
+ 2. **中等示例(100MB-1GB)**:使用 Git LFS 或持久存储
304
+ 3. **大示例(>1GB)**:使用持久存储或运行时下载
305
+ 4. **生产环境**:使用运行时下载,从外部源获取
306
+
307
+ ---
308
+
309
+ ## 📚 相关资源
310
+
311
+ - [Git LFS 文档](https://git-lfs.github.com/)
312
+ - [Hugging Face Spaces 文档](https://huggingface.co/docs/hub/spaces)
313
+ - [Hugging Face Datasets](https://huggingface.co/docs/datasets)
314
+
depth_anything_3/app/gradio_app.py CHANGED
@@ -21,6 +21,7 @@ The original functionality has been split into modular components for better mai
21
 
22
  import argparse
23
  import os
 
24
  from typing import Any, Dict, List
25
  import gradio as gr
26
 
@@ -575,7 +576,16 @@ class DepthAnything3App:
575
  ) -> None:
576
  """Set up example scene handlers."""
577
 
 
 
 
578
  def load_and_update_measure(name):
 
 
 
 
 
 
579
  result = self.event_handlers.load_example_scene(name)
580
  # result = (reconstruction_output, target_dir, image_paths, log_message, processed_data, measure_view_selector, gs_video, gs_video_vis, gs_info_vis) # noqa: E501
581
 
@@ -587,8 +597,19 @@ class DepthAnything3App:
587
  self.event_handlers.visualization_handler.update_measure_view(result[4], 0)
588
  )
589
 
590
- return result + ("True", measure_img, measure_depth)
 
 
 
 
 
 
 
 
 
591
 
 
 
592
  for i, scene in enumerate(scenes):
593
  if i < len(scene_components):
594
  scene_components[i].select(
@@ -607,6 +628,9 @@ class DepthAnything3App:
607
  measure_image,
608
  measure_depth_image,
609
  ],
 
 
 
610
  )
611
 
612
  def launch(self, host: str = "127.0.0.1", port: int = 7860, **kwargs) -> None:
 
21
 
22
  import argparse
23
  import os
24
+ from functools import lru_cache
25
  from typing import Any, Dict, List
26
  import gradio as gr
27
 
 
576
  ) -> None:
577
  """Set up example scene handlers."""
578
 
579
+ # Cache for example scene loading (in-memory cache for faster access)
580
+ _example_cache = {}
581
+
582
  def load_and_update_measure(name):
583
+ # Check cache first
584
+ if name in _example_cache:
585
+ print(f"✅ Using cached result for example scene: {name}")
586
+ return _example_cache[name]
587
+
588
+ # Load example scene
589
  result = self.event_handlers.load_example_scene(name)
590
  # result = (reconstruction_output, target_dir, image_paths, log_message, processed_data, measure_view_selector, gs_video, gs_video_vis, gs_info_vis) # noqa: E501
591
 
 
597
  self.event_handlers.visualization_handler.update_measure_view(result[4], 0)
598
  )
599
 
600
+ final_result = result + ("True", measure_img, measure_depth)
601
+
602
+ # Cache the result (limit cache size to prevent memory issues)
603
+ if len(_example_cache) < 20: # Cache up to 20 scenes
604
+ _example_cache[name] = final_result
605
+ print(f"💾 Cached result for example scene: {name}")
606
+ else:
607
+ print(f"⚠️ Cache full, not caching: {name}")
608
+
609
+ return final_result
610
 
611
+ # Enable caching for example scene loading
612
+ # Gradio will cache the results based on the scene name
613
  for i, scene in enumerate(scenes):
614
  if i < len(scene_components):
615
  scene_components[i].select(
 
628
  measure_image,
629
  measure_depth_image,
630
  ],
631
+ # Note: cache_examples is not a valid parameter for select()
632
+ # Caching is handled by file-based cache in load_example_scene()
633
+ # which checks for predictions.npz files
634
  )
635
 
636
  def launch(self, host: str = "127.0.0.1", port: int = 7860, **kwargs) -> None:
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00029.png ADDED

Git LFS Details

  • SHA256: d34d22028d6236520cc63efa692ee8ac16dfa321461a8ca1c275087a63937dcb
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00038.png ADDED

Git LFS Details

  • SHA256: aafa6ab14852b18a867d555e5652fdb0ffc01cc9970e20716c839026773f464a
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00049.png ADDED

Git LFS Details

  • SHA256: 564eb4bc3086989c42b557b23f183c288d36c06061718d7063dbc0a916367c88
  • Pointer size: 132 Bytes
  • Size of remote file: 1.02 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00054.png ADDED

Git LFS Details

  • SHA256: 4d3f99b1a5ec3f7dd4c99e663e2b7af752c77ff2d70b5e45039f085c2d8853e7
  • Pointer size: 132 Bytes
  • Size of remote file: 1.02 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00065.png ADDED

Git LFS Details

  • SHA256: 664b8d51688f0daa894f7ce6742b96cfd1188d9f8f66b0f61cd3c20569a4310a
  • Pointer size: 132 Bytes
  • Size of remote file: 1.02 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00070.png ADDED

Git LFS Details

  • SHA256: 9bfc3f897df6590b593a4eaa9af79c8bdc3b5c91d1a19496e0a83f9bf421b7b5
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00077.png ADDED

Git LFS Details

  • SHA256: 7205b8b96cbbe6ed6623460b19f37a44369c752553014ccb4bddb570a2321533
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00083.png ADDED

Git LFS Details

  • SHA256: ee821f71850df7c9178293fdbdf713655412a4fb3917478e91c25e289cf4fbbc
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00095.png ADDED

Git LFS Details

  • SHA256: 85280efc065ac29953d3320e7d12bc58aac4c45283322295edda5774fcb3ed86
  • Pointer size: 132 Bytes
  • Size of remote file: 1.09 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00116.png ADDED

Git LFS Details

  • SHA256: 377c78bd24ac4ef431343f47075a02b948c83a64c2c94127d96bbb2e73bb3b73
  • Pointer size: 132 Bytes
  • Size of remote file: 1.02 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00122.png ADDED

Git LFS Details

  • SHA256: 787262a0b026989c553b19de050a30dc0f244380a05f4ebdd1a1a9ee65c811cf
  • Pointer size: 132 Bytes
  • Size of remote file: 1.03 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00129.png ADDED

Git LFS Details

  • SHA256: 7cd060ba5838478b51b3b65a5b3fcdcebad707978d535d883c6c144941703d3b
  • Pointer size: 131 Bytes
  • Size of remote file: 976 kB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00135.png ADDED

Git LFS Details

  • SHA256: fe9ce1643b05643d2dfd63e93cadd3fd6653b8a9a689d5f4cce457975617f991
  • Pointer size: 132 Bytes
  • Size of remote file: 1 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00150.png ADDED

Git LFS Details

  • SHA256: a9d77e51d7d3e096d39cfbf3d3c714f281c13494b8bd67a3c9853c21c03d31bd
  • Pointer size: 131 Bytes
  • Size of remote file: 944 kB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00159.png ADDED

Git LFS Details

  • SHA256: 230fca2d36beb7e09d91c4d89df4379f72518eb74e07510527e0bf6e3d602925
  • Pointer size: 132 Bytes
  • Size of remote file: 1.02 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00165.png ADDED

Git LFS Details

  • SHA256: ea90cd1ebfbc1f88c018338b069b7aede87ec73526f7ccfc00d91050d034c74f
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00175.png ADDED

Git LFS Details

  • SHA256: 4756bbf8aa9c88e94127132372d6266ed1dadb17e2ca7fed9aed785f4fb2f913
  • Pointer size: 131 Bytes
  • Size of remote file: 974 kB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00180.png ADDED

Git LFS Details

  • SHA256: 775520bb5ea29d521297824ee439ad9ad537c6ca904aee095ba1df9b849b4bd5
  • Pointer size: 131 Bytes
  • Size of remote file: 966 kB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00187.png ADDED

Git LFS Details

  • SHA256: bc3bac9dffda333818e3bbd8cf120ae2e8e18ec6516f6ddeb5f13775b9ebd804
  • Pointer size: 131 Bytes
  • Size of remote file: 934 kB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00199.png ADDED

Git LFS Details

  • SHA256: 502512cafed3f5afe994d54716314389ed9ba899da0be9138f2abae238ebaf54
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00209.png ADDED

Git LFS Details

  • SHA256: b8757598c24e5b2a266f5391131659e2dd135da11e439c44ec74da156774e118
  • Pointer size: 132 Bytes
  • Size of remote file: 1.12 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00221.png ADDED

Git LFS Details

  • SHA256: f593286997e1310926b5b5ca1cbc7a5d0b1d5309fafa8d46d9aff25d81c80551
  • Pointer size: 132 Bytes
  • Size of remote file: 1.11 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00231.png ADDED

Git LFS Details

  • SHA256: 29d9ea752ec10356d7ef0651822164665a721fe020619daa3d7f294557680d24
  • Pointer size: 132 Bytes
  • Size of remote file: 1.15 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00237.png ADDED

Git LFS Details

  • SHA256: ffe5d6ee39dffb840dbe3155bd6c6221324daaae41226aef40952c86a7f4d307
  • Pointer size: 132 Bytes
  • Size of remote file: 1.09 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00244.png ADDED

Git LFS Details

  • SHA256: 4dc5d0c7ddd6e9fa3cec34d8d4cdf914639c059f6776f40dbb7a426fdb03b149
  • Pointer size: 132 Bytes
  • Size of remote file: 1.11 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00251.png ADDED

Git LFS Details

  • SHA256: 63cdc5c214b8b7a2ea9ebf2d45ca06be32142a6491881bfd6f89d9a5e980a190
  • Pointer size: 132 Bytes
  • Size of remote file: 1.07 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00257.png ADDED

Git LFS Details

  • SHA256: 26c57588b6c894c997abac976c3a2af638de901f4e7fc92a3fbcad6d4f6c5650
  • Pointer size: 132 Bytes
  • Size of remote file: 1.06 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00268.png ADDED

Git LFS Details

  • SHA256: 8f1b3de675af869d1a2c6b5a8399cf734acf3c357d4aa973562a6a3e6c830829
  • Pointer size: 132 Bytes
  • Size of remote file: 1.22 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00285.png ADDED

Git LFS Details

  • SHA256: dce4315eee0b82fc0f634ad4c3ea5b1ac6025bc4ca29119e21c3194bac4ed758
  • Pointer size: 132 Bytes
  • Size of remote file: 1.06 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00305.png ADDED

Git LFS Details

  • SHA256: f6d4413df7fb3199fe5aa9a5564eb57fa2771cc14e2256af71d730f843d2da34
  • Pointer size: 132 Bytes
  • Size of remote file: 1.08 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00319.png ADDED

Git LFS Details

  • SHA256: 7085b280721bad49223f39da092c8eca88ba54367f8806ce4b64402c2ba04e68
  • Pointer size: 132 Bytes
  • Size of remote file: 1.05 MB
workspace/gradio/examples/DL3DV_10K_a401469cb0/frame_00345.png ADDED

Git LFS Details

  • SHA256: e66d72cc2adb3d58da43ef0b08ad49f2d5efa26d3858e71a4e0bef94550e282d
  • Pointer size: 131 Bytes
  • Size of remote file: 953 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00001.png ADDED

Git LFS Details

  • SHA256: 575aeaed9845079d790e832846bebed8dabd6ebb428856d6a767fbf4e45e5b97
  • Pointer size: 131 Bytes
  • Size of remote file: 835 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00015.png ADDED

Git LFS Details

  • SHA256: 0c75ab3c0d7dacded865960e1bb8be1f02205e2711b25f3f03c06c2b5ec07c56
  • Pointer size: 131 Bytes
  • Size of remote file: 819 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00028.png ADDED

Git LFS Details

  • SHA256: 32c92e518100e6b477d3b94643ca29cf20a097e417571da69c831cd5a5aa08b6
  • Pointer size: 131 Bytes
  • Size of remote file: 775 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00041.png ADDED

Git LFS Details

  • SHA256: ed424f7ecb54bec7217cf837f1aeb8651c46ea7c5a5b213fdbddd0f74ac06bb7
  • Pointer size: 131 Bytes
  • Size of remote file: 803 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00050.png ADDED

Git LFS Details

  • SHA256: 70c9704091b897bcb2270d9c28d01d35dbfdcf3cf85b75406c8d9774dca60404
  • Pointer size: 131 Bytes
  • Size of remote file: 794 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00062.png ADDED

Git LFS Details

  • SHA256: 8468ff88ef94a7945770b959d19c2345594501ed07f428ba8e677fe7e3cfc065
  • Pointer size: 131 Bytes
  • Size of remote file: 804 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00081.png ADDED

Git LFS Details

  • SHA256: 00b0040fd470df44910b1a743b2808fea2957f70e0a0d3a5745309295a2509fd
  • Pointer size: 131 Bytes
  • Size of remote file: 873 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00093.png ADDED

Git LFS Details

  • SHA256: 2f21073de82d8e0f81c6de27bebac54b38fc322c20d78dfbc8cdaa3bdf1c2e11
  • Pointer size: 131 Bytes
  • Size of remote file: 882 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00100.png ADDED

Git LFS Details

  • SHA256: f5160b77b1787e16fe5596bd3bbb04c43266c069322916e3a7fb66c3f5a9a4b7
  • Pointer size: 131 Bytes
  • Size of remote file: 939 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00106.png ADDED

Git LFS Details

  • SHA256: 33eb664ad34f2cbbf810d08b109b416bc2790694ad20e34e1976662d8100bb8c
  • Pointer size: 131 Bytes
  • Size of remote file: 945 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00113.png ADDED

Git LFS Details

  • SHA256: 8b01df8719d56829e14002dce91de54cc44a0d5f0c32b32c85fd2957d66b4ccd
  • Pointer size: 131 Bytes
  • Size of remote file: 939 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00119.png ADDED

Git LFS Details

  • SHA256: 0124a2ac0e0b094b9c6f7df11f0bea410ac64c737c7392cdefe0c69e2ab78d9d
  • Pointer size: 131 Bytes
  • Size of remote file: 918 kB
workspace/gradio/examples/DL3DV_10K_cc08c0bdc3/frame_00127.png ADDED

Git LFS Details

  • SHA256: 5e9023b75d6f0cd3df57d8b146bf89b3ecdbca5844596daaa21d99b893a6c2f3
  • Pointer size: 131 Bytes
  • Size of remote file: 931 kB