How to upload my dataset into Google Colab?

橙三吉。 提交于 2021-02-07 10:01:10

问题


I have my dataset on my local device. Is there any way to upload this dataset into google colab directly.

Note:

I tried this code :

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

But it loads file by file. I want to upload the whole dataset directly


回答1:


Here's the workflow I used to upload a zip file and create a local data directory:

  1. zip the file locally. Something like: $zip -r data.zip data
  2. upload zip file of your data directory to colab using their (Google's) instructions.

    from google.colab import files
    uploaded = files.upload()
    
  3. Once zip file is uploaded, perform the following operations:

    import zipfile
    import io
    zf = zipfile.ZipFile(io.BytesIO(uploaded['data.zip']), "r")
    zf.extractall()
    

Your data directory should now be in colab's working directory under a 'data' directory.




回答2:


Another way is to store all the dataset into a numpy object and upload to drive. There you can easily retrieve it. (zipping and unzipping also fine but I faced difficulty with it)




回答3:


Zip or tar the files first, and then use tarfile or zipfile to unpack them.



来源:https://stackoverflow.com/questions/48841500/how-to-upload-my-dataset-into-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!