gordicaleksa / pytorch-neural-style-transfer

Reconstruction of the original paper on neural style transfer (Gatys et al.). I've additionally included reconstruction scripts which allow you to reconstruct only the content or the style of the image - for better understanding of how NST works.
https://youtube.com/c/TheAIEpiphany
MIT License
376 stars 79 forks source link

Getting to work with CUDA 11.1 #3

Closed sbetzin closed 4 years ago

sbetzin commented 4 years ago

Hi Aleksa,

thanks for this fantastic python implementation. I tried to get it to run under Windows 10 with an NVIDIA GPU. I am failing with the error:

Traceback (most recent call last):
  File "neural_style_transfer.py", line 183, in <module>
    results_path = neural_style_transfer(optimization_config)
  File "neural_style_transfer.py", line 64, in neural_style_transfer
    content_img = utils.prepare_img(content_img_path, config['height'], device)
  File "D:\pytorch-neural-style-transfer\utils\utils.py", line 51, in prepare_img
    img = transform(img).to(device).unsqueeze(0)
  File "C:\Users\Sebastian\anaconda3\envs\pytorch-nst\lib\site-packages\torch\cuda\__init__.py", line 196, in _lazy_init
    _check_driver()
  File "C:\Users\Sebastian\anaconda3\envs\pytorch-nst\lib\site-packages\torch\cuda\__init__.py", line 94, in _check_driver
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

my nvidia-smi provides

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 456.81       Driver Version: 456.81       CUDA Version: 11.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 970    WDDM  | 00000000:01:00.0  On |                  N/A |
|  0%   42C    P8    17W / 200W |    268MiB /  4096MiB |      4%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

For me it seems that the version of the installed cuda toolkit and the version that pytorch requires are different? Sorry, I am just about to start to learn with python an cuda....

Thank you

Sebastian

sbetzin commented 4 years ago

Yeah, updated the environment.yml to the next version of pytorch and torchvision and it worked

name: pytorch-nst
channels:
  - defaults
  - pytorch
dependencies:
  - python=3.7.6
  - pip=20.0.2
  - matplotlib=3.1.3
  - pytorch==1.5.0
  - torchvision=0.6.0
  - pip:
    - numpy==1.18.1
    - opencv-python==4.2.0.32