I am working through the bear sample in lesson two. I am struggling with missing parts in the underlying function. Here I got stuck. Could it be a library version issue?
I am using 02_production.ipynb.
Here is the minimum code (and a colab notebook with the code) that I was able to use to create the DataLoaders
object. Note that I am using the updated DuckDuckGo Search API instead of Bing:
! pip install duckduckgo_search -Uqq
from fastdownload import download_url
from fastai.vision.all import *
from duckduckgo_search import DDGS
def search_images(term, max_images=30):
print(f"Searching for ‘{term}’")
with DDGS() as ddgs:
return L(ddgs.images(term, max_results=max_images)).itemgot('image')
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)
download_images(dest, urls=search_images(f'{o} bear photo'))
bears = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=RandomSplitter(valid_pct=0.2, seed=42),
get_y=parent_label,
item_tfms=Resize(128))
dls = bears.dataloaders(path)
dls.valid.show_batch(max_n=4, nrows=1)
Here is the output I get from dls.valid.show_batch
:
1 Like