Lesson1 - dls is getting the images miscategorized

This is my homework. Basically the same as lesson1 but with four types of images. I also did some of the code differently but I don’t think that affects my problem. lesson1 hw - dolphin whale manatees | Kaggle

Look at block 71. It has the images labeled wrong. My first thought was that duckduckgo was returning bad data. But when I did a search in my browser everything look kosher. Any ideas what is going on?
Output of block 71 with dls

Why do you think this is happening? Also, is there a way to browse the HDD and see the downloaded images?

The problem is not within the DataBlock / DataLoader, but in the function that you defined to download the images. This is you function:

image_gens=[dolphins, whales, manatees, turtles]
searches = 'dolphin', 'whale', 'manatee','turtle'
path = Path('training_images')

for category in searches:
    dest = (path/category)
    dest.mkdir(exist_ok=True, parents=True)
    for gen in image_gens:
        download_images(dest, urls=get_n_urls(gen, 50))
    resize_images(path/category, max_size=400, dest=path/category)

The first for loop iterates over all the search terms. But inside that for loop, you iterate over all images again, instead of just picking the ones that fit to the currently iterated search term. This means, that you download all the images into all folders and therefore the chance of the correct image being displayed is 1/4. To correct this, you should remove the inner for loop and fix it up like that:

image_gens=[dolphins, whales, manatees, turtles]
searches = 'dolphin', 'whale', 'manatee','turtle'
path = Path('training_images')

for i, category in enumerate(searches):
    dest = (path/category)
    dest.mkdir(exist_ok=True, parents=True)
    download_images(dest, urls=get_n_urls(image_gens[i], 50))
    resize_images(path/category, max_size=400, dest=path/category)

You can also browse all files on the disk in Kaggle, if you open the sidebar and check the data column, as shown on the right in this screenshot:

Good luck on your homework.

1 Like