如何使用谷歌colab在MyFolder中运行文件"train.py"?



我上传了一个谷歌驱动器的文件夹,里面有我所有的文件。它的结构就像-

MyFolder
-Images
-train.py 
-classify.py
-Facenet.py

我按照"如何将许多文件上传到Google Colab?"的说明安装文件夹?在我的电脑里,我只需进入MyFolder,打开终端,运行python train.py。如何在谷歌colab中做同样的事情?我已经在谷歌驱动器上传了MyFolder。

编辑:挂载后,我将目录更改为MyFolder(署名:Google colab更改目录(。我已经运行了train.py,它仍在运行。我希望一切正常。所以现在我想知道的是,运行脚本后所做的所有更改都将存储在驱动器本身的MyFolder中?

我的问题解决了。提到两个环节就足够了。

首先在谷歌驱动器上上传MyFolder。然后转到谷歌colab(使用相同的gmail帐户(。复制并粘贴以下脚本并在谷歌colab上运行。(请参阅如何将许多文件上传到Google Colab?(

# Install a Drive FUSE wrapper.
# https://github.com/astrada/google-drive-ocamlfuse
!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

# Generate auth tokens for Colab
from google.colab import auth
auth.authenticate_user()

# Generate creds for the Drive FUSE library.
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}

# Create a directory and mount Google Drive using that directory.
!mkdir -p My Drive
!google-drive-ocamlfuse My Drive

!ls My Drive/
# Create a file in Drive.
!echo "This newly created file will appear in your Drive file list." > My Drive/created.txt

之后,您可以使用命令%cd Drive/移动到驱动器,然后命令%cd MyFolder在MyFolder内移动。请参阅Google colab更改目录。您可以使用%或!在命令语句的开头。要训练数据,请运行相应的命令。

!python train.py 

相关内容

最新更新