【问题标题】:How to access zip files from drive on Google collab?如何从 Google Collab 上的驱动器访问 zip 文件?
【发布时间】:2020-01-09 09:17:18
【问题描述】:

我的 Google 驱动器中有来自 https://www.kaggle.com/puneet6060/intel-image-classification 的数据集。这些文件夹已压缩。

需要有关如何从主文件夹访问单个 zip 文件夹(seg_train.zip、seg_test.zip、seg_pred.zip)的帮助? 那么,在访问 zip 之后,比如说 seg_train.zip,如何从中访问文件夹(建筑物、冰川)?

我试过下面的代码:

    !pip install PyDriveimport os
    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    from google.colab import auth
    from oauth2client.client import GoogleCredentials
    auth.authenticate_user()
    gauth = GoogleAuth()
    gauth.credentials = GoogleCredentials.get_application_default()
    drive = GoogleDrive(gauth)
    download = drive.CreateFile({'id': '1d7-jWu8P1q3cNfcRaqSE8bybUrdl9qyW'})
    download.GetContentFile('data.zip')
    !unzip data.zip

主文件夹的ID

1d7-jWu8P1q3cNfcRaqSE8bybUrdl9qyW

我遇到以下错误:

FileNotDownloadableError                  Traceback (most recent call last)
<ipython-input-9-db7681c14c0b> in <module>()
----> 1 download.GetContentFile('data.zip')
      2 get_ipython().system('unzip data.zip')

2 frames
/usr/local/lib/python3.6/dist-packages/pydrive/files.py in FetchContent(self, mimetype, remove_bom)
    263     else:
    264       raise FileNotDownloadableError(
--> 265         'No downloadLink/exportLinks for mimetype found in metadata')
    266 
    267     if mimetype == 'text/plain' and remove_bom:

FileNotDownloadableError: No downloadLink/exportLinks for mimetype found in metadata

【问题讨论】:

    标签: google-drive-api google-colaboratory pydrive


    【解决方案1】:

    跳过 PyDrive 并使用此 sn-p 直接安装您的 Google Drive:

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

    然后,您可以像访问后端 VM 上的普通文件一样访问 Drive 中的目录。

    【讨论】:

    • 你能详细说明一下吗?假设我想访问英特尔图像分类数据文件夹,如第二张图像所示。我该怎么做?
    • 使用桌面上的Drive backup & sync 客户端将该目录与云端硬盘同步。然后,使用上面的 sn-p 连接到 Colab 上的云端硬盘文件,您将看到该目录。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多