CompVis / latent-diffusion

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

conda env settings issue #49

Open joowon-dm-snu opened 2 years ago

joowon-dm-snu commented 2 years ago

Thanks for great research, I found out conda env settings error while using scripts below.

conda env create -f environment.yaml
conda activate ldm

Error Log

(ldm) ubuntu@nipa2021-19981:~/jwk/latent-diffusion$ python scripts/txt2img.py --prompt "a sunset behind a mountain range, vector image" --ddim_eta 1.0 --n_samples 1 --n_iter 1 --H 384 --W 1024 --scale 5.0  
Loading model from models/ldm/text2img-large/model.ckpt
Traceback (most recent call last):
  File "scripts/txt2img.py", line 101, in <module>
    model = load_model_from_config(config, "models/ldm/text2img-large/model.ckpt")  # TODO: check path
  File "scripts/txt2img.py", line 18, in load_model_from_config
    model = instantiate_from_config(config.model)
  File "/home/ubuntu/jwk/latent-diffusion/ldm/util.py", line 78, in instantiate_from_config
    return get_obj_from_str(config["target"])(**config.get("params", dict()))
  File "/home/ubuntu/jwk/latent-diffusion/ldm/util.py", line 86, in get_obj_from_str
    return getattr(importlib.import_module(module, package=None), cls)
  File "/home/ubuntu/anaconda3/envs/ldm/lib/python3.8/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 "/home/ubuntu/jwk/latent-diffusion/ldm/models/diffusion/ddpm.py", line 12, in <module>
    import pytorch_lightning as pl
  File "/home/ubuntu/anaconda3/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/__init__.py", line 20, in <module>
    from pytorch_lightning import metrics  # noqa: E402
  File "/home/ubuntu/anaconda3/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/metrics/__init__.py", line 15, in <module>
    from pytorch_lightning.metrics.classification import (  # noqa: F401
  File "/home/ubuntu/anaconda3/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/metrics/classification/__init__.py", line 14, in <module>
    from pytorch_lightning.metrics.classification.accuracy import Accuracy  # noqa: F401
  File "/home/ubuntu/anaconda3/envs/ldm/lib/python3.8/site-packages/pytorch_lightning/metrics/classification/accuracy.py", line 18, in <module>
    from pytorch_lightning.metrics.utils import deprecated_metrics, void
  File "/home/ubuntu/anaconda3/envs/ldm/lib/python3.8/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' (/home/ubuntu/anaconda3/envs/ldm/lib/python3.8/site-packages/torchmetrics/utilities/data.py)

# environment.yaml
name: ldm
...
dependencies:
  ...
  - pytorch=1.7.0
  - torchvision=0.8.1
  - pip:
    ...
    - pytorch-lightning==1.4.2
    ...

Problem was pytorch-lightning==1.4.2 automatically imports from torchmetrics.utilities.data import get_num_classes as _get_num_classes but that function was dropped by this PR.

So yaml file should be changed by updating pytorch & torchvision & pytorch-lightning or add explicit torchmetric version

I solved it by updating pytorch-lightning.

hyungkwonko commented 2 years ago

I did

pip install pytorch-lightning==1.5

and it works fine.

peterwilli commented 2 years ago

pip install pytorch-lightning==1.6.1 for me

Straafe commented 2 years ago

This worked for me (although I needed to re-install pytorch with cuda too), but now txt2img.py gives me an Entry Point Not Found error for torchvision_C.pyd , as seen here: https://github.com/CompVis/latent-diffusion/issues/72#issuecomment-1138729437

Tuxius commented 2 years ago

I did

pip install pytorch-lightning==1.5

and it works fine.

This worked for me, but only after removing the conda environment, changes the yaml to pytorch-lightning==1.5, and creating the conda environment based on the new yaml.

pcicales commented 2 years ago

Created new conda env here with pytorch-lightning==1.6.1 and it seems to work, after running conda env remove -n ldm and recreating the env with new .yml as pointed out by @Tuxius