colab

Colab的使用


Colab介绍

好东西!! 贫穷的人民,想拥有GPU或者TPU的难得的方式
对于一些基础的东西,都不加以介绍了,如果有兴趣,可以自己去查一下,或者ucadity的tensorflow教程里面就要用到这个东西,直接视频观看即可。
这里直接记录配置方式

首先选择修改,改为GPU或者TPU

然后添加如下代码后执行

1
2
3
4
5
6
7
8
9
10
11
12
!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
!mkdir -p drive
!google-drive-ocamlfuse drive

如果需要安装包的时候,比如:

1
!pip install http://download.pytorch.org/whl/cu80/torch-0.3.1-cp36-cp36m-linux_x86_64.whl torchvision

这样安装就ok了

当然在执行之前还需要更改目录:

1
2
import os
os.chdir('drive/.../...')#进入你希望进入的目录