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
How We Make Money Homesteading - Boots & Hooves Homestead
Stocks Are Recovering While the Economy Collapses. That Makes More Sense Than You'd Think.
Cold Air Intake - High-flow, Roto-mold Tube - TOYOTA TACOMA V6-4.0
Sandrail Options and Accessories
Missing 2023 Showtimes Near Cinemark West Springfield 15 And Xd
Senior Tax Analyst Vs Master Tax Advisor
Prosper TX Visitors Guide - Dallas Fort Worth Guide
Myhr North Memorial
Blairsville Online Yard Sale
Kent And Pelczar Obituaries
Pbr Wisconsin Baseball
Braums Pay Per Hour
Roblox Character Added
Dark Souls 2 Soft Cap
Florida (FL) Powerball - Winning Numbers & Results
Moe Gangat Age
Watch TV shows online - JustWatch
5808 W 110Th St Overland Park Ks 66211 Directions
Theycallmemissblue
Cnnfn.com Markets
Nitti Sanitation Holiday Schedule
Moparts Com Forum
Procore Championship 2024 - PGA TOUR Golf Leaderboard | ESPN
Aldi Süd Prospekt ᐅ Aktuelle Angebote online blättern
Swedestats
Weather Rotterdam - Detailed bulletin - Free 15-day Marine forecasts - METEO CONSULT MARINE
Prestige Home Designs By American Furniture Galleries
Keck Healthstream
Curry Ford Accident Today
ELT Concourse Delta: preparing for Module Two
Https Paperlesspay Talx Com Boydgaming
O'Reilly Auto Parts - Mathis, TX - Nextdoor
Encore Atlanta Cheer Competition
Greyson Alexander Thorn
Kirsten Hatfield Crime Junkie
Pioneer Library Overdrive
Cardaras Funeral Homes
What is Software Defined Networking (SDN)? - GeeksforGeeks
Log in or sign up to view
Calvin Coolidge: Life in Brief | Miller Center
Boneyard Barbers
Suspect may have staked out Trump's golf course for 12 hours before the apparent assassination attempt
How Much Is Mink V3
Tokyo Spa Memphis Reviews
ENDOCRINOLOGY-PSR in Lewes, DE for Beebe Healthcare
Free Crossword Puzzles | BestCrosswords.com
Quiktrip Maple And West
Deezy Jamaican Food
Lesly Center Tiraj Rapid
All Buttons In Blox Fruits
Ewwwww Gif
Razor Edge Gotti Pitbull Price
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.