[SOLVED] Need help setting up Colab environment

I have followed the instruction on the fast.ai website- https://course.fast.ai/start_colab.html.

But I am unable to run cells that depend on local files. For example-

I have also tried everything as mentioned in the guide.

What are my steps to make it work?

the files need to be local in colab, not on your desktop system.

you can run this in a cell to upload files into the colab runtime.

from google.colab import files
uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
  name=fn, length=len(uploaded[fn])))

you can also just click the folder icon in the top left under the menu bar and upload things there, you can also connect your google drive and copy things in and out (handy because anything you create inside the colab runtime will eventually vanish when the runtime gets recycled).

It doesn’t work as it is trying to open a file images/notebook_tutorial/cat_example.jpg which doesn’t exists.

These images are part of the fastai repo here: https://github.com/fastai/course-v3/tree/master/nbs/dl1 but when you open a github file in colab, it only loads that particular file, and it doesn’t know about the rest of the files in that repo.

You just have to ensure you also download images folder and use the right path in the call above. There are some solutions discussed in this thread - Platform: Colab ✅

For e.g., you could clone the whole repo locally by running this in a cell:

!git clone https://github.com/fastai/course-v3.git

This will clone the repo in /content/course-v3. You can then change the path to image in this folder as follows:

Image.open('course-v3/nbs/dl1/images/notebook_tutorial/cat_example.jpg')

1 Like

Thanks for the reply. I have followed the guide word by word.

And I understand that, the files need to be local in colab. But how to get those files?

I follow the steps here as mentioned in the post.

But whenever I need to use any local files, the file can’t be found.

There is no mention of how to obtain the files needed for running the notebook. Any idea?

I don’t think !curl -s https://course.fast.ai/setup/colab | bash fetches the needed files.

Then, how is Image.open('images/notebook_tutorial/cat_example.jpg') supposed to work?

I am very new to fast.ai.

Help will be highly appreciated.

N.B.- In Paperspace, only the v4 notebooks are available. And the notebook I began to work with looks incomplete. So, I will start learning from v4 when the course becomes available.

!curl -s https://course.fast.ai/setup/colab | bash just creates folders and updates the fastai library if it’s out of date. it doesn’t download anything specific to any notebook.

generally each notebook will download the files it needs itself. (i think you’ve just found an example in the notebook tutorial which expected that you’ve git cloned everything to your local system. don’t worry about it.)

for example the notebook you have on paperspace does this:

from fastai2.vision.all import *
path = untar_data(URLs.PETS)/'images'

which downloads the data and unzips it into your runtime.

if you want to start on v3 it’s dead easy. from the open notebook screen on colab click on github, enter fastai in the user/organisation box and pick the fastai/course-v3 repo. you can open notebooks from there and then save a copy into your google drive. i’d have thought paperspace should be just as easy and i know people are using it for v3, but i’ve never used it so i can’t comment.

1 Like

The idea was really helpful.

I mounted the Drive and then cloned the repo onto it.

Works perfectly, can access the image in the intro to notebook notebook.

And I wote a guide- https://medium.com/@r.ghosh/setting-up-google-colab-for-fast-ai-mooc-488d5d0f99f.

Thanks for the assistance. It was really helpful.

Thanks. I wrote a whole guide about it though. That’s one less thing to worry about.

Paperspace is more straightforward than Colab, but there the v4 of the course is made available which is incomplete. You can check the link I provided.

When the v4 videos are made available (read in Reddit, on Aug 4), I will probably switch to Paperspace.

step 6: clone the repo. you really don’t need to do this. that one single cat picture in the notebook tutorial is the only file you’re going to find missing, and that was simply an oversight.

the lesson notebooks download everything they need as they go along.

1 Like

Thanks, edited the post.

Update 1/6/2021 – The cat or not cat example works in Colab if the following code is NOT run.

“hide
For the book, we can’t actually click an upload button, so we fake it
uploader = SimpleNamespace(data = [‘images/chapter1_cat_example.jpg’])”

I am just getting started and I have followed the guidelines (mounting drive, followed by !curl…) but the lesson1_pets.ipynb seems to be using fastai V1 (unlike yours: from fastai2.vision.all…). This errors out help(untar_data) in the following cell.

Please see attached screenshot from Colab.

What could be the potential issue here? (same for other notebooks, all refer to from fastai V1)!

Looks like the curl command is interfering. Didn’t run after mounting Google drive.

fastai version = 1.0.61

  !curl -s https://course19.fast.ai/setup/colab | bash

I am now able to run in Colab without any issues.