Getting Started With Google Colab

You can create notebooks in Colab, upload notebooks, store notebooks, share notebooks, mount your Google Drive and use whatever you’ve got stored in there, import most of your favorite directories, upload your personal Jupyter Notebooks, upload notebooks directly from GitHub, upload Kaggle files, download your notebooks, and do just about everything else that you might want to be able to do.It’s awesome.Working in Google Colab for the first time has been totally phenomenal and pretty shockingly easy, but it hasn’t been without a couple of small challenges!.If you know Jupyter Notebooks at all, you’re pretty much good to go in Google Colab, but there are just a few little differences that can make the difference between flying off to freedom on the wings of free GPU and sitting at your computer, banging your head against the wall…Photo by Gabriel Matula on UnsplashThis article is for anyone out there who is confused, frustrated, and just wants this thing to work!Setting up your driveCreate a folder for your notebooks(Technically speaking, this step isn’t totally necessary if you want to just start working in Colab. However, since Colab is working off of your drive, it’s not a bad idea to specify the folder where you want to work. You can do that by going to your Google Drive and clicking “New” and then creating a new folder. I only mention this because my Google Drive is embarrassingly littered with what looks like a million scattered Colab notebooks and now I’m going to have to deal with that.)If you want, while you’re already in your Google Drive you can create a new Colab notebook..Just click “New” and drop the menu down to “More” and then select “Colaboratory.”Otherwise, you can always go directly to Google Colab.Game on!You can rename your notebook by clicking on the name of the notebook and changing it or by dropping the “File” menu down to “Rename.”Set up your free GPUWant to use GPU?.It’s as simple as going to the “runtime” dropdown menu, selecting “change runtime type” and selecting GPU in the hardware accelerator drop-down menu!Get coding!You can easily start running code now if you want!.You are good to go!Make it betterWant to mount your Google Drive?.Use:from google.colab import drivedrive.mount('/content/gdrive')Then you’ll see a link, click on that, allow access, copy the code that pops up, paste it in the box, hit enter, and you’re good to go!.If you don’t see your drive in the side box on the left, just hit “refresh” and it should show up.(Run the cell, click the link, copy the code on the page, paste it in the box, hit enter, and you’ll see this when you’ve successfully mounted your drive):Now you can see your drive right there on the left-hand side of the screen!.(You may need to hit “refresh.”) Plus, you can reach your drive any time with!ls "/content/drive/My Drive/"If you’d rather download a shared zip file link, you can use:!wget !unzipFor example:!wget -cq https://s3.amazonaws.com/content.udacity-data.com/courses/nd188/flower_data.zip!unzip -qq flower_data.zipThat will give you Udacity’s flower data set in seconds!If you’re uploading small files, you can just upload them directly with some simple code..However, if you want to, you can also just go to the left side of the screen and click “upload files” if you don’t feel like running some simple code to grab a local file.Google Colab is incredibly easy to use on pretty much every level, especially if you’re at all familiar with Jupyter Notebooks..However, grabbing some large files and getting a couple of specific directories to work did trip me up for a minute or two.I covered getting started with Kaggle in Google Colab in a separate article, so if that’s what interests you, please check that out!Importing librariesImports are pretty standard, with a few exceptions.For the most part, you can import your libraries by running import like you do in any other notebook.PyTorch is different!.Before you run any other Torch imports, you’ll want to run# http://pytorch.org/from os.path import existsfrom wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tagplatform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*.([0-9]*).([0-9]*)$/cu12/'accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-{platform}-linux_x86_64.whl torchvisionimport torchThen you can continue with your imports..If you try to simply run import torch you’ll get an error message.. More details

Leave a Reply