Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google-Colaboratory - How to Refresh google-drive?

I am using google-colaboratory GPU to train NN models. My python/pytorch code is stored in google-drive. I am able to mount my drive in colaboratory and train models. But any python code changes in the "my drive" is not updated to google-colaboratory even after rebooting my PC and start all again.

To clear the google-colaboratory cache I tried :

!google-drive-ocamlfuse -cc

But it does not work:

/bin/bash: google-drive-ocamlfuse: command not found

How to clean this cache and avoid waiting hours before my code being taken into account by google-colaboratory ? Thanks in advance

PS : the method I used to mount:

from google.colab import drive
drive.mount('/content/drive/')
like image 712
u2gilles Avatar asked Nov 18 '18 05:11

u2gilles


People also ask

Can colab access Google Drive?

Since a Colab notebook is hosted on Google's cloud servers, there's no direct access to files on your local drive (unlike a notebook hosted on your machine) or any other environment by default. However, Colab provides various options to connect to almost any data source you can imagine.

How do you import files from Google Drive to Colab?

Once you have completed verification, go to the CSV file in Google Drive, right-click on it and select “Get shareable link”. The link will be copied into your clipboard. Paste this link into a string variable in Colab.


2 Answers

google-drive-ocamlfuse is irrelevant to mounts using google.colab.drive.mount as described in the PS, so not surprising the -cc invocation is not helping you. I suspect what's happening is you have .py files stored in Google Drive, which you're importing in your notebook, and you want to see changes to the .py files reflected in your runtime, but they're not because python's import system is idempotent (an import statement is ignored if python thinks it's already loaded a module by that name, even if the underlying file has changed). You can force a reload using something like https://stackoverflow.com/a/437591/8755609 e.g.:

from importlib import reload  # Py3 only; unneeded in py2.
foo = reload(foo)

(obvs replace foo with your module's name).

like image 181
Ami F Avatar answered Oct 20 '22 10:10

Ami F


Try using:

drive.mount('/content/drive/',force_remount=True)

Sometimes the files tab lags behind in refreshing so you might consider waiting for some time too.

like image 37
Farhan Hai Khan Avatar answered Oct 20 '22 09:10

Farhan Hai Khan