Downloading images from links contained in .csv file

I have a bit of a problem here. I want to make a classifier that can distinguish different types of motorbikes. Just some exercise to practice things from lesson 2. So I scraped some links from google images and saved them as .csv file.
And here is my question - how can I download those images using download_images()?
I have specified my destination and my file name:
download_images(dest = '/content/drive/My Drive/racers', url_file= '/content/drive/My Drive/motorbikes.csv')
and I get error like this:
'str' object has no attribute 'read'
It’s probably an easy fix but I’m stuck here :stuck_out_tongue:


Hi Lucas.J hope all is well!

It looks like you may have placed an ‘=’ sign where there should be a ‘,’ so you have assigned a string to variable dest.

e.g. is what is used in notebook 2
download_images(dest, urls=results.attrgot('content_url'))

Changing this will hopefully solve your problem.

Cheers mrfabulous1 :smiley: :smiley:

It didn’t :confused:
I’m confused about attrgot(). I don’t really know what is does and couldn’t find anything about it in documentation or about download_images() in general.
Can you explain this or point me in the right direction?

Hi Lucas.J hope all is well!

The command in the previous post was not for you to replace your command but is the example from notebook2 showing a “,” where you have an = sign.

You you should change your command to the one below:

download_images(dest, url_file= '/content/drive/My Drive/motorbikes.csv')

If you read the documentation you have to declare dest as a path not a string, before you run download_images().

In notebook 2 the path is created in the following section.

bear_types = 'grizzly','black','teddy'
path = Path('bears')

if not path.exists():
    for o in bear_types:
        dest = (path/o)

With out seeing your code its difficult to know what to set your path but if you ammend/use the code above so maybe bears becomes motor bikes and grizzly say kawasaki etc this should work.

If you actually complete the bear example first, then to change it to a bike classifier this becomes easy.

Cheers mrfabuluous1 :smiley: :smiley:

1 Like

Obliged to have this information here. I was searching for this!

There’s a tool name ImgDownloader that you might need to check if it solves your issue. I’m personally using this web-based tool and It’s working fine for me.