参考:https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d
https://zhuanlan.zhihu.com/p/33344222
https://blog.csdn.net/linhai1028/article/details/79275945
#--------------------------------------------------------------------------------
A.设置python、GPU版本号,
在【修改】》【笔记本设置】设置
B.安装必要的库、执行授权
!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}
C. 挂载Google Drive
!mkdir -p drive
!google-drive-ocamlfuse drive
D.启动程序
D.1 改变工作路径
(代码功能:把工作路径切换到app文件夹下面)
import os
os.chdir("drive/app") #app为工作的文件夹
D.2 启动程序
(注意:不要再加/app,否则会出错)
!python3 mnist_cnn.py #mnist_cnn.py为要执行的文件
E.查看当前路径
!ls
#-----------------------------------------------------------------------------------
1.每次新打开之前要运行:
挂载Google Drive
!mkdir -p drive
!google-drive-ocamlfuse drive
2.判断GPU是否工作:
import tensorflow as tf
tf.test.gpu_device_name()
3.重启
!kill -9 -1
转载自原文链接, 如需删除请联系管理员。
原文链接:Google colabo使用说明,转载请注明来源!