MegEngine / YOLOX

MegEngine implementation of YOLOX
Apache License 2.0
106 stars 15 forks source link

AssertionError: Torch not compiled with CUDA enabled #2

Closed monkeycc closed 2 years ago

monkeycc commented 3 years ago
 python tools/demo.py image -n yolox-tiny -c /path/to/your/yolox_tiny.pkl --path assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 416 --save_result --device gpu
2021-09-07 18:45:49.600 | INFO     | __main__:main:250 - Args: Namespace(camid=0, ckpt='/path/to/your/yolox_tiny.pkl', conf=0.25, demo='image', device='gpu', exp_file=None, experiment_name='yolox_tiny', fp16=False, fuse=False, legacy=False, name='yolox-tiny', nms=0.45, path='assets/dog.jpg', save_result=True, trt=False, tsize=416)
E:\anaconda3\envs\YOLOX\lib\site-packages\torch\nn\functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  ..\c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
2021-09-07 18:45:49.791 | INFO     | __main__:main:260 - Model Summary: Params: 5.06M, Gflops: 6.45
Traceback (most recent call last):
  File "tools/demo.py", line 306, in <module>
    main(exp, args)
  File "tools/demo.py", line 263, in main
    model.cuda()
  File "E:\anaconda3\envs\YOLOX\lib\site-packages\torch\nn\modules\module.py", line 637, in cuda
    return self._apply(lambda t: t.cuda(device))
  File "E:\anaconda3\envs\YOLOX\lib\site-packages\torch\nn\modules\module.py", line 530, in _apply
    module._apply(fn)
  File "E:\anaconda3\envs\YOLOX\lib\site-packages\torch\nn\modules\module.py", line 530, in _apply
    module._apply(fn)
  File "E:\anaconda3\envs\YOLOX\lib\site-packages\torch\nn\modules\module.py", line 530, in _apply
    module._apply(fn)
  [Previous line repeated 2 more times]
  File "E:\anaconda3\envs\YOLOX\lib\site-packages\torch\nn\modules\module.py", line 552, in _apply
    param_applied = fn(param)
  File "E:\anaconda3\envs\YOLOX\lib\site-packages\torch\nn\modules\module.py", line 637, in <lambda>
    return self._apply(lambda t: t.cuda(device))
  File "E:\anaconda3\envs\YOLOX\lib\site-packages\torch\cuda\__init__.py", line 166, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

环境 CUDA Version: 11.2 没问题

按照官方的教程 报错

cmFighting commented 3 years ago

这个是megengine版本,不是pyotorch版本的,不过python setup.py develop的时候确实有检查torch,我安装的cpu版本的torch和torchvision通过了检查

pot2mayo commented 2 years ago

@monkeycc Having the same error on my side. Did you find any solution?

FateScript commented 2 years ago

Did you find any solution?

Plz make sure you install cuda version torch @pot2mayo

pot2mayo commented 2 years ago

@FateScript Thanks for you reply.

After double checking I figured what was my issue.

I installed torch with cuda using conda (I'm using anaconda for managing environments) via the following command: conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch following the official documentation.

However when checking if it's available using the script

import torch
print(torch.cuda.is_available())

It returned False I actually should have installed via pip using the command below

pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio===0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

And now it works fine 🎉