From Model to Production - Purpose of IMS

Hi everyone, looking for a little help on understanding the code to download images

I have walked through the real book and the juypter book and this code is not working properly

# This codes run without a problem
results = search_images_ddg('grizzly bear')
ims = results.attrgot('content_url')
len(ims)


This code gives me an error

dest = 'images/grizzly.jpg'
download_url(ims[0], dest)

I guess I don’t understand what the ims = results.attrgot('content_url') is doing, when I change the code to:

results = search_images_ddg('grizzly bear')
ims = results.attrgot('content_url')
dest = 'images/grizzly.jpg'
download_url(results[0], dest)

It works, why are we using ims instead of results

In help would be greatly appreciated.

1 Like

I just rewatched the video and there is no reference to ims = results.attrgot(‘content_url’) maybe this only work if you are using the bing

What error are you getting.
Did you get the Bing API key and populate it few cell above?

If the search worked and if you print(ims), you should get a URL, something like

['http://3.bp.blogspot.com/-S1scRCkI3vY/UHzV2kucsPI/AAAAAAAAA-k/YQ5UzHEm9Ss/s1600/Grizzly%2BBear%2BWildlife.jpg']

If you don’t have a Bing API key, use the function search_images_ddg(search term) instead.
See: Downloading images | Practical Deep Learning for Coders

see: L.attrgot() for attrgot discussion

1 Like

hey,

what method are you using for IMG search? ddg_images() ? If you are using DDGs python library you will get a list of URLs and fetch the image using the key ‘image’ i.e. imgs_req.itemgot(‘image’)
attrgot is a method used by the BING library.

You must cast the List constructor helper by the fastai library to get a simple list from the ddg_image query.

example:
L(ddg_images(search_term)).itemgot(‘image’)

1 Like

Hi and thanks for your reply, the problem I was having was I was reading the search_images_bing in which references the attrgot but I was using the search_images_ddg instead which give me the results automatically like you said.

Thank you

2 Likes

Glad to be of help!

happy learning.

Thanks for your response …

I did not use bing I actually used DDG, I think that is the problem BIng has a property attrgot that the search_ddg does not have.

1 Like