TensorFlow 是一个端到端开源机器学习平台。它拥有一个全面而灵活的生态系统,其中包含各种工具、库和社区资源,可助力研究人员推动先进机器学习技术的发展,并使开发者能够轻松地构建和部署由机器学习提供支持的应用。
背景
Python 3.7 Windows10 64
步骤
安装Tensorflow库 目前版本是2.2
pip install tensorflow
pip install tensorflow-gpu (二选一,两个在使用上等价,只是性能有差别,gpu会稍微快一点)安装CUDA显卡加速软件(GPU的并行计算框架) tensorflow的支持版本是 10.1
下载地址: https://developer.nvidia.com/cuda-10.1-download-archive-update2
安装CUDNN(神经网络的加速包) 下载7.6即可
样例代码
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
message=tf.constant("Welcome")
with tf.compat.v1.Session() as sess:
print(sess.run(message).decode())
print(tf.__version__)
运行后的提示
2020-07-15 10:20:58.102520: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x26741a73950 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-15 10:20:58.102728: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2020-07-15 10:20:58.103169: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5
coreClock: 1.71GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 312.97GiB/s
2020-07-15 10:20:58.103468: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-07-15 10:20:58.103618: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-07-15 10:20:58.103765: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-07-15 10:20:58.103909: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-07-15 10:20:58.104054: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-07-15 10:20:58.104203: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-07-15 10:20:58.104351: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-07-15 10:20:58.104827: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-07-15 10:20:58.838326: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-15 10:20:58.838492: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108] 0
2020-07-15 10:20:58.838587: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0: N
2020-07-15 10:20:58.839346: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4602 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2060, pci bus id: 0000:01:00.0, compute capability: 7.5)
2020-07-15 10:20:58.842158: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x26764433380 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-07-15 10:20:58.842368: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): GeForce RTX 2060, Compute Capability 7.5
Welcome
2.2.0
出现错误的地方:
- cudart64_101.dll not found
没有安装正确版本的Cuda 请检查第二步骤 - cudnn64_7.dll not found
没有安装正确版本的cudnn 请看第三步骤
看不懂是啥玩意??
干啥用的