今天突然看到一篇推文,里面讲解了如何薅资本主义羊毛,即如何免费使用Google免费提供的GPU使用权。

可以免费使用的方式就是通过Google Colab,全名Colaboratory。我们可以用它来提高Python技能,也可以用Keras、TensorFlow、PyTorch、OpenCV等等流行的深度学习库来练习开发深度学习的应用。

现在我们介绍如何免费的使用这个非常非常给力的应用!!!

一  项目建立与配置

(1)在Google Drive上创建文件夹:这项功能的使用主要是通过Google Drive,首先需要在Google Drive里面创建新的文件夹,因为我们所有的操作都是通过Google Drive文件的方式进行的,这里我们创建了一个名为gpu的文件夹,然后打开文件夹;

(2)创建新的Colaboratory:右键更多选择Colaboratory, 如果更多没有的话,可以点击关联更多应用搜索添加即可!

并且这里可以随意修改文件名

(3)设置后端Python版本和免费的GPU使用:然后就可以进行代码编写了~~~

二   授权与挂载

(4)当完成基本的文件建立和配置后,就需要先运行下面这些代码,来安装必要的库、执行授权:

 !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}

点击运行可以看到如下结果:此时,点击链接地址,获取验证码。

点击链接地址,获取验证码。

提示成功!

(5)授权完成后,就可以挂载Google Drive了

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

三   测试阶段

我们使用安装Keras中的测试样例代码进行效果的测试:

 # -*- coding: utf-8 -*-

 '''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])

这里使用Google GPU的效率每个Epoch大概需要11s左右即可完成

而我们使用实验室的工作站

每个率每个Epoch大概需要130s+完成

四  相关命令

(1)查看是否使用GPU:

 import tensorflow as tf
tf.test.gpu_device_name()

(2)在使用哪个GPU:

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

(3)RAM大小:

 !cat /proc/meminfo

当然Google的使用需要自备翻墙工具!

原文链接:https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d

Google免费GPU使用教程的更多相关文章

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

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

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

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

  3. Google Colab 免费GPU服务器使用教程 挂载云端硬盘

    一.前言二.Google Colab特征三.开始使用3.1在谷歌云盘上创建文件夹3.2创建Colaboratory3.3创建完成四.设置GPU运行五.运行.py文件5.1安装必要库5.2 挂载云端硬盘 ...

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

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

  5. 深度学习,机器学习神器,白嫖免费GPU

    深度学习,机器学习神器,白嫖免费GPU! 最近在学习计算机视觉,自己的小本本没有那么高的算力,层级尝试过Google的Colab,以及移动云的GPU算力,都不算理想.如果数据集比较小,可以试试Cola ...

  6. Google免费的SVN服务器管理VS2010代码

    原文:Google免费的SVN服务器管理VS2010代码 前言 Google免费为我们提供了代码管理的SVN服务器.首先我这里用的Win7 64的电脑系统,用VS2010进行的代码开发.这里管理代码需 ...

  7. [海蜘蛛] 海蜘蛛 V8 全线无限试用版 免费发布破解教程

    http://bbs.p52.cn/forum.php?mod=viewthread&tid=3499&extra=page%3D1&page=1&_dsign=79c ...

  8. [转载]Google Android开发精华教程

    原文地址:Android开发精华教程">Google Android开发精华教程作者:huiyi8zai Android是Google于2007年11月5日宣布的基于Linux平台的开 ...

  9. Google 免费公共 DNS 服务器

    Google 免费公共 DNS 服务器 http://googleblog.blogspot.com/2009/12/introducing-google-public-dns.html DNS 8. ...

随机推荐

  1. Head First设计模式之工厂模式

    一.定义 定义了一个创建对象的接口, 但由子类决定要实例化的类是哪一个. 工厂方法让类把实例化推迟到子类 二.结构 1.抽象工厂角色:这是工厂方法模式的核心,它与应用程序无关.是具体工厂角色必须实现的 ...

  2. Linux 定时任务不生效的问题

    Linux 中定时任务不生效的问题屡见不鲜, 本质原因是: 登录式 shell & 非登录式 shell. 登录式 shell & 非登录式 shell 登录式 shell 有: su ...

  3. Mysql无法启动 InnoDB: Attempted to open a previously opened tablespace

    win2008,Mysql5.6,mysql服务无法启动 查看事件日志,报错InnoDB: Attempted to open a previously opened tablespace 最终解决方 ...

  4. Windows平台下的内存泄漏检测

    在C/C++中内存泄漏是一个不可避免的问题,很多新手甚至有许多老手也会犯这样的错误,下面说明一下在windows平台下如何检测内存泄漏. 在windows平台下内存泄漏检测的原理大致如下. 1. 在分 ...

  5. three.js 相机

    图形学中的相机定义了三维空间到二维屏幕的投影方式,根据投影方式的不同,相机可分为 正交投影相机 与 透视投影相机. 正交投影相机 : 近处.远处的物体大小尺寸保持一致,常适用于工程制图.建模软件,如C ...

  6. 关于 " +new Date "

    关于 " +new Date " 的个人见解 今天晚上,在一个Javascript的Q群里,有人问下面这种代码是什么意思: var time = +new Date; 这段代码中, ...

  7. Linux之内存描述符mm_struct

    Linux对于内存的管理涉及到非常多的方面,这篇文章首先从对进程虚拟地址空间的管理说起.(所依据的代码是2.6.32.60) 无论是内核线程还是用户进程,对于内核来说,无非都是task_struct这 ...

  8. Yii2.0源码阅读-一次请求的完整过程

    Yii2.0框架源码阅读,从请求发起,到结束的运行步骤 其实最初阅读是从yii\web\UrlManager这个类开始看起,不断的寻找这个类中方法的调用者,最终回到了yii\web\Applicati ...

  9. [搬运] C# 这些年来受欢迎的特性

    原文地址:http://www.dotnetcurry.com/csharp/1411/csharp-favorite-features 在写这篇文章的时候,C# 已经有了 17 年的历史了,可以肯定 ...

  10. hihocoder-1079题解(线段树+离散化)

    一.题目链接 http://hihocoder.com/problemset/problem/1079 二.题意 给定一个长度为L的区间,给你n个子区间,没一个区间涂成一种颜色,问最后这个区间内有几种 ...