如何从 Google collab 上的驱动器访问 zip 文件?
How to access zip files from drive on Google collab?
我的 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
跳过 PyDrive 并使用此代码段直接安装您的 Google 驱动器:
from google.colab import drive
drive.mount('/content/drive')
然后,您可以访问 Drive 中的目录,就像它们是后端 VM 上的普通文件一样。
我的 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
跳过 PyDrive 并使用此代码段直接安装您的 Google 驱动器:
from google.colab import drive
drive.mount('/content/drive')
然后,您可以访问 Drive 中的目录,就像它们是后端 VM 上的普通文件一样。