Google Colab Free GPU Tutorial (2024)

Now you can develop deep learning applications with Google Colaboratory -on the free Tesla K80 GPU- using Keras, Tensorflow and PyTorch.

Google Colab Free GPU Tutorial (3)

Before we start, I would like to recommend you to join the leading community for AI experts and aspiring talents around the world: Global AI Hub.

Hello! I will show you how to use Google Colab, Google’s free cloud service for AI developers. With Colab, you can develop deep learning applications on the GPU for free.

I am happy to announce that this blog post was selected as KDnuggets Silver Blog for February 2018! Read this on KDnuggets.

Google Colab Free GPU Tutorial (4)

Google Colab is a free cloud service and now it supports free GPU!

You can;

  • improve your Python programming language coding skills.
  • develop deep learning applications using popular libraries such as Keras, TensorFlow, PyTorch, and OpenCV.

The most important feature that distinguishes Colab from other free cloud services is; Colab provides GPU and is totally free.

Detailed information about the service can be found on the faq page.

Creating Folder on Google Drive

Google Colab Free GPU Tutorial (5)

Since Colab is working on your own Google Drive, we first need to specify the folder we’ll work. I created a folder named “app” on my Google Drive. Of course, you can use a different name or choose the default Colab Notebooks folder instead of app folder.

Google Colab Free GPU Tutorial (6)

Creating New Colab Notebook

Create a new notebook via Right click > More > Colaboratory

Google Colab Free GPU Tutorial (7)

Rename notebook by means of clicking the file name.

Google Colab Free GPU Tutorial (8)

It is so simple to alter default hardware (CPU to GPU or vice versa); just follow Edit > Notebook settings or Runtime>Change runtime type and select GPU as Hardware accelerator.

Google Colab Free GPU Tutorial (9)

Now we can start using Google Colab.

Google Colab Free GPU Tutorial (10)

I will run some Basic Data Types codes from Python Numpy Tutorial.

Google Colab Free GPU Tutorial (11)

It works as expected :) If you do not know Python which is the most popular programming language for AI, I would recommend this simple and clean tutorial.

Run these codes first in order to install the necessary libraries and perform authorization.

When you run the code above, you should see a result like this:

Google Colab Free GPU Tutorial (12)

Click the link, copy verification code and paste it to text box.

After completion of the authorization process, you should see this:

Google Colab Free GPU Tutorial (13)

Now you can reach you Google Drive with:

install Keras:

!pip install -q keras

upload mnist_cnn.py file to app folder which is located on your Google Drive.

Google Colab Free GPU Tutorial (14)

run the code below to train a simple convnet on the MNIST dataset.

!python3 "/content/drive/My Drive/app/mnist_cnn.py"

As you can see from the results, each epoch lasts only 11 seconds.

If you want to download .csv file from url to “app” folder, simply run:

!wget https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/datasets/Titanic.csv -P "/content/drive/My Drive/app"

You may upload your .csv files directly to “app” folder instead of wget method.

Google Colab Free GPU Tutorial (15)

Read .csv file in “app” folder and display first 5 rows:

import pandas as pd
titanic = pd.read_csv(“/content/drive/My Drive/app/Titanic.csv”)
titanic.head(5)
Google Colab Free GPU Tutorial (16)

It is easy to clone a Github repo with Git.

Step 1: Find the Github Repo and Get “Git” Link

Find any Github repo to use.

For instance: https://github.com/wxs/keras-mnist-tutorial

Clone or download > Copy the link!

2. Git Clone

Simply run:

!git clone https://github.com/wxs/keras-mnist-tutorial.git
Google Colab Free GPU Tutorial (17)

3. Open the Folder in Google Drive

Folder has the same with the Github repo of course :)

4. Open The Notebook

Right Click > Open With > Colaboratory

5. Run

Now you are able to run Github repo in Google Colab.

Google Colab Free GPU Tutorial (18)

1. How to Install Libraries?

Keras

!pip install -q keras
import keras

PyTorch

from os import path
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu'!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.3.0.post4-{platform}-linux_x86_64.whl torchvision
import torch

or try this:

!pip3 install torch torchvision

MxNet

!apt install libnvrtc8.0
!pip install mxnet-cu80
import mxnet as mx

OpenCV

!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2

XGBoost

!pip install -q xgboost==0.4a30
import xgboost

GraphViz

!apt-get -qq install -y graphviz && pip install -q pydot
import pydot

7zip Reader

!apt-get -qq install -y libarchive-dev && pip install -q -U libarchive
import libarchive

Other Libraries

!pip install or !apt-get install to install other libraries.

2. Is GPU Working?

To see if you are currently using the GPU in Colab, you can run the following code in order to cross-check:

import tensorflow as tf
tf.test.gpu_device_name()
Google Colab Free GPU Tutorial (19)

3. Which GPU Am I Using?

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

Currently, Colab only provides Tesla K80.

Google Colab Free GPU Tutorial (20)

4. What about RAM?

!cat /proc/meminfo
Google Colab Free GPU Tutorial (21)

5. What about CPU?

!cat /proc/cpuinfo

6. Changing Working Directory

Normally when you run this code:

!ls

You probably see datalab and drive folders.

Therefore you must add drive/app before defining each filename.

To get rid of this problem, you can simply change the working directory. (In this tutorial I changed to app folder) with this simple code:

import os
os.chdir("drive/app")

After running code above, if you run again

!ls

You would see app folder content and don’t need to add drive/app all the time anymore.

7. “No backend with GPU available“ Error Solution

If you encounter this error:

Failed to assign a backend
No backend with GPU available. Would you like to use a runtime with no accelerator?

Try again a bit later. A lot of people are kicking the tires on GPUs right now, and this message arises when all GPUs are in use.

Reference

8. How to Clear Outputs of All Cells

Follow Tools>>Command Palette>>Clear All Outputs

9. “apt-key output should not be parsed (stdout is not a terminal)” Warning

If you encounter this warning:

Warning: apt-key output should not be parsed (stdout is not a terminal)

That means authentication has already done. You only need to mount Google Drive:

!mkdir -p drive
!google-drive-ocamlfuse drive

10. How to Use Tensorboard with Google Colab?

I recommend this repo:

https://github.com/mixuala/colab_utils

11. How to Restart Google Colab?

In order to restart (or reset) your virtual machine, simply run:

!kill -9 -1

12. How to Add Form to Google Colab?

In order not to change hyperparameters every time in your code, you can simply add form to Google Colab.

Google Colab Free GPU Tutorial (22)

For instance, I added form which contain learning_rate variable and optimizer string.

Google Colab Free GPU Tutorial (23)

13. How to See Function Arguments?

To see function arguments in TensorFlow, Keras etc, simply add question mark (?) after function name:

Google Colab Free GPU Tutorial (24)

Now you can see original documentation without clicking TensorFlow website.

Google Colab Free GPU Tutorial (25)

14. How to Send Large Files From Colab To Google Drive?

15. How to Run Tensorboard in Google Colab?

If you want to runt Tensorboard in Google Colab, run the code below.

You can track your Tensorboard logs with created ngrok.io URL. You will find the URL at the end of output.

Note that your Tensorboard logs will be save to tb_logs dir. Of course, you can change the directory name.

Google Colab Free GPU Tutorial (26)

After that, we can see the Tensorboard in action! After running the code below, you can track you Tensorboard logs via ngrok URL.

Tensorboard :)

Google Colab Free GPU Tutorial (27)

I think Colab will bring a new breath to Deep Learning and AI studies all over the world.

If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.

You can find me on Twitter .

Last Note

This blog post will be constantly updated.

26-01–2018

  • “insert app folder to path” removed
  • “downloading, reading and displaying .csv file” added
  • “Some Useful Tips” added

27–01–2018

  • “Changing Working Directory” added

28–01–2018

  • “Cloning Github Repo to Google Colab” added
  • “pip install mxnet” added

29–01–2018

No backend with GPU available. Error Solution added

2–02–2018

  • “MxNet Installation” changed (CPU to GPU)

5–02–2018

  • “How to Clear Outputs of All Cells” added
  • apt-key output should not be parsed (stdout is not a terminal) warning added

11–02–2018

  • “How to use Tensorboard with Google Colab” added

20–02–2018

28–02–2018

  • “How to Restart Google Colab?” added

9–03–2018

  • How to Add Form to Google Colab? added

21–03–2018

  • How to See Function Arguments? added

20–05–2018

  • PyTorch installation updated

18–08–2018

  • How to Send Large Files From Colab to Google Drive added

19–08–2018

  • How to Run Tensorboard in Google Colab added

28–09–2018

  • Auth and Google Drive mounting processs changed
Google Colab Free GPU Tutorial (2024)
Top Articles
Three-step investing strategy | Fidelity
Building your FY 2025 portfolio? Here are 5 real estate investment options | Mint
Devon Lannigan Obituary
Archived Obituaries
Top Scorers Transfermarkt
Mileage To Walmart
Truist Park Section 135
Us 25 Yard Sale Map
Optimal Perks Rs3
Volstate Portal
Soap2Day Autoplay
ATV Blue Book - Values & Used Prices
Dumb Money
United Dual Complete Providers
Erskine Plus Portal
272482061
Price Of Gas At Sam's
Canvas Nthurston
Petco Vet Clinic Appointment
20 Different Cat Sounds and What They Mean
Shopmonsterus Reviews
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
Melendez Imports Menu
Craigslist Houses For Rent In Milan Tennessee
Jail View Sumter
Craig Woolard Net Worth
Farm Equipment Innovations
Craigslist Northern Minnesota
What we lost when Craigslist shut down its personals section
Darknet Opsec Bible 2022
Craigslist Cars And Trucks Mcallen
Persona 4 Golden Taotie Fusion Calculator
#scandalous stars | astrognossienne
Appraisalport Com Dashboard /# Orders
Does Iherb Accept Ebt
Tirage Rapid Georgia
888-333-4026
Miracle Shoes Ff6
Shane Gillis’s Fall and Rise
2007 Jaguar XK Low Miles for sale - Palm Desert, CA - craigslist
Nina Flowers
Coffee County Tag Office Douglas Ga
Reilly Auto Parts Store Hours
Skyward Cahokia
Conan Exiles Colored Crystal
Actress Zazie Crossword Clue
Horseneck Beach State Reservation Water Temperature
Craiglist.nj
Msatlantathickdream
Sml Wikia
What your eye doctor knows about your health
Southern Blotting: Principle, Steps, Applications | Microbe Online
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 6438

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.