It has been a while since I wrote my first tutorial about running deep learning experiments on Google's GPU enabled Jupyter notebook interface- Colab. Since then, my several blogs have walked through running either Keras, TensorFlow or Caffe on Colab with GPU accelerated.
One missing framework not pre-installed on Colab is PyTorch. Recently, I am checking out a video to video synthesis model requires running on Linux, plus there are gigabytes of data and pre-trained model to download before I can take the shiny model for a spin. I was wondering, why not give Colab a try by leveraging its awesome downloading speed and freely available GPU?
Let's starts by installing CUDA on Colab.
Why not other CUDA versions? Here are three reasons.
Back to installing, the Nvidia developer site will ask you for the Ubuntu version where you want to run the CUDA. To find out, run this cell below in a Colab notebook.
It returns the information you want.
VERSION="17.10 (Artful Aardvark)"
After that, you will be able to navigate through the target platform selections, make the installer type "deb(local)", then right click on the "Download (1.2 GB)" button to copy the link address.
Back to Colab notebook, paste the link after a wget command to download the file. A 1.2GB file only takes about 10 seconds to download on Colab which means there is no coffee break -_-.
Run the following cell to complete the CUDA installation.
!dpkg -i cuda-repo-ubuntu1710-9-2-local_9.2.148-1_amd64 # You can use this line to find out the directory name # !ls /var/ | grep cuda-repo !apt-key add /var/cuda-repo-9-2-local/7fa2af80.pub !apt-get update !apt-get install cuda
If you see those lines at the end of the output, that means the installing was successful.
Setting up cuda (9.2.148-1) ...
Processing triggers for libc-bin (2.26-0ubuntu2.1) ...
Continue with Pytorch.
Very easy, go to pytorch.org, there is a selector for how you want to install Pytorch, in our case,
It will let you run this line below, after which, the installation is done!
pip3 install torch torchvision
Out of the curiosity how well the Pytorch performs with GPU enabled on Colab, let's try the recently published Video-to-Video Synthesis demo, a Pytorch implementation of our method for high-resolution photorealistic video-to-video translation. That video demo turns poses to a dancing body looks enticing.
Besides, the demo also depends on custom built CUDA extensions gives the chance to test out the installed CUDA toolkit.
The cell below does all the job from getting the code to running the demo with the pre-trained model.
!git clone https://github.com/NVIDIA/vid2vid !pip install dominate requests # This step downloads and sets up several CUDA extensions !python scripts/download_flownet2.py # Download pre-trained model (smaller model) !python python scripts/download_models_g1.py # Run the demo !python test.py --name label2city_1024_g1 --dataroot datasets/Cityscapes/test_A --loadSize 1024 --n_scales_spatial 3 --use_instance --fg --n_downsample_G 2 --use_single_G
The generated frame goes to directory results/label2city_1024_g1/test_latest/images which you can display one by calling the cell below.
from IPython.display import Image Image(filename='results/label2city_1024_g1/test_latest/images/fake_B_stuttgart_00_000000_000003_leftImg8bit.jpg')
That wraps up this tutorial.
This short post shows you how to get GPU and CUDA backend Pytorch running on Colab quickly and freely. Unfortunately, the authors of vid2vid haven't got a testable edge-face, and pose-dance demo posted yet, which I am anxiously waiting. So far, It only serves as a demo to verify our installing of Pytorch on Colab. Feel free to connect with me on social media where I will keep you posted on my future projects and other practical deep learning applications.Share on Twitter Share on Facebook