【问题标题】:How to use google colab to run the file 'train.py' in MyFolder?如何使用 google colab 在 MyFolder 中运行文件“train.py”?
【发布时间】:2020-02-27 11:23:58
【问题描述】:

我已经上传了一个包含我所有文件的谷歌驱动器文件夹。它的结构就像 -

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

我按照How to Upload Many Files to Google Colab? 上的说明安装文件夹 在我的电脑中,我只需转到 MyFolder,打开终端并运行 python train.py。如何在 google colab 中做同样的事情?我已将 MyFolder 上传到 Google Drive。

编辑:安装后,我将目录更改为 MyFolder(学分:Google colab changing directory)。我运行了 train.py,它仍在运行。我希望一切正常。所以现在我只想知道运行脚本后引起的所有更改都将存储在驱动器本身的 MyFolder 中?

我的问题解决了。提到的两个链接就足够了。

【问题讨论】:

  • Google colab 中的安装问题肯定不是与 artificial-intelligence 相关的问题 - 请不要向不相关的标签发送垃圾邮件(已删除)。另外,您可能更愿意将您的解决方案发布为答案并接受它,以便将来对其他人有用(并节省人们试图阅读您的帖子并认为问题仍然存在的时间成立,但不成立)。
  • 不知道你为什么觉得我有信息——如果我知道如何回答,我早就知道了;这个问题对于 SO 来说仍然过于宽泛,因为几乎所有对问题的口头描述实际上都是如此。

标签: google-colaboratory


【解决方案1】:

首先将 MyFolder 上传到 google drive。然后转到 google colab(使用相同的 gmail 帐户)。复制并粘贴以下脚本并在 google colab 上运行。(请参阅How to Upload Many Files to 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 changing directory。您可以使用 % 或 ! 运行 Linux 的终端命令在命令语句的开头。训练数据运行相应的命令。

!python train.py 

【讨论】:

    猜你喜欢
    • 2019-10-18
    • 2020-06-25
    • 1970-01-01
    • 2020-08-28
    • 2021-06-24
    • 2019-02-19
    • 2022-12-14
    • 2020-04-06
    • 2022-11-11
    相关资源
    最近更新 更多