Hi guys,
I’m trying to build a plant classifier. From Wikipedia, I got a list of plants and they latin names and was trying to build upon the example in lesson 1 to create the classifier.
However, on certain plant names, I’m getting a KeyError during the download_images execution:
import shutil
path = Path('OregonPlants')
def search_to_folder(x): return '_'.join(x.split(' ')[-2:])
for o in search_terms:
dnld = (path/'dnld')
dest = (path/search_to_folder(o))
dnld.mkdir(exist_ok=True, parents=True)
dest.mkdir(exist_ok=True, parents=True)
print(o)
download_images(dnld, urls=search_images(f'{o} photo'), max_pics=20)
resize_images(dnld, max_size=400, dest=dest)
shutil.rmtree(dnld)
and get the following output:
Vaccinium ovalifolium Alaska blueberry
Daucus pusillus American wild
Melica aristata Awned melic
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Input In [37], in <cell line: 7>()
11 dest.mkdir(exist_ok=True, parents=True)
12 print(o)
---> 13 download_images(dnld, urls=search_images(f'{o} photo'), max_pics=20)
14 resize_images(dnld, max_size=400, dest=dest)
15 shutil.rmtree(dnld)
Input In [14], in search_images(term, max_images)
12 data = urljson(requestUrl,data=params)
13 urls.update(L(data['results']).itemgot('image'))
---> 14 requestUrl = url + data['next']
15 time.sleep(0.2)
16 return L(urls)[:max_images]
KeyError: 'next'
I haven’t changed the function download_images
from the notebook, but it seems to get hung up on specific examples. Any ideas what could be happening? A quick manual search on ddg for the term where I get the error shows plenty of image results for the string.