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.53k stars 633 forks source link

PyTorch Hub ModuleNotFoundError: No module named 'midas.dpt_depth'; 'midas' is not a package #118

Open xvel opened 3 years ago

xvel commented 3 years ago

Can't download model

model = torch.hub.load("intel-isl/MiDaS", "DPT_Large")

gives this on Windows 10, Anaconda env, Pytorch 1.9, Pycharm IDE

Traceback (most recent call last):
  File "C:/Users/abcd/PycharmProjects/test/midas.py", line 12, in <module>
    midas_v3L = torch.hub.load("intel-isl/MiDaS", model_type)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 364, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 390, in _load_local
    hub_module = import_module(MODULE_HUBCONF, hubconf_path)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 75, in import_module
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\abcd/.cache\torch\hub\intel-isl_MiDaS_master\hubconf.py", line 5, in <module>
    from midas.dpt_depth import DPTDepthModel
  File "C:\Users\abcd\PycharmProjects\test\midas.py", line 12, in <module>
    midas_v3L = torch.hub.load("intel-isl/MiDaS", model_type)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 364, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 390, in _load_local
    hub_module = import_module(MODULE_HUBCONF, hubconf_path)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 75, in import_module
    spec.loader.exec_module(module)
  File "C:\Users\abcd/.cache\torch\hub\intel-isl_MiDaS_master\hubconf.py", line 5, in <module>
    from midas.dpt_depth import DPTDepthModel
ModuleNotFoundError: No module named 'midas.dpt_depth'; 'midas' is not a package
ranftlr commented 3 years ago

This seems unrelated to MiDaS. I believe you might have naming conflict with some file shadowing the MiDaS namespace. See here: https://stackoverflow.com/questions/59502364/modulenotfounderror-no-module-named-xxx-xxx-is-not-a-package

LeXwDeX commented 2 years ago

u can change this import code ,like this

# from midas.dpt_depth import DPTDepthModel
from MiDaS.midas.dpt_depth import DPTDepthModel
# from midas.midas_net import MidasNet
from MiDaS.midas.midas_net import MidasNet
# from midas.midas_net_custom import MidasNet_small
from MiDaS.midas.midas_net_custom import MidasNet_small
# from midas.transforms import Resize, NormalizeImage, PrepareForNet
from MiDaS.midas.transforms import Resize, NormalizeImage, PrepareForNet

this use path to find class name and import it

remmel commented 2 years ago

This seems unrelated to MiDaS. I believe you might have naming conflict with some file shadowing the MiDaS namespace. See here: https://stackoverflow.com/questions/59502364/modulenotfounderror-no-module-named-xxx-xxx-is-not-a-package

Right, this is unrelated with MiDaS. Was parent folder was named midas and my file midas.py, I renamed both and now it works (maybe only one has to be renamed)

andylucny commented 2 years ago

I have fixed this error with pip install timm

picobyte commented 1 year ago

ModuleNotFoundError: No module named 'midas.dpt_depth'; 'midas' is not a package This error pops up again, I have timm, and the midas model is in a ComfyUI directory, unsure what installed it. I've searched for potentially shadowing variables, but none of the midas variables seemed to be the culprit. What helps for me is placing an (empty) __init__.py in the ComfyUI/models/midas/intel-isl_MiDaS_master/midas directory.

kennydd001 commented 10 months ago

if you tried "pip install midas" before thinking it was correct thats whats causing the issue. #2023

pip uninstall midas, pip install timm

and that should fix it all.

BaronFalke commented 2 months ago

I get the same error. image This is my usage of the node: image

I tried "pip uninstall midas" and "pip install timm". After restarting I still get this error.

Stacktrace:

WAS Node Suite: Downloading and loading MiDaS Model... Using cache found in E:\Software\ComfyUI_windows_portable\ComfyUI\models\midas\intel-isl_MiDaS_master !!! Exception during processing !!! No module named 'midas.dpt_depth' Traceback (most recent call last): File "E:\Software\ComfyUI_windows_portable\ComfyUI\execution.py", line 323, in execute output_data, output_ui, has_subgraph = get_output_data(obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Software\ComfyUI_windows_portable\ComfyUI\execution.py", line 198, in get_output_data return_values = _map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Software\ComfyUI_windows_portable\ComfyUI\execution.py", line 169, in _map_node_over_list process_inputs(input_dict, i) File "E:\Software\ComfyUI_windows_portable\ComfyUI\execution.py", line 158, in process_inputs results.append(getattr(obj, func)(*inputs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Software\ComfyUI_windows_portable\ComfyUI\custom_nodes\was-node-suite-comfyui\WAS_Node_Suite.py", line 8949, in midas_remove midas = torch.hub.load("intel-isl/MiDaS", midas_model, trust_repo=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Software\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\hub.py", line 568, in load model = _load_local(repo_or_dir, model, args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Software\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\hub.py", line 594, in _load_local hub_module = _import_module(MODULE_HUBCONF, hubconf_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\Software\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\hub.py", line 106, in _import_module spec.loader.exec_module(module) File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "E:\Software\ComfyUI_windows_portable\ComfyUI\models\midas\intel-isl_MiDaS_master\hubconf.py", line 5, in from midas.dpt_depth import DPTDepthModel ModuleNotFoundError: No module named 'midas.dpt_depth'

I read something about renaming folders. Could somebody provide details? I am not sure what to rename and where. At least it seems I have the "midas" folder: image

I just wanted to try the depth map.