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.