Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (2024)

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (3)

If you are a Python user, you must be familiar with Jupyter Notebook. The good news is Google has a cloud based service called CoLab. It is just like running Jupyter Notebook on Google Drive. No need to apply for additional accounts, and no need to apply for the service. All you need is a Google Drive account, and that’s it. Easy & Simple! The best thing is that it gives users free TPU access to run your task! Therefore, if your local machine does not have enough GPU power, for example, my T470P laptop has only 2G VRAM (graphic card memory) and couldn’t run a training task that needs approximately 4G memory, then Google CoLab can be one solution.

In this blog, I will introduce:

  • How to create a CoLab in Google Drive
  • How to install library in CoLab
  • How to import modules in CoLab

As the below image shows, use the normal way you created a Google doc to add a coLab document. If you are using it for the first time, you would have to add the service in the Connect more apps section and search Colaboratory in the pop-up App searching box.

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (4)
Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (5)

This is how it looks in a Colab document. It is almost identical to JupyterNoteBook. It has CODE and TEXT to allow you add a new cell to write your code or text, and when you hit SHIFT+ENTER, it will execute the cell. The TEXT cell also support Markdown syntax.

Colab has command line support, so simply add ! exclamation mark to run Linux commands in the cell. You can simply run !pip install <package-name>to perform pip install. So when you go to Pytorch official installation website, and choose the specifications of the pytorch version you want to download, make sure you choose Linux, Pip, and Python, and then the CUDA version you want to install, and you would see a pip command line shown at the bottom:

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (6)

Then copy paste that command to CoLab cell with a prefix !
So, simply run !pip install torch trochvision in the CoLab cell:

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (7)

Then after it runs, the package is successfully installed.

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (8)

Note: It seems that CoLab has already preinstalled Pytorch for you, so if you run this command, it’ll tell you “Requirement already satisfied”. However, you can use the same method to install any other python package through pip install.

Mount Google Drive

For the Colab to recognize your Google Drive main directory, the first step is to mount your Google drive to CoLab, by running these:

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

After you execute the above code, it will show a URL link that has the authorization code for you to grant admission. Click on the URL, and copy paste the authentification code to the input box here.

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (9)
Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (10)

Now it’s done! Your Google Drive is mounted in this path /content/drive/My Drive/. Try listing out all the files under the dir.

!ls "/content/drive/My Drive/"

Now the platform can recognize "/content/drive/My Drive/" as the root path. Any Python modules under this main directory can be seen and imported. For example, if I have a Python file model.py under my Google Drive directory, then I can simply do import model in my Colab.

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (11)

However, sometimes we want to separate our projects and use different dir for different projects. Then we can add our project dir to the sys.path which allows Python to see everything under the project dir. For example, if my project folder is under code folder and then image-segmentation-keras folder. The absolute path is /content/drive/My Drive/code/image-segmentation-keras.

Then we can simply add the “code” folder path to the system path:

import sys

# Add your absolute path of your project folder to system path.
sys.path.append("/content/drive/My Drive/code/image-segmentation-keras")

# See the full list of paths in sys.path
print(sys.path)

After adding the project folder to sys.path, now I can import any Python modules in this folder. For example, I can import `keras_segmentation` module in my Colab:

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (12)
import keras_segmentation

One last thing is Don't forget to setup free TPU for your CoLab page if you are using it to run a GPU intensive training task, e.g., a Deep Learning task. You can setup a TPU in Edit > Notebook settings. Choose GPU or TPU from the drop down menu Hardware accelerator and then you are good to go!

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (13)
Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (14)

Lastly, although the abovementioned steps is all you need to get started using Pytorch in Google Colab, if you happened to be a VSCode user, and want to access Google Colab via VSCode interface, then I found this article very interesting to have a look.

That’s it! Hope you enjoy this tutorial about how to setup a Deep Learning environment on CoLab! If you find this post to be useful, please leave a “clap” to this post! You are also welcome to leave your thoughts, comments or feedback! Thanks for your reading!

Google CoLab Tutorial — How to setup a Deep Learning Environment on CoLab (2024)
Top Articles
Part 5: When Can We Expect A Useful Quantum Computer? A Closer Look At Timelines | Quantum.Amsterdam
Phantom Wallet - Web3 Wiki
Craigslist Houses For Rent In Denver Colorado
Jazmen Jafar Linkedin
No Limit Telegram Channel
Driving Directions To Fedex
San Diego Terminal 2 Parking Promo Code
Localfedex.com
Best Cheap Action Camera
Katie Boyle Dancer Biography
Tcu Jaggaer
Our Facility
zopiclon | Apotheek.nl
Cnnfn.com Markets
Nwi Arrests Lake County
9044906381
Theresa Alone Gofundme
Overton Funeral Home Waterloo Iowa
Kringloopwinkel Second Sale Roosendaal - Leemstraat 4e
Rubber Ducks Akron Score
A Man Called Otto Showtimes Near Cinemark University Mall
1145 Barnett Drive
Bidrl.com Visalia
Ullu Coupon Code
Remnants of Filth: Yuwu (Novel) Vol. 4
Www Mydocbill Rada
Dl.high Stakes Sweeps Download
Petsmart Distribution Center Jobs
Texters Wish You Were Here
Tenant Vs. Occupant: Is There Really A Difference Between Them?
Obsidian Guard's Skullsplitter
Mcgiftcardmall.con
Stanley Steemer Johnson City Tn
511Pa
The best specialist spirits store | Spirituosengalerie Stuttgart
Unveiling Gali_gool Leaks: Discoveries And Insights
LumiSpa iO Activating Cleanser kaufen | 19% Rabatt | NuSkin
Strange World Showtimes Near Century Stadium 25 And Xd
War Room Pandemic Rumble
Amy Zais Obituary
Spreading Unverified Info Crossword Clue
St Anthony Hospital Crown Point Visiting Hours
552 Bus Schedule To Atlantic City
Enter The Gungeon Gunther
Identogo Manahawkin
Diccionario De Los Sueños Misabueso
Bluebird Valuation Appraiser Login
Autozone Battery Hold Down
Craigslist Monterrey Ca
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 5675

Rating: 4.4 / 5 (55 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.