首页
/ 开源项目最佳实践:Prior-Depth-Anything

开源项目最佳实践:Prior-Depth-Anything

2025-05-19 18:27:34作者:江焘钦

1. 项目介绍

Prior-Depth-Anything 是一个开源项目,旨在结合不完整但精确的深度测量度量和相对但完整的几何结构深度预测,为任何场景生成准确、密集和详细的度量化深度图。该框架通过整合先验深度信息与图像内容,提高了深度估计的精度和鲁棒性。

2. 项目快速启动

环境准备

首先,确保您的系统中安装了 Python 3.9,然后克隆仓库并创建一个新的虚拟环境:

git clone https://github.com/SpatialVision/Prior-Depth-Anything.git
conda create -n priorda python=3.9
conda activate priorda
cd Prior-Depth-Anything

安装依赖

接下来,安装项目所需的依赖:

pip install -r requirements.txt

或者,您可以选择将 Prior-Depth-Anything 安装为包:

pip install -e .

运行示例

运行以下命令来执行 CLI 演示。首次执行时,模型权重将自动从 Hugging Face Model Hub 下载:

priorda test --image_path assets/sample-1/rgb.jpg --prior_path assets/sample-1/gt_depth.png --pattern downscale_32 --visualize 1

或者,您可以使用 Python 代码来运行演示:

import torch
from prior_depth_anything import PriorDepthAnything

device = "cuda:0" if torch.cuda.is_available() else "cpu"
priorda = PriorDepthAnything(device=device)

image_path = 'assets/sample-2/rgb.jpg'
prior_path = 'assets/sample-2/prior_depth.png'

output = priorda.infer_one_sample(image=image_path, prior=prior_path, visualize=True)

运行完成后,结果将保存到 ./output 目录中。

3. 应用案例和最佳实践

使用 Prior-Depth-Anything 作为插件

Prior-Depth-Anything 展示了出色的零样本鲁棒性,即使在多变且可能嘈杂的先验输入存在下也能工作。它可以作为一个即插即用的模块,集成到其他深度估计框架中,提高其性能。

以下是一个使用 VGGT 模型的示例:

  1. 使用 VGGT 模型预测深度图。
  2. 使用 Prior-Depth-Anything 来细化深度图。
import torch
from vggt.models.vggt import VGGT
from vggt.utils.load_fn import load_and_preprocess_images

device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] >= 8 else torch.float16

model = VGGT.from_pretrained("facebook/VGGT-1B").to(device)

image_names = ['assets/sample-2/rgb.jpg']
images = load_and_preprocess_images(image_names).to(device)

with torch.no_grad():
    with torch.cuda.amp.autocast(dtype=dtype):
        predictions = model(images)

然后,使用 Prior-Depth-Anything 细化深度图。

from PIL import Image
import numpy as np
import torch.nn.functional as F
from prior_depth_anything.plugin import PriorDARefiner, PriorDARefinerMetrics

Refiner = PriorDARefiner(device=device)

priorda_image = torch.from_numpy(np.asarray(Image.open(image_names[0])).astype(np.uint8))

depth_map, depth_conf = predictions['depth'], predictions['depth_conf']

refined_depth, meview_depth_map = Refiner.predict(image=priorda_image, depth_map=depth_map.squeeze(), confidence=depth_conf.squeeze())

4. 典型生态项目

目前,Prior-Depth-Anything 主要与 VGGT 等深度估计框架集成。未来,开发者可以将其集成到更多的深度估计项目中,形成一个更加丰富和多样化的技术生态。

登录后查看全文
热门项目推荐

最新内容推荐

项目优选

收起
ohos_react_nativeohos_react_native
React Native鸿蒙化仓库
C++
176
261
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
860
511
ShopXO开源商城ShopXO开源商城
🔥🔥🔥ShopXO企业级免费开源商城系统,可视化DIY拖拽装修、包含PC、H5、多端小程序(微信+支付宝+百度+头条&抖音+QQ+快手)、APP、多仓库、多商户、多门店、IM客服、进销存,遵循MIT开源协议发布、基于ThinkPHP8框架研发
JavaScript
93
15
openGauss-serveropenGauss-server
openGauss kernel ~ openGauss is an open source relational database management system
C++
129
182
openHiTLSopenHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
259
300
kernelkernel
deepin linux kernel
C
22
5
cherry-studiocherry-studio
🍒 Cherry Studio 是一款支持多个 LLM 提供商的桌面客户端
TypeScript
596
57
CangjieCommunityCangjieCommunity
为仓颉编程语言开发者打造活跃、开放、高质量的社区环境
Markdown
1.07 K
0
HarmonyOS-ExamplesHarmonyOS-Examples
本仓将收集和展示仓颉鸿蒙应用示例代码,欢迎大家投稿,在仓颉鸿蒙社区展现你的妙趣设计!
Cangjie
398
371
Cangjie-ExamplesCangjie-Examples
本仓将收集和展示高质量的仓颉示例代码,欢迎大家投稿,让全世界看到您的妙趣设计,也让更多人通过您的编码理解和喜爱仓颉语言。
Cangjie
332
1.08 K