Get_image_files(path) returning empty list v2

I keep getting an empty list on the Grizzly Bear project, despite tweaking my code to take into account this prior thread on the subject. Does anyone know what I might be doing wrong?

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

if not path.exists():
    path.mkdir()
    for o in bear_types:
        dest = (path/o)
        dest.mkdir(exist_ok=True)
        results = search_images_ddg(f'{o} bear')
        download_images(dest, urls=results.attrgot('contentUrl'))

fns = get_image_files(path)
fns

This returns: (#0) []

Thank you for any guidance

4 Likes

Have you verified which lines of your code are actually being executed? Its about time I learnt to use the python debugger in jupyter, but in the meantime you can do it the older fashioned way…

if not path.exists():
    print("GOT HERE")
    path.mkdir()
    for o in bear_types:
        print("PROCESSING: ", o)
...etc
2 Likes

had the same problem (using Colab to run) this seemed to work
Screenshot from 2022-09-16 12-08-47

2 Likes

if you are still looking for something on this, here is a starting point (radek’s tweet)-

this ^ is helpful after you get an exception to poke around
But if you want to step through your code checkout %%debug :slight_smile:

1 Like

Had the same problem, this worked for me. Thanks!

Code:
if not path.exists():
path.mkdir()
print(path)

for o in bear_types:
print(True)
dest = (path/o)
dest.mkdir(exist_ok=True)
results = search_images_ddg(f’{o} bear’) #Note: changed to search_images_ddg as of the 2022 videos
download_images(dest, urls=results) #Note: updates urls=results.attrgot(‘contentUrl’) => results

How did you go with this? I got pulled back to this thread by another post, and as pointed out by @jjeria and @jdvaugha, attrgot was required with Bing search, but not DDG search.

It seems like you are using ddg_search.
In this case you should use:
download_images(dest, urls=results)
instead of:
download_images(dest, urls=results.attrgot('contentUrl'))

I hope it will be helpful

1 Like