Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
This repository was archived by the owner on May 5, 2025. It is now read-only.

Cannot run ZoeDepth in Python 3.10+ #84

@decamun

Description

@decamun

As far as I can tell, there is no way to run ZoeDepth in Python 3.10+, because torch v2 introduces a breaking change and v1 cannot run above python 3.9.

My goal is to run this code in Python 3.11 and Pytorch 2.1.0. This is necessary for me because reverting to Python 3.9 is breaking for other parts of my codebase.

I can load the model using the method in #82:

(in model_io.py)

def load_state_dict(model, state_dict):
    """Load state_dict into model, handling DataParallel and DistributedDataParallel. Also checks for "model" key in state_dict.

    DataParallel prefixes state_dict keys with 'module.' when saving.
    If the model is not a DataParallel model but the state_dict is, then prefixes are removed.
    If the model is a DataParallel model but the state_dict is not, then prefixes are added.
    """
    state_dict = state_dict.get('model', state_dict)
    # if model is a DataParallel model, then state_dict keys are prefixed with 'module.'

    do_prefix = isinstance(
        model, (torch.nn.DataParallel, torch.nn.parallel.DistributedDataParallel))
    state = {}
    for k, v in state_dict.items():
        if k.startswith('module.') and not do_prefix:
            k = k[7:]

        if not k.startswith('module.') and do_prefix:
            k = 'module.' + k

        state[k] = v

    model.load_state_dict(state, strict=False) # modified
    for b in model.core.core.pretrained.model.blocks: # modified
        b.drop_path = torch.nn.Identity() # modified
    print("Loaded successfully")
    return model

But I still get the following error when trying to use the model.eval function:

  File "C:\Users\[decamun]/.cache\torch\hub\intel-isl_MiDaS_master\midas\backbones\beit.py", line 47, in _get_rel_pos_bias
    new_sub_table = F.interpolate(old_sub_table, size=(new_height, new_width), mode="bilinear")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[decamun]\AppData\Local\anaconda3\envs\n15_b\Lib\site-packages\torch\nn\functional.py", line 3924, in interpolate
    raise TypeError(
TypeError: expected size to be one of int or Tuple[int] or Tuple[int, int] or Tuple[int, int, int], but got size with types [<class 'numpy.intc'>, <class 'numpy.intc'>]

#62 fixes this for models constructed locally, but even locally instantiating zoedepthNK in 'infer' downloads the statedict from this repo.

From config_zoedepth_nk.json

"infer": {
        "train_midas": false,
        "pretrained_resource": "url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_NK.pt",
        "use_pretrained_midas": false,
        "force_keep_ar": true
    },

We need an update to this repo (or a release in an independent repo) that incorporates the fixes in #62

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions