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

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

2025-05-19 03:33:41作者:江焘钦

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 等深度估计框架集成。未来,开发者可以将其集成到更多的深度估计项目中,形成一个更加丰富和多样化的技术生态。

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