MiDaS
MiDaS copied to clipboard
PyTorch Hub ModuleNotFoundError: No module named 'midas.dpt_depth'; 'midas' is not a package
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
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
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
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)
I have fixed this error with pip install timm
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.
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.