赞
踩
说明:
1. 此台电脑上装了anaconda
,下列教程对比完整安装TensorFlow-GPU,缺少的部分是:安装anaconda,安装cuda+cudnn(win10下这两步挺简单的)
2. 我的cuda安装了10.2版本,tensorflow-gpu==2.1
支持的cuda是10.1,这个问题在后面解决了(至少表面上)……
3. 另外,由于anaconda的base环境里已经装好了 torch,我想把 torch 和 tf 分开,所以新建虚拟环境。如果直接安装 tf,请省略Step1,2。
4. 中间遇上的不少问题也是在网上找到了别人的方法……如果出现一些错误请指正~本人挺菜的……
总过程一共花了1个小时多点吧
打开cmd窗口
conda create -n tf_gpu python=3.7
conda activate tf_gpu
如果出现下述报错,(按提示)执行conda init cmd.exe
退出,打开新的cmd窗口即可
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your invocation to 'CALL conda.bat activate'.
(tf_gpu) pip install nltk
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
中间省略报错
/simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
但我新建的虚拟环境里有openssl
所以……去对比了一下我的base环境,发现少了两个和ssl有关的包
决定先conda install pyopenssl
装完还是不行
conda install service_identity
ok pip正常
(tf_gpu) PS C:\Users\3\D\2019-master>
pip install --upgrade pip
Requirement already up-to-date: pip in e:\anaconda\lib\site-packages (20.0.2)
(tf_gpu) PS C:\Users\30322\Desktop\BallClustering_ICCV2019-master>
tf
官网:https://tensorflow.google.cn/install
感觉官方教程不太靠谱呢……pip install tensorflow
这应该是默认cpu版的安装命令。
所以决定pip install tensorflow-gpu
,不加版本号,试试会不会自动装最新的
嗯确实安装最新版了……就是这网速……
(tf_gpu) PS C:\Users\30322\Desktop\BallClustering_ICCV2019-master>
pip install tensorflow-gpu
Collecting tensorflow-gpu
Downloading tensorflow_gpu-2.1.0-cp37-cp37m-win_amd64.whl (356.5 MB)
| | 245 kB 5.5 kB/s eta 17:55:29
然后我试了下使用已经添加好了国内源的conda: conda install tensorflow-gpu==2.1
发现又没有conda识别出我装好的的cuda……
找到了一个有2.1版本的源,速度很快~ pip install tensorflow-gpu==2.1 -i https://pypi.douban.com/simple
(tf_gpu) PS C:\Users\3\D\2019-master>
pip install tensorflow-gpu==2.1 -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting tensorflow-gpu==2.1
Downloading https://pypi.doubanio.com/…………………………………………
|███ | 32.4 MB 2.2 MB/s eta 0:02:29
但是:
ERROR: google-auth 1.11.2 has requirement setuptools>=40.3.0, but you'll have setuptools 40.2.0 which is incompatible.
哪些版本低了更新就好。pip install --upgrade setuptools
ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
查到的:pip install -U --ignore-installed wrapt enum34 simplejson netaddr
夜深了不愿意去查这句命令后几个包具体是啥以及是不是必须(其实就是菜)
结果:
Successfully installed cachetools-4.0.0 google-auth-1.11.2 google-auth-oauthlib-0.4.1 keras-preprocessing-1.1.0 markdown-3.2.1 oauthlib-3.1.0 opt-einsum-3.1.0 requests-2.22.0 requests-oauthlib-1.3.0 rsa-4.0 scipy-1.4.1 tensorboard-2.1.0 tensorflow-gpu-2.1.0
进入python环境,import tensorflow as tf
Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
完蛋我装的是cuda10.2……torch也是官网说支持10.1但也能在10.2环境运行,为啥TF这么苛刻啊啊23333
再见,人间不值得
咳咳
上网一查发现神奇操作
把C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin
中的 cudart64_102.dll 复制改名为 cudart64_101.dll 粘贴,然后就可以import了
检查是否成功的代码见下:
>>>import tensorflow as tf
>>> tf.config.list_physical_devices('GPU')
2020-02-21 00:52:26.690740: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1050 Ti computeCapability: 6.1
coreClock: 1.62GHz coreCount: 6 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s
2020-02-21 00:52:26.730078: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-02-21 00:52:26.749611: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-02-21 00:52:26.762755: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-02-21 00:52:26.767525: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-02-21 00:52:26.791410: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-02-21 00:52:26.796559: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-02-21 00:52:26.800775: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-02-21 00:52:26.818404: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
为了证明上面的改名操作对torch没有影响
>>> import torch
>>> print(torch.cuda.is_available())
True
>>>
大概装了这么多,估计以后一段时间内还是用CPU计算的,用GPU的话,我这1050Ti也撑不住呢
等待疫情结束回去用Ubuntu吧~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。