LiheYoung / Depth-Anything

[CVPR 2024] Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data. Foundation Model for Monocular Depth Estimation
https://depth-anything.github.io
Apache License 2.0
7.01k stars 539 forks source link

How to "not" resize image when inferencing metric depth? #215

Closed TikaToka closed 4 months ago

TikaToka commented 4 months ago

Hello @LiheYoung, Thank you for sharing your amazing work!

I am trying to use your work with metric depth esimation, but I am struggling with using it.

 config = get_config(args.model, "infer")
        config.pretrained_resource = args.pretrained_resource
        model = build_model(config).to('cuda' if torch.cuda.is_available() else 'cpu')
        model.eval()
        image_tensor = transforms.ToTensor()(image.convert('RGB')).unsqueeze(0).to('cuda' if torch.cuda.is_available() else 'cpu')
        pred = model(image_tensor, dataset='nyu')
        if isinstance(pred, dict):
                pred = pred.get('metric_depth', pred.get('out'))
        elif isinstance(pred, (list, tuple)):
            pred = pred[-1]
        depth = pred.squeeze().detach().cpu().numpy()

I am using the code like this with referencing here[https://github.com/LiheYoung/Depth-Anything/blob/main/metric_depth/depth_to_pointcloud.py

However, It keep tried to resize the original 720x1280 image like this:

Params passed to Resize transform:
        width:  518
        height:  392
        resize_target:  True
        keep_aspect_ratio:  True
        ensure_multiple_of:  14
        resize_method:  minimal
Using pretrained resource local::./checkpoints/depth_anything_metric_depth_indoor.pt
Loaded successfully

I'm not sure how to pass args not to resize target.

It might be a dumb question, but please forgive me :(

Thank you in advance and have a nice day!

TikaToka commented 4 months ago

Solved with using V2...