安装并验证tensorflow是否可用

  • 安装
pip install --upgrade pip
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow-gpu
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow-probability
  • 验证
import tensorflow as tf
tf.__version__

#检验CPU版TensorFlow是否可用:
tf.reduce_sum(tf.random.normal([1000, 1000]))

#检验GPU版TensorFlow是否可用:
#tf.test.is_gpu_available()
tf.config.list_physical_devices('GPU') #检验GPU版TensorFlow是否可用:
  • 另一种在ipython下验证的方法
import tensorflow as tf 
with tf.device('/GPU:0'):
    a = tf.constant(3)

猜你喜欢

转载自blog.csdn.net/qq_43377653/article/details/127454112