参考这篇文章
【window环境】Python安装与深度学习环境(tensorflow)配置保姆教程_python安装tensorflow-CSDN博客
遇到报错
解决:
pip uninstall numpy==1.19.2
pip install numpy==1.20.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
测试:
import tensorflow as tf
print (tf.__version__)
if tf.test.gpu_device_name():
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
print("Please install GPU version of TF")
返回device:GPU:0就很正常,因为我就一块显卡可用
import tensorflow as tf
tf.debugging.set_log_device_placement(True)
# Place tensors on the CPU
with tf.device('/GPU:0'):
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
print(c)
返回tf.Tensor(
[[22. 28.]
[49. 64.]], shape=(2, 2), dtype=float32)