Tuesday, January 8, 2019

Google Colab setup for fast.ai Deep learning course

For past few days I have been trying to setup Google Colab to run fast.ai lesson files.
Found multiple post on the same but  I was getting some or other error.

So here is the code which worked for me, I know there is latest version of fast.ai, but I wasn't able to make it work with that. 
Here the code is based on fastai version 0.7.
#Here is the code for setting up the fast ai in google colab
!pip uninstall fastai
!pip install Pillow==4.1.1
!pip install "fastai==0.7.0"
!pip install torchtext==0.2.3
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
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())
!apt update && apt install -y libsm6 libxext6
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
!pip install image
%matplotlib inline
from fastai.imports import *
#To download the data, for example dogcats.zip
!wget http://files.fast.ai/data/dogscats.zip
!unzip '/content/dogscats.zip'
#finally setting the path
PATH = "/content/dogscats/"
#Rest of the code you can use as per your lesson


I am unable to mention the author of the original post, as I was trying multiple combination at the time. If you are able to find, please comment, I will update my post with proper citation.


PS: sometimes Google colab throws random error, so I will suggest to reset all runtime and then run again