一、前言
二、Google Colab特征
三、开始使用
3.1在谷歌云盘上创建文件夹
3.2创建Colaboratory
3.3创建完成
四、设置GPU运行
五、运行.py文件
5.1安装必要库
5.2 挂载云端硬盘
5.3 安装Keras
5.4 Hello Mnist!
一、前言
不知道大家是否为了寻找免费GPU服务器而焦头烂额。
近些天,谷歌推出了Google Colab(Colaboratory)
官方对其的说明是:

Colaboratory 是一个研究项目,可免费使用。

划重点,最重要的特点是 免费GPU!免费GPU!免费GPU!
虽然不确定这个项目是不是永久的
但这无疑给纠结在是否花大量钱租用GPU服务器进行研究的个人研究者带去了重磅福利!
经过查阅资料与亲自实践,特把相关教程写成博文分享给大家。
由于博主水平能力有限,难免有错误,欢迎指正哈!

2018.3.22更新
emmm,大概是用的人多了…
在colab上跑一个DCGAN竟然比自己笔记本上用CPU跑的还要慢5倍…
天下没有免费的午餐…

二、Google Colab特征
Colaboratory 是一个 Google 研究项目,旨在帮助传播机器学习培训和研究成果。它是一个 Jupyter 笔记本环境,不需要进行任何设置就可以使用,并且完全在云端运行。
Colaboratory 笔记本存储在 Google 云端硬盘中,并且可以共享,就如同您使用 Google 文档或表格一样。Colaboratory 可免费使用。
利用Colaboratory ,可以方便的使用Keras,TensorFlow,PyTorch等框架进行深度学习应用的开发。
三、开始使用
注意:使用google服务可能需要梯子

3.1在谷歌云盘上创建文件夹
当登录账号进入谷歌云盘时,系统会给予15G免费空间大小。由于Colab需要依靠谷歌云盘,故需要在云盘上新建一个文件夹。

选择新建文件夹,文件夹名称可自定义。

3.2创建Colaboratory
进入创建好的文件夹,点开新建-更多。

如果在更多栏里没有发现Colaboratory,选择关联更多应用,搜索Colaboratory,选择关联。

3.3创建完成
创建完成后,会自动生成一个jupyter笔记本,是不是很熟悉~

四、设置GPU运行
选择 修改-笔记本设置

将硬件加速器设置为GPU即可

五、运行.py文件
5.1安装必要库
输入相应代码,并执行(crtl+F9)

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!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 URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
1
2
3
4
5
6
7
8
9
10
11
12
运行后,会出现以下提示

先点开相应的链接,选择自己的谷歌账号,并允许,最后会得到相应的代码,输入相应的框中即可

5.2 挂载云端硬盘
同上,输入下面命令,执行即可

!mkdir -p drive
!google-drive-ocamlfuse drive -o nonempty
1
2
5.3 安装Keras
同理,输入命令

!pip install -q keras
1
5.4 Hello Mnist!
将代码粘入jupyter笔记本中,运行,即可开始奇妙的Google Colab之旅
代码摘自:https://github.com/keras-team/keras/blob/master/examples/mnist_cnn.py

'''Trains a simple convnet on the MNIST dataset.
Gets to 99.25% test accuracy after 12 epochs
(there is still a lot of margin for parameter tuning).
16 seconds per epoch on a GRID K520 GPU.
'''

from __future__ import print_function
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K

batch_size = 128
num_classes = 10
epochs = 12

# input image dimensions
img_rows, img_cols = 28, 28

# the data, shuffled and split between train and test sets
(x_train, y_train), (x_test, y_test) = mnist.load_data()

if K.image_data_format() == 'channels_first':
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
input_shape = (1, img_rows, img_cols)
else:
x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
input_shape = (img_rows, img_cols, 1)

x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')

# convert class vectors to binary class matrices
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),
activation='relu',
input_shape=input_shape))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))

model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adadelta(),
metrics=['accuracy'])

model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test))
score = model.evaluate(x_test, y_test, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

每一个epoch都只用了十多秒!
是不是很有意思呢!

References
https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d
---------------------
作者:cocoaqin
来源:CSDN
原文:https://blog.csdn.net/cocoaqin/article/details/79184540
版权声明:本文为博主原创文章,转载请附上博文链接!

Google Colab 免费GPU服务器使用教程 挂载云端硬盘的更多相关文章

  1. Google Colab 免费GPU服务器使用教程

    Google免费GPU使用教程(亲测可用)   今天突然看到一篇推文,里面讲解了如何薅资本主义羊毛,即如何免费使用Google免费提供的GPU使用权. 可以免费使用的方式就是通过Google Cola ...

  2. Google Colab免费GPU使用教程(一)

    一.前言 现在你可以开发Deep Learning Applications在Google Colaboratory,它自带免费的Tesla K80 GPU.重点是免费.免费!(国内可能需要tz) 这 ...

  3. Google Colab 免费的谷歌GPU for deep learning

    Who wants to use a free GPU for deep learning?Google Colab is a free cloud service and now it suppor ...

  4. Google Colab Free GPU Tutorial【转载】

    转自:https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d 1.Google Cola ...

  5. sftp服务器搭建以及挂载新硬盘到home目录下

    前言 我身边一直有一个空闲不用的硬盘,一直空闲不用,闲暇的时候想到为什么不用起来呢,于是想起来搭建一个sftp服务器,当做云盘用了 搭建sftp服务器 SFTP称作"安全的FTP" ...

  6. Google免费GPU使用教程(Google Colab Colaboratory)

    参考: https://www.234du.com/1154.html https://mp.weixin.qq.com/s/TGTToLYSQJui94-bQC4HIQ 注册gmail时遇到手机号无 ...

  7. Google Colab——用谷歌免费GPU跑你的深度学习代码

    Google Colab简介 Google Colaboratory是谷歌开放的一款研究工具,主要用于机器学习的开发和研究.这款工具现在可以免费使用,但是不是永久免费暂时还不确定.Google Col ...

  8. Google免费GPU使用教程

    今天突然看到一篇推文,里面讲解了如何薅资本主义羊毛,即如何免费使用Google免费提供的GPU使用权. 可以免费使用的方式就是通过Google Colab,全名Colaboratory.我们可以用它来 ...

  9. Google Colab使用教程

    简介Google Colaboratory是谷歌开放的云服务平台,提供免费的CPU.GPU和TPU服务器. 目前深度学习在图像和文本上的应用越来越多,不断有新的模型.新的算法获得更好的效果,然而,一方 ...

随机推荐

  1. Django项目:CRM(客户关系管理系统)--03--02PerfectCRM创建ADMIN页面01

    八.CRM项目创建king_admin python.exe manage.py startapp king_admin 'king_admin', 九.CRM项目分发URL "" ...

  2. Mysql的CMD操作

    一.MySQL登录和退出——在CMD模式操作 l  语法格式:mysql.exe –h主机名 –u用户名 –p密码 l  参数说明:   mysql.exe是mysql服务器的主应用程序.   -h代 ...

  3. callee和caller属性的区别

    在函数内部,有两个特殊的对象:arguments和this .arguments是一个类数组对象,用于存放传入函数中的所有参数. callee是arguments对象的属性,caller是所有函数对象 ...

  4. 一位AI研究员+区块链创业者的终极展望:AI DAO将统治世界

    一位AI研究员+区块链创业者的终极展望:AI DAO将统治世界 [日期:2017-01-09] 来源:infoq.com  作者:杨赛 [字体:大 中 小] Trent McConaghy是一位资深的 ...

  5. 下载额外数据文件失败 以下软件包要求安装后下载附加数据,但其数据无法下载或无法处理 ttf-mscorefonts-installer

    故障显示: 一些软件包的数据文件无法下载 以下软件包要求安装后下载附加数据,但其数据无法下载或无法处理. ttf-mscorefonts-installer 这是一个永久错误,系统中的这些软件包将无法 ...

  6. 利用SQL查询扶贫对象医保报销比率的审计方法

    利用SQL查询扶贫对象医保报销比率的审计方法 扶贫资金惠及贫困百姓的切身利益,主管部门多,资金实行逐级下拨,并且扶贫项目小而分散,主要在乡镇和农村实施.根据湖北省审计厅关于2017年扶贫审计工作方案的 ...

  7. 【7.19 graphshortestpath graphallshortestpaths函数】matlab 求最短路径函数总结

    graphshortestpath 函数是用来解决最短路径问题的. 语法为: [dist, path, pred]=graphshortestpath(G,S) [dist, path, pred]= ...

  8. 安装tomcat(fedora16)

    sudo yum install tomcat6 sudo yum install tomcat6-webapps sudo yum install tomcat6-admin-webapps   s ...

  9. Directx11教程(19) 画一个简单的地形

    原文:Directx11教程(19) 画一个简单的地形       通常我们在xz平面定义一个二维的网格,然后y的值根据一定的函数计算得到,比如正弦.余弦函数的组合等等,可以得到一个看似不错的地形或者 ...

  10. RDS 5.7三节点企业版时代的数据一致性解决方案

    上篇我们看到了在MySQL主备模式下,我们在数据一致性上做了不少事情,但解决方案都有一定的局限性,适合部分场景或者解决不彻底的问题.随着以Google Spanner以及Amazon Aruora 为 ...