Lesson 2: 'NoneType' object is not iterable

when entering the below code,
dls = bears.dataloaders(path)

I receive the error message: ‘NoneType’ object is not iterable. What should I do?

Hi Sarrah,

I hesitate to offer advice as I’m very new to DL/coding! I had a similar issue which was caused by my path object not set-up correctly (backslash v forward slash).

Hopefully that helps?

Hi Troy, thanks so much for replying! Totally new to DL & coding too so I really appreciate the help. What path object are you referring to? Is it in the code snippet attached above or somewhere on top?

I tried adding a backslash here but ended up with an error.

I didn’t use that code as had issues with Azure keys so used duckduckgo image downloader which dropped images into a file structure directly. Probably means I’m likely to mislead you!

It should be forward slash so sorry for distracting you.
Is your path object unchanged:
bear_types = ‘grizzly’,‘black’,‘teddy’
path = Path(‘bears’)

The error message here is not exactly obvious. After some debugging, I realised it comes from having 0 (zero) items in the source, maybe because the path is not correct.

You can inspect if this is the case by passing the verbose=True parameter:

dls = bears.dataloaders(path, verbose=True)

I`m having the same issue. On further inspection it seemed that that the following block didn’t download any pictures (it just created the folders). So I assume that caused the bug in the code. (iterating over an empty list?)
Question now is, how to make it download the bear pictures in the first place?

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

Yes, Oliver. I have the same issue and found that the images were not downloaded in the first place. That is, ‘fns’ is empty.
So, the lecture was filmed last year and MS might have changed how they provided free services (I had a hard time finding the API key but managed to do it reading other replies down in the thread). In short, images are not downloaded when you iterate three bears instantly using the ‘for’ loop. It seems to cause an overload issue for a free account.
Instead, we should put codes one by one in each cell.

dest=(path/‘grizzly’)

dest.mkdir(exist_ok=True)

results = search_images_bing(key, ‘grizzly bear’)

download_images(dest, urls=results.attrgot(‘contentUrl’))

then in the next cell

dest=(path/‘black’)

dest.mkdir(exist_ok=True)

results = search_images_bing(key, ‘black bear’)

download_images(dest, urls=results.attrgot(‘contentUrl’))

In the last cell,

dest=(path/‘teddy’)

dest.mkdir(exist_ok=True)

results = search_images_bing(key, ‘teddy bear’)

download_images(dest, urls=results.attrgot(‘contentUrl’))

You see it will take some time running each cell, which means the code is actually working.
Hope this helps.

Hi,

It seems the problem was solved by upgrading to the latest version of FastAI, 2.5.2 , as there was a bug in the download_images() function in 2.5.0.

And indeed the code as in Chapter 2 is now running well and downloading the actual pictures

Wow. Has Jeremy looked into this and updated fast.ai? The original code did not work last night, but now does. I did not check the version last night, but the current one is 2.5.2 as you mention, and it works well now. Thanks!

Thats great!
No, fastai version 2.5.2 worked already. I was running a server on Jarvislabs.ai and they updated now to the lastest version of Fastai.
Good luck!