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.52k stars 626 forks source link

Errors during operation #235

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hi, I experience multiple errors using the script.

Initialize
Device: cpu
/home/user/.local/lib/python3.11/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]
Model loaded, number of parameters = 345M
Start processing
  Processing input/my_image.jpg (1/1)
    Input resized to 512x768 before entering the encoder
Traceback (most recent call last):
  File "/home/user/Downloads/MiDaS-master/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 "/home/user/Downloads/MiDaS-master/run.py", line 154, in run
    prediction = process(device, model, model_type, image, (net_w, net_h), original_image_rgb.shape[1::-1],
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/run.py", line 61, in process
    prediction = model.forward(sample)
                 ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/midas/dpt_depth.py", line 166, in forward
    return super().forward(x).squeeze(dim=1)
           ^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/midas/dpt_depth.py", line 114, in forward
    layers = self.forward_transformer(self.pretrained, x)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/midas/backbones/beit.py", line 15, in forward_beit
    return forward_adapted_unflatten(pretrained, x, "forward_features")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/midas/backbones/utils.py", line 86, in forward_adapted_unflatten
    exec(f"glob = pretrained.model.{function_name}(x)")
  File "<string>", line 1, in <module>
  File "/home/user/Downloads/MiDaS-master/midas/backbones/beit.py", line 125, in beit_forward_features
    x = blk(x, resolution, shared_rel_pos_bias=rel_pos_bias)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/midas/backbones/beit.py", line 102, in block_forward
    x = x + self.drop_path(self.gamma_1 * self.attn(self.norm1(x), resolution,
            ^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1614, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'Block' object has no attribute 'drop_path'. Did you mean: 'drop_path1'?
Initialize
Device: cpu
/home/user/.local/lib/python3.11/site-packages/timm/models/_factory.py:114: UserWarning: Mapping deprecated model name swinv2_large_window12to24_192to384_22kft1k to current swinv2_large_window12to24_192to384.ms_in22k_ft_in1k.
  model = create_fn(
/home/user/.local/lib/python3.11/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 "/home/user/Downloads/MiDaS-master/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 "/home/user/Downloads/MiDaS-master/run.py", line 126, in run
    model, transform, net_w, net_h = load_model(device, model_path, model_type, optimize, height, square)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/midas/model_loader.py", line 80, in load_model
    model = DPTDepthModel(
            ^^^^^^^^^^^^^^
  File "/home/user/Downloads/MiDaS-master/midas/dpt_depth.py", line 163, in __init__
    self.load(path)
  File "/home/user/Downloads/MiDaS-master/midas/base_model.py", line 16, in load
    self.load_state_dict(parameters)
  File "/home/user/.local/lib/python3.11/site-packages/torch/nn/modules/module.py", line 2041, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for DPTDepthModel:
        Missing key(s) in state_dict: "pretrained.model.layers.3.downsample.reduction.weight", "pretrained.model.layers.3.downsample.norm.weight", "pretrained.model.layers.3.downsample.norm.bias", "pretrained.model.head.fc.weight", "pretrained.model.head.fc.bias". 
        Unexpected key(s) in state_dict: "pretrained.model.layers.0.downsample.reduction.weight", "pretrained.model.layers.0.downsample.norm.weight", "pretrained.model.layers.0.downsample.norm.bias", "pretrained.model.layers.0.blocks.1.attn_mask", "pretrained.model.layers.1.blocks.1.attn_mask", "pretrained.model.head.weight", "pretrained.model.head.bias". 
        size mismatch for pretrained.model.layers.1.downsample.reduction.weight: copying a param with shape torch.Size([768, 1536]) from checkpoint, the shape in current model is torch.Size([384, 768]).
        size mismatch for pretrained.model.layers.1.downsample.norm.weight: copying a param with shape torch.Size([768]) from checkpoint, the shape in current model is torch.Size([384]).
        size mismatch for pretrained.model.layers.1.downsample.norm.bias: copying a param with shape torch.Size([768]) from checkpoint, the shape in current model is torch.Size([384]).
        size mismatch for pretrained.model.layers.2.downsample.reduction.weight: copying a param with shape torch.Size([1536, 3072]) from checkpoint, the shape in current model is torch.Size([768, 1536]).
        size mismatch for pretrained.model.layers.2.downsample.norm.weight: copying a param with shape torch.Size([1536]) from checkpoint, the shape in current model is torch.Size([768]).
        size mismatch for pretrained.model.layers.2.downsample.norm.bias: copying a param with shape torch.Size([1536]) from checkpoint, the shape in current model is torch.Size([768]).

Why is it doing this ? I installed the packages via pip install on Debian testing.

Thanks

Bob-The-Worker commented 1 year ago

Hello,

For the first error, as mentioned in issue #215 try to install timm==0.6.13 using the command pip install timm==0.6.13

bianchiidentity commented 1 year ago

thank you

ghost commented 1 year ago

Thanks

Dez1gner commented 1 year ago

I ran this command and rebooted the PC. This method didn't help me. It looks like nothing has changed even in the console. Please look, maybe there is something else causing it that I don’t know about? Here is the console output: https://pastebin.com/DzcCTkwn I ran the "room" request in text to img and then sent the image to img to img, included the "Depth.." script and executed a new generation with the room request and got this error

ghost commented 1 year ago

Are the versions you use the same as the one they require? It may happen that a lib is not synced with the others.. just check that out