CompVis / latent-diffusion

High-Resolution Image Synthesis with Latent Diffusion Models
MIT License
11.77k stars 1.53k forks source link

ImportError on torchmetrics-related name on Windows #72

Open ilTofa opened 2 years ago

ilTofa commented 2 years ago

After installation, running the example command python scripts/txt2img.py --prompt "A prompt" --ddim_eta 0.0 --n_samples 4 --n_iter 4 --scale 5.0 --ddim_steps 50 Fails with cannot import name 'get_num_classes' from 'torchmetrics.utilities.data'

I was not able to find anything useful to solving this problem (it seems probably related to torchmetrics library changes). Is this a know problem?


Traceback (most recent call last):
  File "scripts/txt2img.py", line 108, in <module>
    model = load_model_from_config(config, "models/ldm/text2img-large/model.ckpt")  # TODO: check path
  File "scripts/txt2img.py", line 19, in load_model_from_config
    model = instantiate_from_config(config.model)
  File "d:\github\latent-diffusion\ldm\util.py", line 78, in instantiate_from_config
    return get_obj_from_str(config["target"])(**config.get("params", dict()))
  File "d:\github\latent-diffusion\ldm\util.py", line 86, in get_obj_from_str
    return getattr(importlib.import_module(module, package=None), cls)
  File "D:\miniconda3\envs\ldm\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "d:\github\latent-diffusion\ldm\models\diffusion\ddpm.py", line 12, in <module>
    import pytorch_lightning as pl
  File "D:\miniconda3\envs\ldm\lib\site-packages\pytorch_lightning\__init__.py", line 20, in <module>
    from pytorch_lightning import metrics  # noqa: E402
  File "D:\miniconda3\envs\ldm\lib\site-packages\pytorch_lightning\metrics\__init__.py", line 15, in <module>
    from pytorch_lightning.metrics.classification import (  # noqa: F401
  File "D:\miniconda3\envs\ldm\lib\site-packages\pytorch_lightning\metrics\classification\__init__.py", line 14, in <module>
    from pytorch_lightning.metrics.classification.accuracy import Accuracy  # noqa: F401
  File "D:\miniconda3\envs\ldm\lib\site-packages\pytorch_lightning\metrics\classification\accuracy.py", line 18, in <module>
    from pytorch_lightning.metrics.utils import deprecated_metrics, void
  File "D:\miniconda3\envs\ldm\lib\site-packages\pytorch_lightning\metrics\utils.py", line 22, in <module>
    from torchmetrics.utilities.data import get_num_classes as _get_num_classes
ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' (D:\miniconda3\envs\ldm\lib\site-packages\torchmetrics\utilities\data.py)```
gautamchitnis commented 2 years ago

+1

I got this while trying to create a requirements.txt for pip. Was trying to get all deps in one place, apparently this error won't go away.

diediaga commented 2 years ago

I have the same problem. Does anybody found a solution for that? thanks I found the solution: pip install pytorch-lightning==1.6.1 here works for me

Fqlox commented 2 years ago

I have the same problem. Does anybody found a solution for that? thanks I found the solution: pip install pytorch-lightning==1.6.1 here works for me

Worked for me. thought, I had to reinstall pytorch 1.11 with conda

Straafe commented 2 years ago

This worked for me too, but I also needed to re-install pytorch:

pip uninstall torch pip cache purge pip install torch -f https://download.pytorch.org/whl/torch_stable.html

Now it works, but initially after running txt2img.py it gives me an Entry Point Not Found error for torchvision_C.pyd , as in this image

image

(or: https://i.imgur.com/PbKSZc1.png)

I can just hit OK in the error window and it produces the images, but I wish I knew why it was popping up that error.

Edit: Works fine in powershell, error happens with cmd.exe only

susuhu commented 2 years ago

downgrading torchmetrics to v0.6.0 also works

anof commented 2 years ago

downgrading torchmetrics to v0.6.0 also works

works!

ilTofa commented 2 years ago

Workarounds above work. I'm unsure if the ticket in itself can be closed or not