【问题标题】:importing zip file in google Colaboratory stored in google drive在存储在谷歌驱动器中的谷歌 Colaboratory 中导入 zip 文件
【发布时间】:2018-09-11 17:19:58
【问题描述】:

我需要以 .zip 格式将存储在 google 驱动器上的数据访问到 google 协作室。 至于每次我需要上传大数据时都训练模型。有没有其他有效的方法可以直接访问数据而无需每次都上传?

【问题讨论】:

    标签: python tensorflow neural-network conv-neural-network google-colaboratory


    【解决方案1】:

    从谷歌驱动器中提取 zip 文件的最小方法

    from google.colab import drive
    drive.mount('/content/gdrive')
    

    在新标签中打开链接->您将获得一个代码-将其复制回您现在可以访问谷歌驱动器检查的提示:

    !unzip "/content/gdrive/My Drive/file_name.zip"
    

    【讨论】:

      【解决方案2】:

      您可以使用 google-drive-ocamlfuse 将谷歌驱动器挂载到 colab 实例。

      以下代码来自这篇博文:https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d

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

      上面的代码会显示授权URL并要求输入验证码。

      提供代码后,应该可以将谷歌驱动器安装到本地文件夹:

      !mkdir -p drive
      !google-drive-ocamlfuse drive
      

      【讨论】:

        【解决方案3】:

        首先安装和导入库

        !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
        

        然后您验证自己并连接到 Google Drive

        auth.authenticate_user()
        gauth = GoogleAuth()
        gauth.credentials = GoogleCredentials.get_application_default()
        drive = GoogleDrive(gauth)
        

        然后,您将文件 your_data.zip 从 Google Drive 下载到 Colab。

        fid = drive.ListFile({'q':"title='your_data.zip'"}).GetList()[0]['id']
        f = drive.CreateFile({'id': fid})
        f.GetContentFile('your_data.zip')
        

        您可以从这里解压缩它们并进行所需的任何培训。

        【讨论】:

          猜你喜欢
          • 2018-07-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-10-09
          相关资源
          最近更新 更多