In this quick tutorial, we’ll see how to use Google Drive as a file storage system when working in Google Colab.
Mount Google Drive
The first step is to mount Google Drive on your Colab session :
from google.colab import drive
drive.mount('/content/drive')
Once you run the cell, a link is provided, similar to :
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=XXX
Open the URL. You should now see a page asking for access to the content of your Drive. Allow access.
Now, simply copy the code given.
Paste it in your notebook :
Check the content of your drive
Your drive is accessible through the folder drive/My Drive
. To check the content of this folder, run the following cell in your notebook :
!ls "drive/My Drive"
Load a file from your drive
Your drive can now be used as a local folder ! For example :
X_train = np.load('drive/My Drive/X_train.npy')
Similarly, you can save your files as you would do locally.
Conclusion : I hope this quick tip on Google Drive on Colab was helpful. If you have any question, don’t hesitate to drop a comment!