尝试用google colab训练自己的神经网络(二)

接下来我们要读取数据了,

首先挂载google drive:

# Install the PyDrive wrapper & import libraries.
# This only needs to be done once per notebook.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

然后读取我们的内容,

txt格式:

    file = drive.CreateFile({'id': '你的文件id'}) 

    file.GetContentFile('你的文件名.txt',"text/plain")

csv格式:

    file = drive.CreateFile({'id': '你的文件id'})

    file.GetContentFile('你的文件名.csv',"text/csv") 

然后按照正常手段处理数据即可。


我发现了另一种处理方式,更方便一点

挂载google drive:

!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}
!mkdir -p drive
!google-drive-ocamlfuse drive
import os
os.chdir("drive/你的文件夹/")
这个操作可让你以google drive中的指定文件夹作为工作目录,接下来就像平时用自己的电脑一样了。

你可能感兴趣的:(尝试用google colab训练自己的神经网络(二))