博客
关于我
Google Colab 免费GPU 教程
阅读量:285 次
发布时间:2019-03-01

本文共 2266 字,大约阅读时间需要 7 分钟。

Google Colab 免费 GPU 教程

近日,Google 的交互式工具 Colaboratory 推出了 GPU 支持的版本,提供了免费的 Tesla K80 GPU,支持 Keras、Tensorflow 和 PyTorch 等前端框架。Colab 是谷歌开源的一款类似 Jupyter 的交互式工具,适合进行深度学习和数据分析。以下是使用 Colab 免费 GPU 的详细教程。

1. 在 Google Drive 创建文件夹

Colab 工作在 Google Drive 上,我们需要先新建一个文件夹。进入 Google Drive 后,右键点击新建文件夹,选择适当的文件夹名称,准备开始创建 Colab 环境。

2. 设置免费 GPU 环境

进入 Colab 的编辑界面,在“Edit”菜单中选择“Notebook settings”,然后勾选“Hardware Accelerator”(GPU),将 GPU 设为默认运行硬件。

3. 运行 Python 代码

配置好 Colab 环境后,就可以开始运行 Python 代码了。以下是一些简单的代码示例,左侧的小按钮可以方便地运行代码。

4. 配置依赖库运行环境

安装必要的库并配置环境,这一步需要运行以下代码:

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools!add-apt-repository -y ppa:alessandro-strada/ppa!apt-get update -qq!apt-get -y install -qq google-drive-ocamlfuse fuse!from google.colab import auth!auth.authenticate_user()!from oauth2client.client import GoogleCredentials!creds = GoogleCredentials.get_application_default()!import getpass!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URLvcode = getpass.getpass()!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}

运行代码后会显示验证码,输入验证码后即可完成授权。

5. 挂载到 Google Drive

运行以下命令将 Colab 挂载到 Google Drive:

!mkdir -p drive!google-drive-ocamlfuse drive

此时你已经完成了 GPU 环境的搭建,接下来可以运行一些有趣的例子。

6. 安装必要的库

安装 Keras:

!pip install -q keras

安装 PyTorch:

!pip install -q http://download.pytorch.org/whl/cu75/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl torchvision

安装 OpenCV:

!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python

安装 XGBoost:

!pip install -q xgboost==0.4a30

安装 GraphViz:

!apt-get -qq install -y graphviz && pip install -q pydot

安装解压工具:

!apt-get -qq install -y libarchive-dev && pip install -q -U libarchive

安装其他工具包可根据需求使用以下命令:

!pip install 或者 !apt-get install

7. 查看 GPU 状态

使用 TensorFlow 查看 GPU 状态:

import tensorflow as tftf.test.gpu_device_name()

运行上述命令可查看当前使用的设备。Colab 提供 Tesla K80 GPU,你还可以使用以下命令查看所有本地设备:

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

8. 运行中的信息查看

查看内存信息:

!cat /proc/meminfo

查看处理器信息:

!cat /proc/cpuinfo

9. 最后建议

Colab 为各位 AI 小伙伴提供了极为便利的研究环境,不仅有友好的交互界面,同时还有 GPU 支持。以后做科研的同学可以不用担心 GPU 的问题。

如果你对 Colab 感兴趣,可以立即注册 Google 账号开始使用。别忘了分享这篇教程,让更多人也能轻松使用免费 GPU!

转载地址:http://vrla.baihongyu.com/

你可能感兴趣的文章
Objective-C实现canny边缘检测算法(附完整源码)
查看>>
Objective-C实现cartesianProduct笛卡尔乘积算法(附完整源码)
查看>>
Objective-C实现check strong password检查密码强度算法(附完整源码)
查看>>
Objective-C实现chudnovsky algorithm楚德诺夫斯基算法(附完整源码)
查看>>
Objective-C实现CIC滤波器(附完整源码)
查看>>
Objective-C实现circle sort圆形排序算法(附完整源码)
查看>>
Objective-C实现CircularQueue循环队列算法(附完整源码)
查看>>
Objective-C实现clearBit清除位算法(附完整源码)
查看>>
Objective-C实现climbStairs爬楼梯问题算法(附完整源码)
查看>>
Objective-C实现cocktail shaker sort鸡尾酒排序算法(附完整源码)
查看>>
Objective-C实现cocktailShakerSort鸡尾酒排序算法(附完整源码)
查看>>
Objective-C实现CoinChange硬币兑换问题算法(附完整源码)
查看>>
Objective-C实现collatz sequence考拉兹序列算法(附完整源码)
查看>>
Objective-C实现Collatz 序列算法(附完整源码)
查看>>
Objective-C实现comb sort梳状排序算法(附完整源码)
查看>>
Objective-C实现combinationSum组合和算法(附完整源码)
查看>>
Objective-C实现combinations排列组合算法(附完整源码)
查看>>
Objective-C实现combine With Repetitions结合重复算法(附完整源码)
查看>>
Objective-C实现combine Without Repetitions不重复地结合算法(附完整源码)
查看>>
Objective-C实现conjugate gradient共轭梯度算法(附完整源码)
查看>>