0

I want to read the dataset from drive inside Google Colab Notbook. how can I do that? I did something like this but it's not working.

train_data_dir = "data/train/"
validation_data_dir = "data/validation/"

This is the structure of my project

The data folder is like this:

data/
    train/
        dogs/
            dog001.jpg
            dog002.jpg
            ...
        cats/
            cat001.jpg
            cat002.jpg
            ...
    validation/
        dogs/
            dog001.jpg
            dog002.jpg
            ...
        cats/
            cat001.jpg
            cat002.jpg
            ...
Kara
  • 6,115
  • 16
  • 50
  • 57
Oussama
  • 603
  • 6
  • 10
  • 18

1 Answers1

-1

I found a solution using the Drive FUSE wrapper

you have to install the drive fuse wrapper then make a directory then mount it, that directory is the root directory of your drive, upload your dataset to your google drive and access it using "/content/name_of_your_directory/dataset_name/"

in my case I followed these steps:

1-Install a Drive FUSE wrapper.

!apt-get update -qq 2>&1 > /dev/null
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse

then

2-Generate auth tokens for Colab

from google.colab import auth
auth.authenticate_user()

3-Generate creds for the Drive FUSE library.

from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass

4-Work around misordering of STREAM and STDIN in Jupyter.

prompt = !google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass(prompt[0] + '\n\nEnter verification code: ')
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}

5-Create a directory and mount Google Drive using that directory.

!mkdir -p yourdirectory
!google-drive-ocamlfuse yourdirectory

6- access this directory from code like in my case

train_data_dir = "/content/yourdirectory/data/train/"
validation_data_dir = "/content/yourdirectory/data/validation/"
Oussama
  • 603
  • 6
  • 10
  • 18