如何在 google colaboratory 上使用 GPU 升级 tensorflow

How to upgrade tensorflow with GPU on google colaboratory

目前 google colaboratory 使用 tensorflow 1.4.1。我想将它升级到 1.5.0 版本。每次执行 !pip install --upgrade tensorflow 命令时,notebook 实例都会成功将 tensorflow 版本升级到 1.5.0。但是升级后运行tensorflow实例只支持"CPU".

当我执行此命令时,它什么也没显示:

from tensorflow.python.client import device_lib device_lib.list_local_devices()

是否应该有其他升级tensorflow的方法?比如升级到 tensorflow-gpu 包?另外,笔记本什么时候会配备升级的 tensorflows?

编辑:这行不通。看看萨尔瓦多的回答。

卸载tensorflow

!pip uninstall tensorflow -y

安装tensorflow-gpu

!pip install tensorflow-gpu==1.5.0

即使您将安装 gpu 版本 !pip install tensorflow-gpu==1.5.0,由于 cuda 库,它仍然无法导入它。目前我还没有找到将 1.5 版本与 GPU 一起使用的方法。所以我宁愿使用带 gpu 的 1.4.1 而不是不带 gpu 的 1.5。

您可以向他们发送反馈( 主页 - 发送反馈 ),希望如果有足够多的人发送类似的东西,他们会更新新的 GPU 版本。

Google Colaboratory 现在似乎支持最高版本 1.6.0rc1

import tensorflow as tf
tf.__version__

#'1.6.0-rc1'

如果你 enable the GPU hardware accelerator,GPU 应该可以工作。然后,您可以测试是否一切正常:

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

输出:

[name: "/device:CPU:0"
 device_type: "CPU"
 memory_limit: 268435456
 locality {
 }
 incarnation: 14621691266205111434, name: "/device:GPU:0"
 device_type: "GPU"
 memory_limit: 198836224
 locality {
   bus_id: 1
 }
 incarnation: 17821632640358169265
 physical_device_desc: "device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7"]

截至 2020 年,Colab 可以 运行 Tensorflow 2.0。卸载当前版本的 Tensorflow:

!pip uninstall tensorflow

然后使用 pip 重新安装即可。

!pip install tensorflow==2.0.0

如果您愿意,也可以使用

安装测试版
!pip install tensorflow==2.0.0-beta1

重新安装 Tensorflow 后,确保不要忘记在“运行时”选项卡下重新启动 运行time。

本机解决方案是以

开始您的代码
%tensorflow_version 2.x