device = torch.device('cuda:1')
報錯內容:

Traceback (most recent call last): File "C:/Users/WQBin/Desktop/Deep-Learning-with-PyTorch-Tutorials-master/lesson28-激活函數與GPU加速/main.py", line 51, in <module> net = MLP().to(device) File "D:\app\Anaconda3\envs\deeplearning\lib\site-packages\torch\nn\modules\module.py", line 425, in to return self._apply(convert) File "D:\app\Anaconda3\envs\deeplearning\lib\site-packages\torch\nn\modules\module.py", line 201, in _apply module._apply(fn) File "D:\app\Anaconda3\envs\deeplearning\lib\site-packages\torch\nn\modules\module.py", line 201, in _apply module._apply(fn) File "D:\app\Anaconda3\envs\deeplearning\lib\site-packages\torch\nn\modules\module.py", line 223, in _apply param_applied = fn(param) File "D:\app\Anaconda3\envs\deeplearning\lib\site-packages\torch\nn\modules\module.py", line 423, in convert return t.to(device, dtype if t.is_floating_point() else None, non_blocking) RuntimeError: CUDA error: invalid device ordinal Process finished with exit code 1
雖然這里沒顯示,但是切換CUDA,可以看到確實在使用英偉達顯卡。