Free GPU ---- Colaboratory specify the Google Drive folder

1. Run the code in the bottom of the notebook are authorized to bind

Run under the Code (fool paste can be run):

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

 

2. Specify the working directory

Before first use specified !lscommand to see what the cloud is automatically assigned the default file directory, cloud default document root is datalab

 

 

Run under the code to specify the document root directory:

# Specify Google Drive Drive root directory, called Drive
 mkdir -! The p-Drive
 ! Drive-ocamlfuse Google-Drive

After specifying finished, then the !lscommand to view the bound document root, root directory into a drive.

 

 

3. Specify the current working folder

# Specify the current working folder 
Import os 

# here is the file path google drive in, drive to work before the specified root directory, to add 
os.chdir ( " Drive / Colab Notebooks / dog_project " )



# 指定当前的工作目录
import os
# 此处为google drive中的文件路径,drive为之前指定的工作根目录,要加上
os.chdir("drive/.../...") 

Again with a !lsview of the current file directory

 

 

Note that, Colaboratory is entirely cloud-based operation, each landing operation, the background distribution of the machine are random,
So if the notebook is running requires additional files, before you have to run the file to upload to Google Drive,
Then Colaboratory specify the working directory.
 

 

 

Source: https: //www.jianshu.com/p/ce2e63d1c10c

Guess you like

Origin www.cnblogs.com/chenlove/p/12520022.html