Deep learning made easy with Colaboratory

TL;DR: Get free a GPU and environment with Jupyter Notebook with this tutorial

mnist

MNIST dataset picture from the tutorial

I always struggle to set up the environment for deep learning frameworks. It seems you need the right set and versions of hardware, OS, drivers,framework. And if you want GPU support, things get even worse.

But google wants you to use their google cloud platform. They even give you the first shot for free a free server including Linux, ssh and static ip.

And google is one of the leading companies in Deep learning. They combined both with Colaboratory. You get:

  • Tesla K80 GPU shared instance for up to 12h / day
  • complete software environment with Jupyter Notebook
  • linked to google drive so you can share with your friends other people
  • you can access the base operating system easily and install other software like opencv

Someone else invested a lot of time and work to explain this. Follow fuat’s tutorial here.

Out of memory errors

Well, this is free, so you only get the ‘free’ resources. You can check how much with this snippet

# memory footprint support libraries/code
!ln -sf /opt/bin/nvidia-smi /usr/bin/nvidia-smi
!pip install gputil
!pip install psutil
!pip install humanize
import psutil
import humanize
import os
import GPUtil as GPU
GPUs = GPU.getGPUs()
# XXX: only one GPU on Colab and isn’t guaranteed
gpu = GPUs[0]
def printm():
process = psutil.Process(os.getpid())
print("Gen RAM Free: " + humanize.naturalsize( psutil.virtual_memory().available ), " I Proc size: " + humanize.naturalsize( process.memory_info().rss))
print("GPU RAM Free: {0:.0f}MB | Used: {1:.0f}MB | Util {2:3.0f}% | Total {3:.0f}MB".format(gpu.memoryFree, gpu.memoryUsed, gpu.memoryUtil*100, gpu.memoryTotal))
printm()

 

The good output should look like this:

Requirement already satisfied: gputil in /usr/local/lib/python3.6/dist-packages (1.3.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from gputil) (1.14.3)
Requirement already satisfied: psutil in /usr/local/lib/python3.6/dist-packages (5.4.5)
Requirement already satisfied: humanize in /usr/local/lib/python3.6/dist-packages (0.5.1)
Gen RAM Free: 12.6 GB I Proc size: 308.3 MB
GPU RAM Free: 11438MB | Used: 1MB | Util 0% | Total 11439MB

If it is not enough you should kill your instance and reconnect. Make sure you comment this line again after execution!

# !kill -9 -1

 

this is the source with other scripts