問題描述
我已經(jīng)在谷歌驅(qū)動器上有一個(2K 圖像)數(shù)據(jù)集的壓縮包.我必須在 ML 訓(xùn)練算法中使用它.下面的代碼以字符串格式提取內(nèi)容:
I already have a zip of (2K images) dataset on a google drive. I have to use it in a ML training algorithm. Below Code extracts the content in a string format:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
import io
import zipfile
# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# Download a file based on its file ID.
#
# A file ID looks like: laggVyWshwcyP6kEI-y_W3P8D26sz
file_id = '1T80o3Jh3tHPO7hI5FBxcX-jFnxEuUE9K' #-- Updated File ID for my zip
downloaded = drive.CreateFile({'id': file_id})
#print('Downloaded content "{}"'.format(downloaded.GetContentString(encoding='cp862')))
但我必須將其提取并存儲在單獨的目錄中,因為這樣更容易處理(以及理解)數(shù)據(jù)集.
But I have to extract and store it in a separate directory as it would be easier for processing (as well as for understanding) of the dataset.
我試圖進一步提取它,但得到不是 zipfile 錯誤"
I tried to extract it further, but getting "Not a zipfile error"
dataset = io.BytesIO(downloaded.encode('cp862'))
zip_ref = zipfile.ZipFile(dataset, "r")
zip_ref.extractall()
zip_ref.close()
Google 云端硬盤數(shù)據(jù)集
注意:數(shù)據(jù)集僅供參考,我已經(jīng)將這個 zip 下載到我的 google 驅(qū)動器中,我指的只是驅(qū)動器中的文件.
Note: Dataset is just for reference, I have already downloaded this zip to my google drive, and I'm referring to file in my drive only.
推薦答案
你可以簡單的使用這個
!unzip file_location
這篇關(guān)于從 Google colab 筆記本中提取 Google Drive zip的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!