我如何安装PyTorch:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
我如何安装Tensor Flow:
pip install tensorflow
CUDA工具包已安装并通过以下方式进行检查:
nvcc --version
按照说明将cuDNN 7.6.4 SDK导入CUDA文件夹,示例如下:
NVIDIDA卡和驱动程序信息
=====================================
代码:
In [1]:
from __future__ import print_function
from __future__ import division
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader, TensorDataset, Dataset
from torch import Tensor
import numpy as np
import pandas
import os
from PIL import Image
import glob
from os import listdir
from os.path import isfile, join
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import math
import copy
import torch.utils.data
import cv2
import tensorflow as tf
print("PyTorch Version: ",torch.__version__)
print("Torchvision Version: ",torchvision.__version__)
print("Tensor Flow Version: ", tf.__version__)
tf.test.gpu_device_name()
Out [1]:
PyTorch Version: 1.6.0
Torchvision Version: 0.7.0
Tensor Flow Version: 2.3.0
'/device:GPU:0'
In [2]:
torch.cuda.current_device()
Out [2]:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-2-3380d2c12118> in <module>
----> 1 torch.cuda.current_device()
~\Anaconda3\lib\site-packages\torch\cuda\__init__.py in current_device()
382 def current_device() -> int:
383 r"""Returns the index of a currently selected device."""
--> 384 _lazy_init()
385 return torch._C._cuda_getDevice()
386
~\Anaconda3\lib\site-packages\torch\cuda\__init__.py in _lazy_init()
184 raise RuntimeError(
185 "Cannot re-initialize CUDA in forked subprocess. " + msg)
--> 186 _check_driver()
187 if _cudart is None:
188 raise AssertionError(
~\Anaconda3\lib\site-packages\torch\cuda\__init__.py in _check_driver()
59 def _check_driver():
60 if not hasattr(torch._C, '_cuda_isDriverSufficient'):
---> 61 raise AssertionError("Torch not compiled with CUDA enabled")
62 if not torch._C._cuda_isDriverSufficient():
63 if torch._C._cuda_getDriverVersion() == 0:
AssertionError: Torch not compiled with CUDA enabled
有人可以帮助我了解这里发生的事情吗? 我已经卸载,然后重新安装了PyTorch和Tensor Flow几次,都没有成功。