cc-ai / climategan

Code and pre-trained model for the algorithm generating visualisations of 3 climate change related events: floods, wildfires and smog.
https://thisclimatedoesnotexist.com
GNU General Public License v3.0
72 stars 18 forks source link

ImportError: cannot import name 'solve' from 'torch.linalg' #222

Open JasonMendoza2008 opened 1 year ago

JasonMendoza2008 commented 1 year ago

I'm using Python 3.8.2 as suggested. My pip freeze is:

addict==2.4.0
APScheduler==3.7.0
attrs==21.2.0
backcall==0.2.0
Brotli==1.0.9
certifi==2021.5.30
charset-normalizer==2.0.4
click==8.0.1
codecarbon==1.2.0
colorama==0.4.6
comet-ml==3.15.3
configobj==5.0.6
cycler==0.10.0
dash==2.0.0
dash-bootstrap-components==0.13.0
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
dataclasses==0.6
decorator==5.0.9
dulwich==0.20.25
everett==2.0.1
filelock==3.0.12
fire==0.4.0
Flask==2.0.1
Flask-Compress==1.10.1
future==0.18.2
gdown==3.13.0
hydra-core==0.11.3
idna==3.2
imageio==2.9.0
ipython==7.27.0
itsdangerous==2.0.1
jedi==0.18.0
Jinja2==3.0.1
joblib==1.0.1
jsonschema==3.2.0
kiwisolver==1.3.2
kornia==0.5.10
MarkupSafe==2.0.1
matplotlib==3.4.3
matplotlib-inline==0.1.2
networkx==2.6.2
numpy==1.21.2
nvidia-ml-py3==7.352.0
omegaconf==1.4.1
opencv-python==4.5.3.56
packaging==21.0
pandas==1.3.2
parso==0.8.2
pexpect==4.8.0
pickleshare==0.7.5
Pillow==8.3.2
plotly==5.3.1
prompt-toolkit==3.0.20
ptyprocess==0.7.0
py-cpuinfo==8.0.0
Pygments==2.10.0
pynvml==11.0.0
pyparsing==2.4.7
pyrsistent==0.18.0
PySocks==1.7.1
python-dateutil==2.8.2
pytorch-ranger==0.1.1
pytz==2021.1
PyWavelets==1.1.1
PyYAML==5.4.1
requests==2.26.0
requests-toolbelt==0.9.1
scikit-image==0.18.3
scikit-learn==0.24.2
scipy==1.7.1
seaborn==0.11.2
semantic-version==2.8.5
six==1.16.0
tenacity==8.0.1
termcolor==1.1.0
threadpoolctl==2.2.0
tifffile==2021.8.30
torch==1.7.1
torch-optimizer==0.1.0
torchvision==0.8.2
tqdm==4.62.2
traitlets==5.1.0
typing-extensions==3.10.0.2
tzlocal==2.1
urllib3==1.26.6
wcwidth==0.2.5
websocket-client==1.2.1
Werkzeug==2.0.1
wrapt==1.12.1
wurlitzer==3.0.2

But I get the following error:

• Imports

Traceback (most recent call last):
  File "apply_events.py", line 171, in <module>
    from climategan.trainer import Trainer
  File "C:\Users\lhott\Documents\Challenges\Essonne Hackathon\climategan\climategan\__init__.py", line 4, in <module>
    __all__ = [
  File "C:\Users\lhott\Documents\Challenges\Essonne Hackathon\climategan\climategan\__init__.py", line 5, in <listcomp>
    import_module(f".{f.stem}", __package__)
  File "C:\Users\lhott\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\lhott\Documents\Challenges\Essonne Hackathon\climategan\climategan\fire.py", line 4, in <module>
    import kornia
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\__init__.py", line 13, in <module>
    from kornia import augmentation, color, contrib, enhance, feature, filters, geometry, jit, losses, morphology, utils
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\augmentation\__init__.py", line 1, in <module>
    from .augmentation import (
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\augmentation\augmentation.py", line 7, in <module>
    from kornia.augmentation.base import GeometricAugmentationBase2D, IntensityAugmentationBase2D, TensorWithTransformMat
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\augmentation\base.py", line 9, in <module>
    from kornia.utils.helpers import _torch_inverse_cast
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\utils\__init__.py", line 5, in <module>
    from .helpers import _extract_device_dtype
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\utils\helpers.py", line 5, in <module>
    from kornia.utils._compat import solve
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\utils\_compat.py", line 9, in <module>
    from torch.linalg import solve  # type: ignore
ImportError: cannot import name 'solve' from 'torch.linalg' (C:\Users\lhott\virtualenv\climategan\lib\site-packages\torch\linalg\__init__.py)

when running: python apply_events.py -b=1 -r config/model/masker -i=inputs -o=outputs

Trifurs commented 3 weeks ago

I'm using Python 3.8.2 as suggested. My pip freeze is:

addict==2.4.0
APScheduler==3.7.0
attrs==21.2.0
backcall==0.2.0
Brotli==1.0.9
certifi==2021.5.30
charset-normalizer==2.0.4
click==8.0.1
codecarbon==1.2.0
colorama==0.4.6
comet-ml==3.15.3
configobj==5.0.6
cycler==0.10.0
dash==2.0.0
dash-bootstrap-components==0.13.0
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
dataclasses==0.6
decorator==5.0.9
dulwich==0.20.25
everett==2.0.1
filelock==3.0.12
fire==0.4.0
Flask==2.0.1
Flask-Compress==1.10.1
future==0.18.2
gdown==3.13.0
hydra-core==0.11.3
idna==3.2
imageio==2.9.0
ipython==7.27.0
itsdangerous==2.0.1
jedi==0.18.0
Jinja2==3.0.1
joblib==1.0.1
jsonschema==3.2.0
kiwisolver==1.3.2
kornia==0.5.10
MarkupSafe==2.0.1
matplotlib==3.4.3
matplotlib-inline==0.1.2
networkx==2.6.2
numpy==1.21.2
nvidia-ml-py3==7.352.0
omegaconf==1.4.1
opencv-python==4.5.3.56
packaging==21.0
pandas==1.3.2
parso==0.8.2
pexpect==4.8.0
pickleshare==0.7.5
Pillow==8.3.2
plotly==5.3.1
prompt-toolkit==3.0.20
ptyprocess==0.7.0
py-cpuinfo==8.0.0
Pygments==2.10.0
pynvml==11.0.0
pyparsing==2.4.7
pyrsistent==0.18.0
PySocks==1.7.1
python-dateutil==2.8.2
pytorch-ranger==0.1.1
pytz==2021.1
PyWavelets==1.1.1
PyYAML==5.4.1
requests==2.26.0
requests-toolbelt==0.9.1
scikit-image==0.18.3
scikit-learn==0.24.2
scipy==1.7.1
seaborn==0.11.2
semantic-version==2.8.5
six==1.16.0
tenacity==8.0.1
termcolor==1.1.0
threadpoolctl==2.2.0
tifffile==2021.8.30
torch==1.7.1
torch-optimizer==0.1.0
torchvision==0.8.2
tqdm==4.62.2
traitlets==5.1.0
typing-extensions==3.10.0.2
tzlocal==2.1
urllib3==1.26.6
wcwidth==0.2.5
websocket-client==1.2.1
Werkzeug==2.0.1
wrapt==1.12.1
wurlitzer==3.0.2

But I get the following error:

• Imports

Traceback (most recent call last):
  File "apply_events.py", line 171, in <module>
    from climategan.trainer import Trainer
  File "C:\Users\lhott\Documents\Challenges\Essonne Hackathon\climategan\climategan\__init__.py", line 4, in <module>
    __all__ = [
  File "C:\Users\lhott\Documents\Challenges\Essonne Hackathon\climategan\climategan\__init__.py", line 5, in <listcomp>
    import_module(f".{f.stem}", __package__)
  File "C:\Users\lhott\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\lhott\Documents\Challenges\Essonne Hackathon\climategan\climategan\fire.py", line 4, in <module>
    import kornia
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\__init__.py", line 13, in <module>
    from kornia import augmentation, color, contrib, enhance, feature, filters, geometry, jit, losses, morphology, utils
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\augmentation\__init__.py", line 1, in <module>
    from .augmentation import (
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\augmentation\augmentation.py", line 7, in <module>
    from kornia.augmentation.base import GeometricAugmentationBase2D, IntensityAugmentationBase2D, TensorWithTransformMat
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\augmentation\base.py", line 9, in <module>
    from kornia.utils.helpers import _torch_inverse_cast
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\utils\__init__.py", line 5, in <module>
    from .helpers import _extract_device_dtype
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\utils\helpers.py", line 5, in <module>
    from kornia.utils._compat import solve
  File "C:\Users\lhott\virtualenv\climategan\lib\site-packages\kornia\utils\_compat.py", line 9, in <module>
    from torch.linalg import solve  # type: ignore
ImportError: cannot import name 'solve' from 'torch.linalg' (C:\Users\lhott\virtualenv\climategan\lib\site-packages\torch\linalg\__init__.py)

when running: python apply_events.py -b=1 -r config/model/masker -i=inputs -o=outputs

I also encountered the same problem, my solution is as follows: Find the _compat.py file in your virtual environment, on my side the path is "E:\miniconda3\envs\flood_gan\Lib\site-packages\kornia\utils\compat.py". Modify it as follows:


import torch
from packaging import version
from torch import solve as _solve

def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: return _solve(B, A).solution