Google Colab, or Google Collaboratory, is a free cloud-based platform to execute Python code in a web-based environment. It is supported by Tensor Processing Units (TPUs) and graphics processing units (GPUs), and it is built on Jupyter Notebook. Google Colab can be used to train machine learning models.
Mounting Google Drive in Google Colab helps us access and work with data/files in Google Drive directly without manually uploading the data to the Colab notebook. The Colab session does not store data permanently, meaning all data is lost once the session ends. By automatically mounting Google Drive, we can access the data conveniently and provide common storage for shared resources.
To use Google Drive in Colab Notebook, we require a Google account. We can create and set up a Colab notebook to start using it.
Once we create and set up the Colab notebook, we can mount Google Drive into our notebook by performing the following steps:
We click the “Files” option from the left sidebar of the notebook to open a new window with more options.
We click the “Mount Drive” option next to the “Refresh” option.
A new window pops up, which asks for permission. We grant permission to mount the drive.
Here is an example of mounting Google Drive to our notebook:
Another way of mounting Google Drive into our notebook is using a code cell, as shown below:
from google.colab import drivedrive.mount('/content/drive', force_remount=True)
We can confirm this by listing the Google Drive content using the ls
command as follows:
!ls "/content/drive/My Drive/"
Google Drive is mounted by running the above code in the Colab notebook cell, providing a Google account, and granting file permissions.
In conclusion, automatically mounting our Google Drive to Google Colab is an efficient way to work with Drive files. We can establish a persistent connection between our Google Drive and Colab notebook with a few lines of code. This process eliminates the need for manual mounting each time you start a new session.
Free Resources