Open hf62580 opened 3 weeks ago
Hi, there should be no problem in this code. Did you carefully check the output? Please print its values rather than visualize it. The values are in the range between 0 to 20.
已经解决,给出来的示列代码有问题,需把 from depth_anything_v2.dpt import DepthAnythingV2 改成 from metric_depth.depth_anything_v2.dpt import DepthAnythingV2
Glad to know! It is more recommended to cd metric_depth
first, when using the metric depth models.
作者您好,我按以下的教程进行推, https://github.com/DepthAnything/Depth-Anything-V2/tree/main/metric_depth
depth 全是0,是有哪里不对的吗? 以下是代码 import cv2 import torch
from depth_anything_v2.dpt import DepthAnythingV2 from PIL import Image import matplotlib.pyplot as plt import numpy as np
model_configs = { 'vits': {'encoder': 'vits', 'features': 64, 'out_channels': [48, 96, 192, 384]}, 'vitb': {'encoder': 'vitb', 'features': 128, 'out_channels': [96, 192, 384, 768]}, 'vitl': {'encoder': 'vitl', 'features': 256, 'out_channels': [256, 512, 1024, 1024]} }
encoder = 'vitl' # or 'vits', 'vitb' dataset = 'vkitti' # 'hypersim' for indoor model, 'vkitti' for outdoor model max_depth = 20 # 20 for indoor model, 80 for outdoor model
model = DepthAnythingV2({model_configs[encoder]}) model.load_state_dict(torch.load(f'checkpoints/depth_anything_v2metric{dataset}_{encoder}.pth', map_location='cpu'))
model = model.to("cuda").eval()
imagePath='/home/hof/share/test/20240903214137.png' raw_img = cv2.imread(imagePath) depth = model.infer_image(raw_img) # HxW depth map in meters in numpy