WIN10下使用Anaconda配置TensorFlow深度学习环境(GTX1050TI+python3.6+TensorFlow1.15.0)
1.新建虚拟环境
确保电脑已经安装过Anaconda,打开CMD
可以直接在当前目录新建虚拟环境,命令行输入:
conda create -n env_name python=X.X
也可以在指定目录新建虚拟环境,这里我在D盘Anaconda安装目录的envs文件夹下新建虚拟环境,命令行输入:
conda create --prefix=D:\Anaconda\evns\env_name python=X.X
2.激活环境
conda activate env_name
3.安装cudatoolkit(很重要)
CUDA10.1只支持TensorFlow2.1.0及以上版本(具体版本对应关系可以参考这篇博客TensorFlow1.2~2.1各个GPU版本CUDA和cuDNN对应版本整理,电脑安装CUDA和CUDNN驱动可以参考其他博客本文不再赘述),如果电脑已安装CUDA10.1的驱动又不想退回低版本CUDA的话,可以在虚拟环境中直接安装CUDA10.0,命令行输入:
conda install cudatoolkit=10.0
3.安装TensorFlow
conda install tensorflow=1.15
4.测试
测试代码:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
测试结果:
(Yolov3) C:\Users\Narziss>python
Python 3.6.12 |Anaconda, Inc.| (default, Sep 9 2020, 00:29:25) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-11-08 16:24:27.994355: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2020-11-08 16:24:50.212625: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-11-08 16:24:50.330296: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
2020-11-08 16:24:50.337582: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2020-11-08 16:24:50.347488: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll
2020-11-08 16:24:50.359554: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_100.dll
2020-11-08 16:24:50.367122: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_100.dll
2020-11-08 16:24:50.381027: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_100.dll
2020-11-08 16:24:50.396118: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_100.dll
2020-11-08 16:24:50.425153: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-11-08 16:24:50.433613: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-11-08 16:24:50.441627: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2020-11-08 16:24:50.460041: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
2020-11-08 16:24:50.466493: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2020-11-08 16:24:50.473662: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll
2020-11-08 16:24:50.481333: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_100.dll
2020-11-08 16:24:50.487351: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_100.dll
2020-11-08 16:24:50.493843: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_100.dll
2020-11-08 16:24:50.498238: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_100.dll
2020-11-08 16:24:50.505298: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-11-08 16:24:50.516882: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-11-08 16:24:51.288048: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-11-08 16:24:51.294663: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0
2020-11-08 16:24:51.299265: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N
2020-11-08 16:24:51.304819: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2996 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>> print(sess.run(hello))
b'Hello, TensorFlow!'