google colab配置gpu环境tensorflow

注意:

首先,tensorflow-gpu和tensorflow不要同时存在。否则会自动选择tensorflow的cpu
第二、colab自带tensorflow和keras

安装步骤:

(1)下载tensorflow和keras

pip list  //查看安装了哪些包,如tensorflow、keras
pip uninstall tensorflow
pip uninstall keras

(2)安装cuda环境,每个tensorflow-gpu版本对应了相应的cuda版本


image.png
!cat /usr/local/cuda/version.txt//查看cuda版本
//安装cuda9.0
!wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
!apt-get update
!apt-get install cuda=9.0.176-1

//安装cuda8.0
!wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
!dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
!apt-get update
!apt-get install cuda=8.0.61-1

(3)安装tensorflow-gpu

pip install tensorflow-gpu==1.11.0

(4)按需安装keras

pip install keras

测试gpu配置

import tensorflow as tf
tf_config = tf.ConfigProto()
tf_config.gpu_options.allow_growth = True
with tf.Session(config=tf_config) as sess:
  print("32")
image.png

测试成功!

参考链接:

https://blog.csdn.net/weixin_43922901/article/details/90715779
https://blog.csdn.net/qq_35654046/article/details/87601561
https://blog.csdn.net/tailonh/article/details/105944605
https://www.cnblogs.com/kongle666/archive/2004/01/13/9456417.html

你可能感兴趣的:(google colab配置gpu环境tensorflow)