Add a folder with ~20K of images into Google Colaboratory

醉酒当歌 提交于 2019-11-29 10:22:23

问题


I am working with cat breeds recognition with Keras and try to use Google Colaboratory for training on GPU. When I worked in PyCharm, I used a path to folder with images:

data_dir = '//home//kate//Рабочий стол//барахло линух минт//more_breeds_all_new'

And I can not understand, how can I download a folder with 19500 images to Colab instead loading pictures there one by one like Google offers in it's notebook. I also have a folder with these images on Google Drive, but I also do not know how to use it as a full folder with it's path.


回答1:


First: zip image folder in .zip .tar format,example folder_data.zip and sync or upload it( folder_data.zip) to Google Drive.

Get google drive file_id of zip file( folder_data.zip) like 1iytA1n2z4go3uVCwE_vIKouTKyIDjEq

Second: I recommend you use Pydrive to download your file from google drive to colab notebook VM . I download 500MB dataset for 5s. 1. install Pydrive

!pip install PyDrive

2. OAouth

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# Authenticate and create the PyDrive client.
# This only needs to be done once in a notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
  1. code for download file from google drive

    fileId = drive.CreateFile({'id': 'DRIVE_FILE_ID'}) #DRIVE_FILE_ID is file id example: 1iytA1n2z4go3uVCwE_vIKouTKyIDjEq print fileId['title'] # folder_data.zip fileId.GetContentFile('folder_data.zip') # Save Drive file as a local file

Finaly: unzip it to folder, example in here is

!unzip folder_data.zip -d ./

list file look like it

folder_data.zip
folder_data/

Cheer Mo Jihad



来源:https://stackoverflow.com/questions/49088159/add-a-folder-with-20k-of-images-into-google-colaboratory

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