In this tutorial we will create a Google Compute Engine with 16 vCPUs, 60 GB memory, 500GB SSD disk, and 2 x NVIDIA Tesla K80 GPUs.
sudo shutdown -h now
while you are logged into the VM via Terminal.
In order to create a Google Compute Engine we need a Google account, if you do not have one please Create your Google Account and continue.
Google offers a generous $300 free credit for everyone with an account to try the provided services. We should visit Google Cloud Platform and click TRY IT FREE. We will be asked to enter contact and credit card information, however, we will only be charged upon finishing $300 free credit and if we upgrade our account, which we will in order to be able to use GPUs.
Filling out the information, will direct us to Google Cloud Platform Dashbord. We should go to VM instances under Compute Engine menu and wait until the compute engine is ready.
Now, we can visit Quotas section under IAM & admin menu to increase the quota of GPUs to 2 Nvidia K80, which is zero in default. First select the project as shown in the picture below.
Then we should find the Google Compute Engine API related to NVidia K80 GPUs in the us-west1 zone, check the box next to it and click EDIT QUOTAS on the top bar. Afterwards, we fill out the information asked in the right menu and request a Change to 2 GPUs and submit it. In a few minutes we will receive an approaval email.
Upon receiving the approval email, we go to VM instances under Compute Engine menu and start configuring the Virtual Machine instance. You can use any configuration you prefer, but as a purpose of this blog post we will use the following configuration
Now we click create and wait for about 20 minutes while virtual machine is getting ready and Nvidia Drivers and CUDA are being installed. You can come later to continue or watch these tow TED Talks.
After about 20 minutes we should visit External IP addresses under VPC network and change the ip Type to Static. We will use the static ip address to connect from our local browser to Jupyter Notebook running on the virtual machine.
Now we should define a new Firewall rule. Go to Firewall rulesunder VPC network and click CREATE FIREWALL RULE on the top menu and fill out the following information.
We are ready to install Deep Learning libraries on our Google Compute Engine. In my opinion the most convenient way to connect to a Google Compute Engine is via Terminal, however you can activate Google Cloud Shell from an icon similar to >- and skip installig Google Cloud SDK. Go to Google Cloud SDK and install it using the scripts in 1, 2, 3, and 4, before going to next section.
When you finish installing SDK run gcloud auth login
to allow Google Cloud SDK to access your account.
Then copy gcloud command as shown in the below and run it on Terminal.
Now we are ready to install Python Deep Learning Libraries on our machine. First copy and paste the following code on Terminal (be sure that you are connected to Google Compute Engine instance) to download the scripts we need.
wget https://raw.githubusercontent.com/ImOmid/Deep-Learning-on-Google-Compute-Engine/master/gcp_ubuntu16_dl.sh
Then run bash gcp_ubuntu16_dl.sh
on Terminal to install the libraries. This process will take about 1 hours, so be patient and do your other task without closing Terminal. After it is done a message will be shown on Terminal which guid you to check if everything is done successfully.
When you see a message similar to the one in the picture above run the followings in order on Terminal to be sure that the python virtual environment was created successfully with deep learning libraries and OpenCV 3.3.0 installed. If there is no erros now you have created a Powerful virtual machine which you can use to train your models.
source ~/venv/bin/activate
ipython
import tensorflow as tf
import keras
import torch
import cv2
exit
jupyter notebook --no-browser --port 7000
You will see a URL similar to the one in the picture below. Copy the url and paste it on your browser address bar and replace the localhost with the external ip address of you virtual machine which you can find at External IP addresses under VPC network. Hit the Enter and you are running Jupyter Notebook of your Google Compute Engine instance locally.
sudo shutdown -h now
while you are logged into the VM via Terminal.