Chapter 2 Question


I would be obliged if somebody could please explain the lines of code in the attached screenshot - I got as far as the ims command that references Should I be updating the code in that command?


Hi John,

These lines of code really just serve as an example for downloading a single image and displaying it. Step-by-step it works as follows:

  • in dest you define a path where you want to save the downloaded image
  • download_url then carries out the job of downloading the image from the url specified in ims[0] and saving the image in the path specified in dest
  • loads the image from dest into your notebook
  • and im.to_thumb(128,128) displays your image using 128x128 pixels

So if you are applying the code from chapter 2 to another dataset, you would want to show an example from your own dataset. Depending on your classes you could change the directory in dest, but otherwise the code will run as is.

Note that cell [12] is optional here. After getting your 150 image urls in cell [16], ims[0] in cell [17] will pick the first item from that list, but you could also choose any other item.

1 Like

Hi Stefan,

Thanks for the reply, it is very kind of you.

I’m new to Colab so I’m not sure where the folder is being created… any idea why I’m getting an error message? Is it related to where the file is being downloaded to?

Much appreciated.

You’re very welcome :slight_smile:

Sorry, I haven’t been working much with Colab myself. I usually work with Paperspace and GCP. But yes, my guess is that file storage works somehow differently in Colab, but I don’t know the details.

Thanks Stefan :slight_smile:

Hi John

One option would be to load your image through google drive.
To use it in your notebook, you have to first set the connection to your drive with the following:

from google.colab import drive

Then you need to set a path to your image.
For example you can change the cwd to your specific directory at the google drive:

import os
os.chdir('/content/gdrive/My Drive/YourDirectory')

Hope that helps.

Hi @stefan-ai. I am using paperspace, can you help me. The get_image_files(path) returns an empty list for me. Thanks

Hi @jbolaifa,

Hard to say just like this what’s causing the problem. It could be that your Bing Search API is not working properly (which is the most likely since many others had problems with this and I also struggled with it), or some issue regarding directories (make sure in Paperspace that all your files are saved in './storage').

But above in cell 23 I can see some saved file paths. So did it already work at some point?

Thanks, much appreciated :slight_smile: