4

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 Answers1

6

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

Mohamed Jihad
  • 466
  • 3
  • 5