簡體   English   中英

如何從本地驅動器上傳大數據並將其保存到Google Colaboratory?

[英]How to upload and save large data to Google Colaboratory from local drive?

我從這個Kaggle鏈接下載了大圖像訓練數據作為zip

https://www.kaggle.com/c/yelp-restaurant-photo-classification/data

我如何有效地實現以下目標?

  1. 在Google Colaboratory中創建一個項目文件夾
  2. 將zip文件上傳到項目文件夾
  3. 解壓縮文件

謝謝

編輯:我嘗試了下面的代碼,但它崩潰了我的大型zip文件。 有沒有更好/更有效的方法來執行此操作,我可以在本地驅動器中指定文件的位置?

from google.colab import files
uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))
!pip install kaggle
api_token = {"username":"USERNAME","key":"API_KEY"}
import json
import zipfile
import os
with open('/content/.kaggle/kaggle.json', 'w') as file:
    json.dump(api_token, file)
!chmod 600 /content/.kaggle/kaggle.json
!kaggle config set -n path -v /content
!kaggle competitions download -c jigsaw-toxic-comment-classification-challenge
os.chdir('/content/competitions/jigsaw-toxic-comment-classification-challenge')
for file in os.listdir():
    zip_ref = zipfile.ZipFile(file, 'r')
    zip_ref.extractall()
    zip_ref.close()

第9行有一些細微的變化,沒有遇到錯誤。 來源: https//gist.github.com/jayspeidell/d10b84b8d3da52df723beacc5b15cb27無法添加為評論原因代表。

你可以參考這些主題:

另請查看I / O示例筆記本 例如,要訪問xls文件,您需要將文件上傳到Google表格。 然后,您可以在同一I / O示例筆記本中使用gspread配方。

您可能需要使用kaggle-cli模塊來幫助下載。

它在這個fast.ai線程中討論過。

我剛剛編寫了這個腳本,可以將Kaggle API中的數據下載並提取到Colab筆記本中。 您只需粘貼用戶名,API密鑰和競爭名稱即可。

https://gist.github.com/jayspeidell/d10b84b8d3da52df723beacc5b15cb27

Colab中的手動上傳功能現在有點兒麻煩,最好通過wget或API服務下載文件,因為每次打開筆記本時都要使用新的VM。 這樣數據將自動下載。

另一個選擇是將數據上傳到Dropbox(如果它適合),獲取下載鏈接。 然后在筆記本上做

!wget link -0 new-name && ls

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM