lpiccinelli-eth / UniDepth

Universal Monocular Metric Depth Estimation
Other
462 stars 39 forks source link

TypeError: UniDepthV1.__init__() missing 1 required positional argument: 'config' #22

Closed lumennYan closed 2 months ago

lumennYan commented 2 months ago

When running the provided demo, I encountered the following error: Torch version: 2.0.1+cu117 Traceback (most recent call last): File "/data/yanyifan/code/dn-splatter/depth_model/UniDepth/./scripts/demo.py", line 40, in model = UniDepthV1.from_pretrained("lpiccinelli/unidepth-v1-vitl14") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/miniconda3/envs/unidepth/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py", line 119, in _inner_fn return fn(*args, kwargs) ^^^^^^^^^^^^^^^^^^^ File "/data/miniconda3/envs/unidepth/lib/python3.11/site-packages/huggingface_hub/hub_mixin.py", line 420, in from_pretrained instance = cls._from_pretrained( ^^^^^^^^^^^^^^^^^^^^^ File "/data/miniconda3/envs/unidepth/lib/python3.11/site-packages/huggingface_hub/hub_mixin.py", line 643, in _from_pretrained model = cls(model_kwargs) ^^^^^^^^^^^^^^^^^^^ TypeError: UniDepthV1.init() missing 1 required positional argument: 'config'

lpiccinelli-eth commented 2 months ago

It looks like the code in your codebase relative to unidepth is not using the latest commits.

TLDR: we merged UniDepthV1 class and its corresponding HuggingFace in the same class and adapted the from_pretrained, if you pull the latest commits it will work.

lumennYan commented 2 months ago

I pull the latest commits, but the error still occurs. Does it have something to do with the modification of modules' versions in the requirements.txt? I changed the file as follows: appdirs attrs black blosc2 botocore==1.34.54 certifi==2022.12.7 charset-normalizer click contourpy cycler docker-pycreds einops==0.7.0 filelock flake8==7.0.0 flake8-bugbear==24.2.6 flake8-comprehensions==3.14.0 fonttools fsspec fvcore==0.1.5.post20221221 gitdb GitPython h5py>=3.10.0 huggingface-hub>=0.22.0 idna imageio imath iopath isort Jinja2 jmespath kiwisolver MarkupSafe matplotlib mccabe mpmath msgpack mypy-extensions ndindex networkx ninja numexpr numpy opencv-python OpenEXR packaging pandas pathspec pillow==10.2.0 platformdirs portalocker protobuf==4.25.3 psutil py-cpuinfo pycodestyle pyflakes pyparsing python-dateutil pytz PyYAML requests safetensors scipy sentry-sdk setproctitle six smmap sympy tables tabulate termcolor timm tqdm triton==2.0.0 typing_extensions tzdata==2024.1 urllib3==1.26.13 wandb yacs torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 xformers==0.0.22

lpiccinelli-eth commented 2 months ago

In the cloned unidepth repo, does the demo.py work?

lumennYan commented 2 months ago

I just cloned the repo today for testing, and it should be the latest version. I think that the error comes from the instantiation of the unidepth model. I downloaded the pretrained weights from hugging face, and tried to load it from local in demo.py. When I instantiated the model by using "model = UniDepthV1.build(config)", the error occurs again. Because I called the ".build()" function before created an instance of the model. Instead, by using "model = UniDepthV1.(config)", the demo.py worked fine. I find in the file unidepthv1.py, the unidepth model is built when initialized: def __init__(self,config,eps: float = 1e-6,**kwargs,): super().__init__() self.build(config) self.eps = eps I don't know if the original demo.py has the same problem.

lpiccinelli-eth commented 2 months ago

Yes, you are correct, you can instantiate UniDepth either "manually" with UniDepthV1(config), but then you also need to load the pretrained weights with the typical method load_state_dict(path), or you can use HuggingFace as

model = UniDepthV1.from_pretrained("lpiccinelli/unidepth-v1-vitl14")

or TorchHub as

model = torch.hub.load("lpiccinelli-eth/UniDepth", "UniDepth", version=version, backbone=backbone, pretrained=True, trust_repo=True, force_reload=True)

the demo should be fine. You can look into hubconf.py to see better how to instantiate UniDepth (also with a local path).

lumennYan commented 2 months ago

Thank you, my problem is solved. I think I'll close the issue.