DepthAnything / Depth-Anything-V2

[NeurIPS 2024] Depth Anything V2. A More Capable Foundation Model for Monocular Depth Estimation
https://depth-anything-v2.github.io
Apache License 2.0
3.81k stars 324 forks source link

segmentation fault running example #104

Open jeezrick opened 3 months ago

jeezrick commented 3 months ago
import cv2
import torch
from depth_anything_v2.dpt import DepthAnythingV2

DEVICE = 'cuda:0' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'

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]},
    'vitg': {'encoder': 'vitg', 'features': 384, 'out_channels': [1536, 1536, 1536, 1536]}
}

encoder = 'vits' # or 'vits', 'vitb', 'vitg'

model = DepthAnythingV2(**model_configs[encoder])
# model_path = "/data/shared/foundation_models/perception/depth/depth-anything-v2"
model.load_state_dict(torch.load(f'checkpoints/depth_anything_v2_{encoder}.pth', map_location='cuda:0'))
model = model.to(DEVICE).eval()
print(model)

raw_img = cv2.imread('rgb.png')

# import time
# ts = time.time()
depth = model.infer_image(raw_img) # HxW raw depth map in numpy
# print(f"dt = {(time.time() - ts) * 1000} ms")

model load fine, but getting segmention fault running infer line.

after debug, I find that problem lies in features = self.pretrained.get_intermediate_layers(x, self.intermediate_layer_idx[self.encoder], return_class_token=True) forward code. Any idea?

jeezrick commented 3 months ago
 [:~/code/rep/Depth-Anything-V2]
$ cl | grep xform
xformers                  0.0.26.post1             pypi_0    pypi

[:~/code/rep/Depth-Anything-V2]
$ cl | grep torch
ffmpeg                    4.3                  hf484d3e_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
open-clip-torch           2.24.0                   pypi_0    pypi
pytorch-cuda              11.7                 h778d358_5    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
pytorch-lightning         2.2.1                    pypi_0    pypi
pytorch-msssim            1.0.0                    pypi_0    pypi
pytorch-mutex             1.0                        cuda    pytorch
pytorch3d                 0.7.6                     dev_0    <develop>
torch                     2.3.0                    pypi_0    pypi
torch-geometric           2.5.0                    pypi_0    pypi
torchaudio                2.3.0                    pypi_0    pypi
torchmetrics              0.10.3                   pypi_0    pypi
torchvision               0.18.0                   pypi_0    pypi