isl-org / MiDaS

Code for robust monocular depth estimation described in "Ranftl et. al., Towards Robust Monocular Depth Estimation: Mixing Datasets for Zero-shot Cross-dataset Transfer, TPAMI 2022"
MIT License
4.25k stars 597 forks source link

what is tisAttributeError: 'LevitDistilled' object has no attribute 'blocks' #225

Open reza-shahriari opened 11 months ago

reza-shahriari commented 11 months ago

i am trying to run dpt_levit_224 but i am seeing this: AttributeError: 'LevitDistilled' object has no attribute 'blocks' python3 run.py --model_type dpt_levit_224 --side /usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.16) or chardet (3.0.4) doesn't match a supported version! warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported " Initialize Device: cuda /home/reza/.local/lib/python3.8/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3483.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] Traceback (most recent call last): File "run.py", line 276, in <module> run(args.input_path, args.output_path, args.model_weights, args.model_type, args.optimize, args.side, args.height, File "run.py", line 126, in run model, transform, net_w, net_h = load_model(device, model_path, model_type, optimize, height, square) File "/home/reza/MiDaS/midas/model_loader.py", line 138, in load_model model = DPTDepthModel( File "/home/reza/MiDaS/midas/dpt_depth.py", line 160, in __init__ super().__init__(head, **kwargs) File "/home/reza/MiDaS/midas/dpt_depth.py", line 71, in __init__ self.pretrained, self.scratch = _make_encoder( File "/home/reza/MiDaS/midas/blocks.py", line 90, in _make_encoder pretrained = _make_pretrained_levit_384( File "/home/reza/MiDaS/midas/backbones/levit.py", line 103, in _make_pretrained_levit_384 return _make_levit_backbone( File "/home/reza/MiDaS/midas/backbones/levit.py", line 31, in _make_levit_backbone pretrained.model.blocks[hooks[0]].register_forward_hook(get_activation("1")) File "/home/reza/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1614, in __getattr__ raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'LevitDistilled' object has no attribute 'blocks'

peterw2333 commented 11 months ago

Same issue here

sjanbs commented 10 months ago

Same issue here

Michaelsladkov commented 7 months ago

Same issue here

ZoenkitZ commented 2 months ago

Same issue here

Flosener commented 1 month ago

Same issue here. Probably has to do with Levit's architecture, i.e. 3 stages x 4 blocks compared to e.g. ViT which has 12 blocks in its architecture and is then called for 4 stages. After having a look at the paper I do not understand why default hooks are [3,11,21], and switching them to [3,7,11] throws even more confusing errors so I am lost here.