Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Colab: How can I mount a particular folder instead of mounting root folder?

Tags:

I am able to mount Google drive using the code below:

from google.colab import drive drive.mount('/content/drive') 

But the above mounts the Root folder enabling all file access within the drive.

I want a particular folder in Google drive to to be mounted (for example just the dataset folder). How can I achieve that?

like image 440
PrakashO Avatar asked Nov 07 '18 04:11

PrakashO


People also ask

How do I change the file path in Colab?

If you want to change directory from google colab into google drive, connect to google drive first. Change to the google drive directory. Yes, because this answer is slightly outdated. Now the same path should be: '/content/drive/MyDrive/'.

How do I mount files in google Colab?

Instructions. Place the Jupyter notebook in your Google Drive. In Google Drive in your web browser, open the Jupyter notebook with Colaboratory. Run the cells in this notebook to mount the drive and practice reading & writing files.

How do I add local folders to google Colab?

Access local files through the file-explorer You can either use the upload option at the top of the file-explorer pane to upload any file(s) from your local file system to Colab in the present working directory. 2. Select the “upload” option.


2 Answers

It's not possible to mount a subfolder, only top-level Drive. You can mount Drive in some out-of-the-way place and then symlink the folder you want someplace more central, e.g.:

from google.colab import drive drive.mount('/gdrive') !ln -s "/gdrive/My Drive/theFolder" "/content/theFolder" 
like image 90
Ami F Avatar answered Oct 12 '22 14:10

Ami F


If you have confidential files, you can create a new google login for collab studies, at least until google creates a way to mount the folder and not the entire driver.

like image 36
carmo crediney Avatar answered Oct 12 '22 14:10

carmo crediney