(This blog post implements the concepts illustrated in my previous post, "Typical (Neural-Network-Based) Classification vs. Zero-Shot, Part 1 - The Joy of 3D". Note that the "3D" part was because of its utility as a teaching tool for gaining intuition; realistic applications usually involve hundreds of "dimensions.")

Intro

In Part 1, I described how contrastive loss-based "metric learning" methods are similar to and different from traditional "one-hot" neural network classifiers in a few ways: similar in that both types of methods can be viewed as embedding methods (not just metric learning), different in that the latter involve a fixed set of classes, whereas the former rely on a similarity measure.

Confession: I didn't fully disclose my motivation last time: I simply got sick of not knowing what "contrastive losses" meant in many important paper titles -- notably OpenAI's "CLIP" and Eduardo Fonseca et al's "Unsupervised Contrastive Learning of Sound Event Representations" -- and decided "I need to learn this."And (as one often finds in the rapidly-advancing and fragmented world of ML) it turned out I already knew what contrastive losses and metric learning were (e.g., I took a 4-course NLP Specialization last year!), just not by those names. So hey, I might actually be qualified to teach on this after all! ;-) Ok, enough with the autobiography.

Here's an annotated outline of the sections of this post:

  1. Traditional One-Hot Classification Demo, using 3 and 4 classes. We'll be following Jeremy Howard and Sylvain Guggers's "bears" example from Chapter 2 of the fastai book. But we'll focus on concepts and outcomes, saving FastAI details for Section 4
  2. Contrastive Loss Demo using the same data as as Section 1.
  3. Discussion
  4. FastAI Details, including "how I learned to write my own Callback" for progress-tracking and data visualization. Note that these coding details will be present earlier in the post and viewable via the "Display Code" buttons, but the explanations of the code won't appear until Section 4.

1. Traditional One-Hot Classification Demo: Three (and 4) Types of Bears

We could do the "cats vs. dogs vs. horses" example from the previous Part 1 post, but it turns out that because we're going to do Transfer Learning using a model pre-trained on ImageNet (which already has categories for cats, dogs, and horses), it's too easy to even see anything "interesting" happen! I want to be able to show you "dots moving around" as the model trains.

Instead, we'll copy Jeremy Howard...

Aside:"We'll copy Jeremy Howard" is something more members the ML community could probably stand to do, or admit they're doing.

...and do three types of bears: grizzly, brown, and teddy. ;-) And then later we'll throw in one more "natural kind" of bear. ;-)

Scraping for Images

Using the DuckDuckGo API, let's grab ~100 images of each kind of bear.

def scrape_for_me(dl_path, labels, search_suffix, erase_dir=True, max_n=100):
    if erase_dir:
        !rm -rf {dl_path}           # clear out last time's downloads
    path = Path(dl_path)
    if not path.exists(): path.mkdir()
    for o in labels:            # scrape images off the web
        search_term = (f'{o} {search_suffix}').strip()
        dest = (path/o)
        dest.mkdir(exist_ok=True)
        urls = search_images_ddg(f'{search_term}', max_n=max_n) 
        urls = [ x for x in urls if ("magpies" not in x) and ("charliebears" not in x) ]   # kludge for now to keep download_images from hanging
        print(f"{search_term}: Got {len(urls)} image URLs. Downloading...")
        print("   urls = ",urls)
        download_images(dest, urls=urls, preserve_filename=False)
        print("    Images downloaded.")
        
    fns = get_image_files(path)     # list image filenames
    failed = verify_images(fns)     # check if any are unloadable

    # remove what's unloadable
    failed.map(Path.unlink);
    if failed != []:
        _ = [fns.remove(f) for f in failed]

    # Extra: To avoid Transparency warnings, convert PNG images to RGBA, from https://forums.fast.ai/t/errors-when-training-the-bear-image-classification-model/83422/9
    converted = L()
    for image in fns:
        if '.png' in str(image):
            im = Image.open(image)
            converted.append(image)  # old file name before resaving
            im.convert("RGBA").save(f"{image}2.png")    
    converted.map(Path.unlink); # delete originals
    print(f"After checking images for issues, {len(get_image_files(path))} (total) images remain.")
    return path     # and return a pathlib object pointing to image dir
dl_path = 'scraped_images'  # where we're saving to
labels = 'grizzly','black','teddy'  
search_suffix = 'bear'
path = scrape_for_me(dl_path, labels, search_suffix, max_n=100)
grizzly bear: Got 100 image URLs. Downloading...
   urls =  ['https://i0.wp.com/www.commonsenseevaluation.com/wp-content/uploads/2013/08/Bear.jpg', 'https://www.conservationnw.org/wp-content/uploads/2017/06/Grizzly-bear-family-Copyright-iStock.com_PhotosbyAndy-4.2015-e1507229404830.jpg', 'https://images.fineartamerica.com/images-medium-large/grizzly-bear-portrait-jim-guy.jpg', 'https://www.mtpr.org/sites/kufm/files/styles/x_large/public/201809/grizzly-bear-02_Istock.jpg', 'https://a57.foxnews.com/a57.foxnews.com/static.foxnews.com/foxnews.com/content/uploads/2018/09/640/320/1862/1048/Grizzly-iStock.jpg?ve=1&tl=1?ve=1&tl=1', 'https://wallsdesk.com/wp-content/uploads/2017/01/Grizzly-Bear-Desktop-Wallpaper-.jpg', 'https://www.mtpr.org/sites/kufm/files/styles/x_large/public/201812/Grizzly-bear-family_LuCaAr-iStock.jpg', 'https://www.unilad.co.uk/wp-content/uploads/2020/02/close-up-photography-of-grizzly-bear-1068554.jpg', 'https://reidparkzoo.org/wp-content/uploads/2013/09/grzbear2812a.jpg', 'https://outsider.com/wp-content/uploads/2020/06/Grizzly-Bear-3.png', 'https://www.livewaterjacksonhole.com/wp-content/uploads/2020/06/Grizzly-399-Grand-Teton-National-Park.jpg', 'https://i0.wp.com/rangerrick.org/wp-content/uploads/2018/04/RRMAR13_6-11Grizzlies.jpg?fit=1156%2C650&ssl=1', 'https://www.vmcdn.ca/f/files/rmotoday/images/grizzly122_kalra.jpg;w=960', 'https://www.gannett-cdn.com/presto/2020/07/21/PGRF/83612915-6ab2-4f0d-aeca-7088f219ecec-AP20191697142470.jpg?crop=2999,1687,x0,y0&width=2999&height=1687&format=pjpg&auto=webp', 'https://www.tsln.com/wp-content/uploads/2018/10/bears-tsln-101318-3-1240x826.jpg', 'https://cdn.rbth.com/980x-/all/2016/10/07/grizzly_gettyimages-10188130_b.jpg', 'http://mediad.publicbroadcasting.net/p/kufm/files/styles/x_large/public/201603/grizzly-bear_Nathan-Rupert-CC-BY-NC-ND_0.jpg', 'http://www.akronzoo.org/Data/Sites/1/media/GalleryImages/105/WebImages/grizzly-bear-hero-1.jpg', 'http://wallup.net/wp-content/uploads/2016/01/139369-bears-nature-animals-river-baby_animals-Grizzly_Bears-Grizzly_bear.jpg', 'https://1.bp.blogspot.com/-l-Y6zD_KF6o/UQN3jPgigAI/AAAAAAAAFcU/HOKJWQmNjo4/s1600/Grizzly+Bear-2013-0pic-05.jpg', 'https://www.conservationnw.org/wp-content/uploads/2017/10/grizzly-bears-1280x950.jpg', 'https://s1.it.atcdn.net/wp-content/uploads/2013/07/Grizzly-bear.jpg', 'https://gohunt-assets-us-west-2.s3.amazonaws.com/wyoming-grizzly-bear-og_0.jpg', 'https://www.wildernesscommittee.org/sites/default/files/2018-05/grizzly_bear.jpg', 'http://www.wyofile.com/wp-content/uploads/2017/11/grizzly-pic-e1509641980482.jpg', 'http://averageoutdoorsman.com/wp-content/uploads/2013/02/grizzly-bear.jpg', 'https://www.publicdomainpictures.net/pictures/90000/velka/grizzly-bear-portrait.jpg', 'https://www.vancouverobserver.com/sites/vancouverobserver.com/files/images/article/body/grouse-grizzly_n3d3306-web.jpg', 'https://www.columbiatribune.com/storyimage/MO/20171003/NEWS/171009653/AR/0/AR-171009653.jpg', 'https://images.wallpapersden.com/image/download/bear-grizzly-bear-eyes_amhrZ5SZmpqtpaSklGZuZ2WtZmVtZQ.jpg', 'https://devdenverzoo.com/wp-content/uploads/2018/09/Grizzly-Bear_05.jpg', 'https://www.conservationnw.org/wp-content/uploads/2020/03/JSW_6993-scaled.jpg', 'https://outsider.com/wp-content/uploads/2020/07/Grizzly-Bear.png', 'https://2.bp.blogspot.com/-p-QKKk3T8O0/UQN3a5YSALI/AAAAAAAAFcE/iTlNg3jee9A/s1600/Grizzly+Bear-2013-0pic-03.jpg', 'https://wildlifeimages.org/wp-content/uploads/2016/09/DSC1704.jpg', 'https://img.theculturetrip.com/1440x807/wp-content/uploads/2018/01/carnivore-nature-wild-alaska-wildlife-grizzly-bear-861962.jpg', 'https://blog.humanesociety.org/wp-content/uploads/2020/07/grizzly-bear-iStock-647126690_369827.jpg', 'https://wallsdesk.com/wp-content/uploads/2017/01/Grizzly-Bear-for-desktop-background.jpg', 'https://gephardtdaily.com/wp-content/uploads/2015/08/11754872_1109393535742666_5103459483633495575_o.jpg', 'http://www.outdoorhub.com/wp-content/uploads/sites/2/2015/08/outdoorhub-yellowstone-grizzly-bear-kills-hiker-in-apparent-predatory-attack-2015-08-12_15-18-35.jpg', 'https://www.rmef.org/wp-content/uploads/2020/05/wyoming-grizzly-bear.jpg', 'http://calgaryguardian.com/wp-content/uploads/2017/05/142_1289.jpg', 'http://www.publicdomainpictures.net/pictures/90000/velka/grizzly-bear-profile.jpg', 'https://wallpapertag.com/wallpaper/full/e/b/8/437151-grizzly-bear-backgrounds-2560x1600-for-tablet.jpg', 'https://external-preview.redd.it/bccjV-0WX40IgFdJ1FOy7_IE9nLPXR0wloCap7hXTSA.jpg?auto=webp&s=a17fd3832e57032a5b44af94010a189e4e906ea6', 'https://outsider.com/wp-content/uploads/2020/08/grizzly-bear-hiker-glacier-national-park-video.png', 'https://i.cbc.ca/1.4174820.1506608673!/fileImage/httpImage/image.jpg_gen/derivatives/16x9_1180/grizzly-glares-at-viewer.jpg', 'https://wallsdesk.com/wp-content/uploads/2017/01/Grizzly-Bear-Wallpapers-HD.jpg', 'https://cdn.britannica.com/19/186719-050-887A6F2C/Grizzly-bear-Rocky-Mountains-Wyoming.jpg', 'http://www.pbs.org/wnet/nature/files/2018/07/Bear133.jpg', 'http://1.bp.blogspot.com/-CoOIzMhLQUI/UHzVx6IxyVI/AAAAAAAAA-c/RHMhnAXXniU/s1600/Grizzly+Bear+Sleepy.jpg', 'http://www.photos-public-domain.com/wp-content/uploads/2012/03/grizzly-bear.jpg', 'http://img.huffingtonpost.com/asset/1910_1000/58c0a5fe1d000027007cd5c0.jpg', 'http://blog.theclymb.com/wp-content/uploads/2014/09/angry-grizzly-bear.jpg', 'https://wallsdesk.com/wp-content/uploads/2017/01/Grizzly-Bear-Background-.jpg', 'https://devdenverzoo.com/wp-content/uploads/2018/09/Grizzly-Bear_04.jpg', 'http://www.montanaoutdoor.com/wp-content/uploads/2018/02/Grizzly-King-FEAT.jpg', 'http://www.wallpapergeeks.com/wp-content/uploads/2014/03/Grizzly-Bear-Near-McNeil-River-Alaska.jpg', 'https://cottagelife.com/wp-content/uploads/2020/07/shutterstock_546562111.jpg', 'https://redtri.com/wp-content/uploads/2014/07/grizzly-bear-2.jpg', 'https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/grizzly-bear-twenty-two-north-photography.jpg', 'http://www.marketwire.com/library/MwGo/2017/3/7/11G132324/Images/3_Bears_Approach_by_Jim_Lawrence-4f4d16b51311853286570ff0d3022a81.jpg', 'https://s3-assets.eastidahonews.com/wp-content/uploads/2015/10/03030033/0ad8593723.jpg', 'https://www.alloutdoor.com/wp-content/uploads/2019/08/Grizzly_Bear_Ursus_arctos_ssp..jpg', 'http://www.cs.columbia.edu/~sedwards/photos/kyle200604/20060412-7108%20Grizzly%20bear.jpg', 'http://2.bp.blogspot.com/-NjMTuklENdE/UHzVv_8dIxI/AAAAAAAAA-U/tNBsQDn8kFI/s1600/Grizzly+Bear+Pic.jpg', 'https://live.staticflickr.com/8078/8277276763_b4d8cff511_b.jpg', 'http://images.fineartamerica.com/images-medium-large/1-grizzly-bear-yukon-robert-postma.jpg', 'http://bloximages.newyork1.vip.townnews.com/stltoday.com/content/tncms/assets/v3/editorial/b/99/b99156d5-0ad8-5b5c-a98a-d805c9a5d6bb/57eaaca236063.image.jpg?resize=1200%2C1369', 'https://media.salon.com/2014/03/Grizzly-Bear.jpg', 'https://d3d0lqu00lnqvz.cloudfront.net/media/media/897b2e5d-6d4c-40fa-bbe8-6829455747e2.jpg', 'https://www.naturalworldsafaris.com/~/media/images/blogs/2018/01/grizzly-bear-hunting-ban/mmr_2015-08-06_7055.jpg', 'https://www.readersdigest.ca/wp-content/uploads/2018/09/grizzly-bear-cub.jpg', 'http://2.bp.blogspot.com/-9JAlJayP2XU/UQN3Wffpa8I/AAAAAAAAFbs/eMP5BcuLetc/w1200-h630-p-k-nu/Grizzly+Bear-2013-0pic-02.jpg', 'https://townsquare.media/site/99/files/2018/12/Bear.jpg?w=1200&h=0&zc=1&s=0&a=t&q=89', 'https://s3.amazonaws.com/images.gearjunkie.com/uploads/2015/07/Grizzly-Bear.jpg', 'https://wildlifefriendly.org/wp-content/uploads/2015/09/Grizzly.jpg', 'https://www.thefencepost.com/wp-content/uploads/sites/12/2018/08/grizzlies-tsln-081118-1240x828.jpg', 'https://wallsdesk.com/wp-content/uploads/2017/01/Grizzly-Bear-Download.jpg', 'http://4.bp.blogspot.com/-QmwOWiR3ydM/USOj4DBjZSI/AAAAAAAAFBM/bvX4-MmH-tY/s1600/Grizzly_Bear_Info_Images+08.jpg', 'https://www.huntingillustrated.com/wp-content/uploads/2014/03/Depositphotos_93855856_xl-2015-1-scaled.jpg', 'http://media1.s-nbcnews.com/j/newscms/2017_07/1905761/170217-grizzly-alaska-mn-1130_e938eae58cdfe33a8c5bd9af07356dd9.nbcnews-ux-2880-1000.jpg', 'https://s1.ibtimes.com/sites/www.ibtimes.com/files/styles/embed/public/2017/11/20/grizzly-bear.jpg', 'http://mediad.publicbroadcasting.net/p/kufm/files/styles/x_large/public/201606/grizzly_PD.jpg', 'https://i1.wp.com/backcountryjourneys.com/wp-content/uploads/2015/12/bigstock-Grizzly-Bear-9532331.jpg', 'https://detroitzoo.org/wp-content/uploads/2015/08/Grizzly-Boys.jpg', 'https://cdn0.wideopenspaces.com/wp-content/uploads/2020/04/whatdogrizzlybearseat4-scaled.jpg', 'https://s3-assets.eastidahonews.com/wp-content/uploads/2019/05/06175149/grizzly-bear-860x571.jpg', 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/GrizzlyBearJeanBeaufort.jpg/1200px-GrizzlyBearJeanBeaufort.jpg', 'https://i2.wp.com/nypost.com/wp-content/uploads/sites/2/2020/09/grizzly-bear-89.jpg?quality=90&strip=all&ssl=1', 'https://davidsuzuki.org/wp-content/uploads/2017/04/grizzly-bears-alaska-wildlife-sanctuary-whittier.jpg', 'https://www.campbellriver.travel/media/2020/02/bear-ears1.jpg', 'http://static.independent.co.uk/s3fs-public/thumbnails/image/2016/06/30/08/yellowstone-grizzly-bear-.jpg', 'https://www.vmcdn.ca/f/files/via/import/2018/07/08143100_grizzly-bear.jpg;w=960', 'https://wyo4news.com/wp-content/uploads/2020/07/grizzly-bear.jpg', 'https://bozone.com/site/wp-content/uploads/2019/03/GRIZZLY.jpeg', 'http://www.news1130.com/wp-content/blogs.dir/sites/9/2015/09/17/iStock_000010656016_Double-e1442507974878.jpg', 'https://tetonvalleylodge.com/wp-content/uploads/2015/04/grizzly-bear-idaho.jpg', 'https://gohunt-assets-us-west-2.s3.amazonaws.com/Grizzly-bear-protections-west-OG.jpg', 'https://www.the-sun.com/wp-content/uploads/sites/6/2020/09/NINTCHDBPICT000512282491.jpg?strip=all&quality=100&w=1200&h=800&crop=1']
    Images downloaded.
black bear: Got 100 image URLs. Downloading...
   urls =  ['https://scx2.b-cdn.net/gfx/news/hires/2019/blackbear.jpg', 'https://www.seacoastonline.com/storyimage/SO/20190730/NEWS/190739992/AR/0/AR-190739992.jpg', 'https://wallup.net/wp-content/uploads/2019/09/719345-baribal-black-bear-bear-muzzle-eyes-predator.jpg', 'http://www.stgeorgeutah.com/wp-content/uploads/2015/11/lynn_11-22-2011_black_bear_1.jpg', 'http://bearsmartdurango.org/wp-content/uploads/2013/06/100_0642.jpg', 'http://naturalbridgezoo.com/wp-content/uploads/2017/05/BB1-1.jpg', 'http://grizzlybearwatching.com/wp-content/uploads/2017/03/BlackBear1-1500x998.jpg', 'http://cdn-image.travelandleisure.com/sites/default/files/styles/1600x1000/public/1522685410/black-bear-BEAR418.jpg?itok=qmoXuFRx', 'http://infotel.ca/news/medialibrary/image/orig-mediaitemid22167-3862.jpg', 'https://www.vpr.org/sites/vpr/files/styles/x_large/public/202007/black-bear-fish-wildlife-dept-Tom-Rogers-2013.png', 'http://www.mountaincountrycabinrentals.com/wp-content/uploads/2014/10/Closeup-of-a-black-bear.jpg', 'https://www.gulflive.com/resizer/XxMMGfEvOQQAVOEKfieknpQOIv8=/1280x0/smart/advancelocal-adapter-image-uploads.s3.amazonaws.com/image.gulflive.com/home/gulf-media/width2048/img/news_impact/photo/bears-threatened-fbdfb579fa67c166.jpg', 'https://wildlife.utah.gov/news_photos/11-18-19_black-bear-in-grass.jpg', 'https://www.piecebypiece.ca/wp-content/uploads/2018/05/165-Black-Bear-Cub.jpg', 'https://www.greatswamp.org/wp-content/uploads/2016/01/black-bear.jpg', 'https://beartrackoutfitters.com/wp-content/uploads/2018/09/bear.jpg', 'http://justfunfacts.com/wp-content/uploads/2017/02/american-black-bear-smell.jpg', 'http://snowbrains.com/wp-content/uploads/2015/08/American-Black-Bear-jpg.jpg', 'https://media-cdn.wehco.com/img/photos/2020/12/11/blackbearnoppers06cmykoriginal1483610356_t1070_h5b279ad6a60bb8d6261090d0367921ea9d3e0cc8.jpg', 'https://www.gannett-cdn.com/-mm-/ba9293e2ff57f90c5ea896bbb7fb36126f38dbc9/c=0-134-3468-2093/local/-/media/2016/06/28/CNYGroup/Elmira/636027114617396897-black-bear.jpg?width=3200&height=1680&fit=crop', 'https://bearexpert.com/wp-content/uploads/2019/10/american-black-bear.jpg', 'https://www.gannett-cdn.com/-mm-/cd26c8713e884a8483a3eb4efd7e9b47f526e46d/c=0-264-4620-2863/local/-/media/Bridgewater/2015/01/05/B9315749966Z.1_20150105153333_000_GUS9JJHMR.1-0.jpg?width=3200&height=1680&fit=crop', 'https://texnat.tamu.edu/files/2018/07/IMG_1573.jpg', 'https://photos1.blogger.com/blogger/5712/2802/1600/DSC01502.jpg', 'https://img1-azrcdn.newser.com/image/1255962-12-20190904134100.jpeg', 'https://www.gravel.org/wp-content/uploads/2015/10/Black-Bear.jpg', 'https://www.crozetgazette.com/wp-content/uploads/2018/06/iStock-153562011.jpg', 'https://images.thestar.com/-S-RKsYxNaEcCX0LRaqhNeLpMAs=/1200x932/smart/filters:cb(1565190981014)/https://www.thestar.com/content/dam/thestar/vancouver/2019/08/06/child-injured-by-bear-bite-at-greater-vancouver-zoo-officials-say/blackbear.jpg', 'https://seniors101.ca/wp-content/uploads/2015/08/Black-bear-cub.jpg', 'https://www.koamnewsnow.com/content/uploads/2020/05/pixabay-black-bear.jpg', 'https://www.gannett-cdn.com/-mm-/40756a948d5a0edcc7ce6d0e16b133540995c9c8/c=0-138-1997-1266/local/-/media/2017/03/06/JacksonMS/JacksonMS/636243918786987260-0307bear01.jpg?width=3200&height=1680&fit=crop', 'https://img.huffingtonpost.com/asset/5d71a56a2500007a1205d0b4.jpeg?cache=i3bilfyydx&ops=1778_1000', 'http://i.huffpost.com/gen/1105509/images/o-MARYLAND-BLACK-BEAR-facebook.jpg', 'http://justfunfacts.com/wp-content/uploads/2017/02/black-bear.jpg', 'https://blog.humanesociety.org/wp-content/uploads/2016/06/BLACK-BEAR-ISTOCK_000046186676_288801-1220x813.jpg', 'https://aldf.org/wp-content/uploads/2018/05/blackbear-121274561-16x9.jpg', 'http://blog.healthywildlife.ca/wp-content/uploads/2016/07/black-bear-hg-1-of-1.jpg', 'http://snowbrains.com/wp-content/uploads/2015/08/connie-lemperle-black-bear-web.jpg', 'https://detroit.cbslocal.com/wp-content/uploads/sites/15909782/2015/05/black-bear-forest.jpg?w=1500', 'https://floridablackbearscenicbyway.org/wp-content/uploads/2020/02/2411420-1920x1080-DesktopNexus.com_.jpg', 'https://storage.googleapis.com/afs-prod/media/media:c1a9aa6b7050465d83977305953495aa/3000.jpeg', 'https://canadaintherough.com/wp-content/uploads/2020/06/blackbear.jpg', 'https://images.dailyhive.com/20190916163711/North-Shore-Black-Bear-Society.jpg', 'https://s29027.pcdn.co/wp-content/uploads/2019/08/Black-Bear-mating-Tekiela-TEK1811.jpg', 'https://www.thehuntingpage.com/wp-content/uploads/sites/2/2014/01/o-BLACK-BEAR-facebook.jpg', 'https://www.transylvaniatimes.com/home/cms_data/dfault/photos/stories/id/9/1/41091/s_top', 'https://mediad.publicbroadcasting.net/p/wvtf/files/styles/x_large/public/201607/AP_608334627084.jpg', 'https://gothunts.com/wp-content/uploads/2019/06/Black-Bear-scaled.jpeg', 'http://2.bp.blogspot.com/-oL5wK6KYI7M/UBji1ikDXXI/AAAAAAAAAMY/jmXUpXVGet4/s1600/Black-Bear-05.jpg', 'http://2.bp.blogspot.com/_1N1pZVb1_C4/TUCDn6EEngI/AAAAAAAABVA/h6BmG9TLADA/s1600/Black+Bear+159087.jpg', 'http://someinterestingfacts.net/wp-content/uploads/2016/07/Black-bear.jpg', 'https://animalhype.com/wp-content/uploads/2019/12/How-Fast-Do-Black-Bears-Run-1024x682.jpg', 'http://uffmannatureimages.net/wp-content/uploads/2012/07/20120519-_Q2C6428Black-Bears-save-for-web-cs6.jpg', 'https://wildlife.org/wp-content/uploads/2015/07/Black-Bear-Reintroduction-Image-1-600.jpg', 'http://archery360.com/wp-content/uploads/2014/06/black-bear-cub.jpg', 'https://cdn.extra.ie/wp-content/uploads/2018/05/15124559/Black-bear-1.jpg', 'https://mediad.publicbroadcasting.net/p/wusf/files/styles/x_large/public/201504/black_bear_closeup_gary_langley.jpg', 'https://bearexpert.com/wp-content/uploads/2020/08/american-black-bear-6.jpg', 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/2015-08-07_Black_Bear_near_Stewart%2C_BC_1090.jpg/1280px-2015-08-07_Black_Bear_near_Stewart%2C_BC_1090.jpg', 'http://www.adirondackalmanack.com/wp-content/uploads/2017/05/blackbear.jpg', 'http://strangesounds.org/wp-content/uploads/2014/08/bear-cubs-photo.jpg', 'https://bear.org/wp-content/uploads/2017/10/Serious-Bear.jpg', 'https://thelaurelofasheville.com/wp-content/uploads/2016/06/Carolina_Nature_Photographers_Association-Black_Bear-6.jpg', 'https://yukon.ca/sites/yukon.ca/files/env/env-imgs/env-black-bear_0.jpg', 'https://media.spokesman.com/photos/2017/07/04/BLACK_BEAR.JPG.jpg', 'https://wallup.net/wp-content/uploads/2019/09/300546-minnesota-black-bear.jpg', 'https://cdn1.theweek.co.uk/sites/theweek/files/2016/10/161026_black_bear.jpg', 'https://bloximages.newyork1.vip.townnews.com/swnewsmedia.com/content/tncms/assets/v3/editorial/7/1a/71a9b7ca-1825-5fdd-9534-5a7c30ac10c8/5d444ec6ac2d5.image.jpg', 'https://www.raincoast.org/wp-content/uploads/2019/12/black-bear-diane-bb-v1.1.jpg', 'http://2.bp.blogspot.com/-yc7X_uO7iMM/UA7U_q5_NtI/AAAAAAAAAqI/72EaqVglzPM/s1600/black-bear.jpg', 'http://wyrz.org/wp-content/uploads/2016/07/black_bear.jpg', 'https://www.gannett-cdn.com/-mm-/98e9eb0055148d8550b3a7d264f19fd6462e6062/c=0-213-4288-2636/local/-/media/2017/03/22/CarolinaGroup/Asheville/636257813777562324-Black-bear-Getty-images.jpg?width=3200&height=1680&fit=crop', 'https://floridawildlifefederation.org/wp-content/uploads/2020/04/black-bear-scaled-e1598566846480.jpg', 'https://bento.cdn.pbs.org/hostedbento-prod/gallery/20170713_222850_315402black-bear-01-gettyimages-155467721.jpg.1280x720_q85.jpg', 'http://wallpapersdsc.net/wp-content/uploads/2017/10/Black-Bear-Background.jpg', 'https://www.gannett-cdn.com/-mm-/2b06f05d8e31b4112ec2ecbca6e9ef0db0cf4d0b/c=0-108-2125-1309/local/-/media/2016/05/18/Wilmington/Wilmington/635991906230694281-black-bear.jpg?width=3200&height=1680&fit=crop', 'https://www.outdoorrevival.com/wp-content/uploads/2017/04/american-black-bear.jpg', 'http://www.hww.ca/kaboom/images/Mammals/Black-Bear/Black-Bear-Elliott-Fotherby.jpg', 'https://wallpapercave.com/wp/wp3102474.jpg', 'https://www.simplemost.com/wp-content/uploads/2019/06/AdobeStock_122783246.jpeg', 'https://images.fineartamerica.com/images-medium-large-5/baby-black-bear-jack-nevitt.jpg', 'http://www.wildlifecenter.org/sites/default/files/patient_images/Black_Bear/DSCN6285.JPG', 'https://cottagelife.com/wp-content/uploads/2019/02/Cottage-Life-Black-Bear-cub.jpg', 'https://images.axios.com/WACso7e7dbhjup_i7iVfclq3BdI=/0x322:4288x2734/1920x1080/2018/05/22/1527002317479.jpg', 'https://northdakotawildlifefederation.org/wp-content/uploads/2020/02/black-bear.jpg', 'https://www.stgeorgeutah.com/wp-content/uploads/2017/01/blackbear.jpg', 'http://images.dailyhive.com/20160826144034/black-bear-e1475078273412.jpg', 'https://www.gannett-cdn.com/presto/2018/11/04/PGRF/7c692a2a-f1d1-4f07-8181-6bfc90c42b2c-AP18305732083625.jpg?crop=1999,1144,x0,y211&width=3200&height=1680&fit=bounds', 'http://1.bp.blogspot.com/-Jc2_QqcDTz4/UBjix7v9rjI/AAAAAAAAAMA/Hr67qTiw_I4/s1600/Black-Bear-02.jpg', 'http://www.exploreclarion.com/wp-content/uploads/2018/11/black-bear.png', 'https://external-preview.redd.it/ny2anVEkjB6eTawYfAN6KcZ7TUyH69buX9Vhm56cds8.jpg?auto=webp&s=500e3a52f7e797eff002fcd91f0f3cf62ff1f401', 'https://media.news4jax.com/photo/2015/11/06/Black-bear-blurb-jpg_308110_ver1.0_1280_720.jpg', 'https://globaljusticeecology.org/wp-content/uploads/black-bear-937037_1920-980x460.png', 'https://wildlifefriendly.org/wp-content/uploads/2015/09/Black-bear-Full.jpg', 'http://wiseaboutbears.org/wp-content/uploads/2014/06/bearmaleJune-222012D80_2149-copy.jpg', 'https://www.columbiatribune.com/storyimage/MO/20200519/NEWS/200519240/AR/0/AR-200519240.jpg', 'http://explorenorth.com/library/nature/images/brown_black_bear-tutshi_lake-0709.jpg', 'https://farm6.staticflickr.com/5588/15080045718_78c2561e6e_b.jpg', 'https://www.gannett-cdn.com/-mm-/a5076e7a43a0cec6129489319d0fb728e2cd1814/c=0-264-5184-3193/local/-/media/2017/06/23/PAGroup/YorkDailyRecord/636338199651309082-GettyImages-482466374.jpg?width=3200&height=1680&fit=crop', 'http://www.reportingday.com/wp-content/uploads/2018/07/Black-Bear-Cute-Pictures-1.png']
    Images downloaded.
teddy bear: Got 100 image URLs. Downloading...
   urls =  ['https://i2-prod.birminghammail.co.uk/incoming/article17583074.ece/ALTERNATES/s1227b/0_IFP_BEM_160120bears011JPG.jpg', 'http://cdn.shopify.com/s/files/1/2622/2548/products/wholesale-plush-in-a-rush-14271861817446_1200x.jpg?v=1584804420', 'https://cdn8.bigcommerce.com/s-dee9d/images/stencil/1280x1280/products/970/6782/Life_size_72in_black_teddy_bear_Juju_Cuddles_is_Tall_dark_and_adorable__95688.1463592717.jpg?c=2', 'http://www.fitzulas.com/Merchant4c/graphics/00000001/2014/gund-4040161-xl.jpg', 'https://cdn0.rubylane.com/shops/chippewalakeantiques/863.1L.jpg', 'https://www.sippycupmom.com/wp-content/uploads/2017/09/NTBD-Exclusive-Bear.jpg', 'http://theawesomedaily.com/wp-content/uploads/2017/10/teddy-bear-images-10-2.jpg', 'https://hips.hearstapps.com/vader-prod.s3.amazonaws.com/1543338622-costco-giant-teddy-bear-1543338603.jpg?crop=1xw:1xh;center,top', 'http://cdn.shopify.com/s/files/1/2610/9472/products/BL1985_BIRKIN_TEDDY_BEAR_01_1024x1024.jpg?v=1554885535', 'https://d3n8a8pro7vhmx.cloudfront.net/accessalliance/pages/454/meta_images/original/Cute_but_Lonely_Teddy_Bear_Sitting_on_Grass.jpg?1591840883', 'https://cdn.notonthehighstreet.com/fs/34/8c/3995-961a-4318-86e4-a5ee78006bf4/original_personalised-teddy-bear-gift.jpg', 'https://cdn0.rubylane.com/_pod/item/1068141/0001459/1910s-Antique-Steiff-Tiny-Teddy-Bear-pic-1-2048-50-f.jpg', 'https://cdn0.rubylane.com/_pod/item/1494839/RL446/Large-Ideal-Antique-Teddy-Bear-full-2o-2048-14-r-ffffff-9f9b7e.jpg', 'https://cdn.notonthehighstreet.com/fs/7a/fe/5bda-9f46-403c-9d21-c798fa5de5ed/original_personalised-siblings-teddy-bears.jpg', 'https://cdn1.tedsby.com/tb/large/storage/1/3/9/139462/cute-handmade-teddy-bear-oliver.jpg', 'https://i5.walmartimages.com/asr/5d5541cd-d9cc-4b47-b7de-ebc107b74d82_1.9f14f307142cfd730852e875760b90bc.jpeg', 'https://api.time.com/wp-content/uploads/2016/12/teddy-bear.jpg', 'http://www.photos-public-domain.com/wp-content/uploads/2011/01/teddy-bear-wearing-mardi-gras-beads.jpg', 'https://pngimg.com/uploads/teddy_bear/teddy_bear_PNG14.png', 'https://teddy.ph/wp-content/uploads/2019/08/feature-30.jpg', 'https://cdn.jewishboston.com/uploads/2019/01/iStock-932242472.jpg', 'https://newcastlebeach.org/images/teddy-bear-with-heart-4.jpg', 'https://teddybears.co.uk/wp-content/uploads/2019/02/uk-2019-2736x3648.jpg', 'https://cdn.thewhoot.com/wp-content/uploads/2018/06/Knitted-Teddy-Bear-Patterns-1.jpg', 'https://www.teddybearaustralia.com.au/wp-content/uploads/2018/09/FullSizeRender-6.jpg', 'https://cdn8.bigcommerce.com/s-dee9d/images/stencil/1280x1280/products/883/8961/4ft_green_teddy_bear_Big_smile_and_soft_cuddly_bear__85725.1493921227.jpg?c=2', 'https://image.made-in-china.com/2f0j00wqhfEUTWOVbo/Factary-Price-Giant-Teddy-Bear-Big-Plush-Teddy-Bear-Soft-Toys-for-Girls.jpg', 'https://www.stuffedwithplushtoys.com/assets/full/u4040131.jpg', 'https://www.bloomsonly.com/media/catalog/product/cache/2/image/1200x1200/9df78eab33525d08d6e5fb8d27136e95/m/e/meng-meng-cute-brown-teddy-bear-head-tilt-twisting-holiday-gifts-velvet-ribbon-light-brown-bear.jpg', 'https://www.desicomments.com/dc3/02/215657/215657.jpg', 'https://www.teddybearacademy.net/wp-content/uploads/2014/08/Marco-full.jpg', 'https://pngimg.com/uploads/teddy_bear/teddy_bear_PNG45.png', 'http://images.antiquesatlas.com/dealer-stock-images/sladesantiques/Vintage_Small_9_Steiff_Mohair__as527a528z.jpg', 'https://www.worldofbears.com/acatalog/LG01.jpg', 'http://www.pavlovspuppets.com/p/teddy3.jpg', 'https://primopromo.com.au/assets/Uploads/Teddy-Bear+Dark-Green-v3.jpg', 'https://cdn0.rubylane.com/shops/700632/I-1277.1L.jpg', 'https://1.bp.blogspot.com/-eTFJzsbT2Pg/T3qHL_rPBMI/AAAAAAAABsA/5J8eXBe2d9A/s1600/Teddy+Bear+Wallpapers.jpg', 'https://plazarealestate.com.au/wp-content/uploads/sites/131/2016/07/Teddy-Bears.jpg', 'https://cdn0.rubylane.com/_pod/item/1491561/1920sx20Germanx20bear/lovely-German-1920s-teddy-bear--full-2-2048-93.jpg', 'https://twinsmom.com/wp-content/uploads/2020/04/GUND-Slumbers-Teddy-Bear-Stuffed-Animal-Plush-Brown-1722.jpg', 'https://www.melijoe.com/images/142519/open_graph.jpg', 'https://i.ebayimg.com/images/i/221655718748-0-1/s-l1000.jpg', 'https://n3.sdlcdn.com/imgs/i/h/h/Mable-Cuddle-Big-Teddy-Bear-SDL312942984-1-7984b.jpeg', 'https://wallsdesk.com/wp-content/uploads/2016/11/Teddy-Bear-Background.jpg', 'https://www.jarrold.co.uk/userdata/root/images/products/steiff/teddy-bear-replica-1909.jpg', 'https://4.bp.blogspot.com/_OTdJvruSaiI/Swtbm1GvbWI/AAAAAAAAFdo/WXyAoA_1Qco/s1600/IMG_3609.JPG', 'http://4.bp.blogspot.com/_ED0zYuiiwBg/TBke2UCnvHI/AAAAAAAACJU/AfQyXaz-NJI/s1600/aetna+bear.jpg', 'https://www.buildabear.co.uk/on/demandware.static/-/Sites-buildabear-master/default/dw82e7e236/25239x.jpg', 'https://www.lifejackets.com/wp-content/uploads/2020/03/229-EBbearblueribboneverych-1.png', 'http://www.funandcash.com/ebay/teddy-white-small-X-1-A.jpg', 'https://3.bp.blogspot.com/_ED0zYuiiwBg/TLNvSWhZTCI/AAAAAAAACrM/1zXtB07mYlY/s1600/teddy+bears+halloween+closeup+2.JPG', 'https://jooinn.com/images/teddy-bear-48.jpg', 'https://cdn.shopify.com/s/files/1/2622/2548/products/wholesale-plush-in-a-rush-106-14242280636518_1200x.jpg?v=1597087632', 'https://www.carouselshop.co.uk/media/catalog/product/cache/9/image/2000x/040ec09b1e35df139433887a97daa66f/B/F/BFFC8662B837D2AA8409CA13393604F6.jpg', 'https://i5.walmartimages.com/asr/ab097d42-d89e-4db0-a7df-6d87b08de9ab_1.0e68fae386f2fafcb61bfbd7fc12828e.jpeg', 'https://3.bp.blogspot.com/-vmp7XBf08eM/Tca-_DqLdeI/AAAAAAAACGQ/cJa3P2VUpT4/s1600/%252362+Teddy+bears+picnic.JPG', 'https://image.made-in-china.com/2f0j00NdUtRvuYOLbp/2017-New-Design-Scary-Teddy-Bear-Zombie-Bear-Undead-Bear-Bloody-Bear-Horrible-Teddy-Bear.jpg', 'https://teddybears.co.uk/wp-content/uploads/2015/09/petsy-28cm.jpg', 'https://4.bp.blogspot.com/-003EDE5jTOw/UDSwjEWC7oI/AAAAAAAADuQ/lA_x_5ECQAo/s1600/teddy-bear-14-hqwallpapers4u.co.cc.jpg', 'https://www.sayitwithbears.co.uk/wp-content/uploads/2016/07/large-personalised-bonnie-honey-scaled.jpg', 'https://webimg.secondhandapp.com/1.1/5e30189ab33a15626007900b', 'https://www.buildabear.com/on/demandware.static/-/Sites-buildabear-master/default/dwa68008ec/26614x.jpg', 'http://cdn.shopify.com/s/files/1/2429/7549/products/Edgar-_4_634bce55-3448-4579-adaf-349cc2dfe069_1200x1200.jpg?v=1557254763', 'https://cdn.shopify.com/s/files/1/2622/2548/products/wholesale-plush-in-a-rush-14271863685222_1024x1024.jpg?v=1586794398', 'https://cdn-image.realsimple.com/sites/default/files/styles/portrait_435x518/public/1510689111/giant-teddy-bear.jpg?itok=JRUEDZtP', 'https://www.buildabear.com/dw/image/v2/BBNG_PRD/on/demandware.static/-/Sites-buildabear-master/default/dw78d308a2/28167x.jpg?sw=600&sh=600&sm=fit&q=70', 'https://www.pcsoutdoors.com/images/products/detail/BeaverBearLgFront.jpg', 'http://allpicts.in/wp-content/uploads/2015/10/Cute-Teddy-bear-with-Pink-roses.jpg', 'https://pngimg.com/uploads/teddy_bear/teddy_bear_PNG94.png', 'http://cdn.shopify.com/s/files/1/0704/5013/products/teddy-bears-gund-maxie-bear-beige-24-1_1024x1024.jpg?v=1544388291', 'http://c.shld.net/rpx/i/s/i/spin/image/spin_prod_1099814412??hei=64&wid=64&qlt=50', 'https://cdn0.rubylane.com/shops/1754162/118.1L.jpg', 'http://www.photos-public-domain.com/wp-content/uploads/2010/12/cream_colored_teddy_bear.jpg', 'https://cdn0.rubylane.com/shops/your-favorite-doll/156.1L.jpg', 'https://pngimg.com/uploads/teddy_bear/teddy_bear_PNG7.png', 'https://www.buildabear.com/on/demandware.static/-/Sites-buildabear-master/default/dwbebeadb4/24925x.jpg', 'https://pngimg.com/uploads/teddy_bear/teddy_bear_PNG90.png', 'http://1.bp.blogspot.com/_ED0zYuiiwBg/TCoGLyKhVNI/AAAAAAAACMU/Sk2m6kJtwQ0/s1600/odd+bear+seated.jpg', 'https://www.henrymayo.com/images/content-images/Teddy-Bear.jpg', 'https://www.buildabear.com/on/demandware.static/-/Sites-buildabear-master/default/dw2b81d8a7/28502x.jpg', 'https://www.school-bears.co.uk/wp-content/uploads/2018/01/personalised-teddy-bear-anne.jpg', 'https://api.time.com/wp-content/uploads/2019/12/Teddy-Bear.jpg?quality=85&w=1200&h=628&crop=1', 'https://purepng.com/public/uploads/large/two-teddy-bear-in-basket-qyo.png', 'https://cdn11.bigcommerce.com/s-dee9d/images/stencil/1280x1280/products/143/1173/Sweetie-Pie-Big-Love-hazelnut-brown-teddy-bear-30in__97755.1542992358.jpg?c=2', 'https://www.taylorherring.com/wp-content/uploads/2015/04/GiantTeddyBears-5-781x1020.jpg', 'https://theeducationhub.org.nz/wp-content/uploads/2020/03/Teddy-bear-hunt-scaled.jpg', 'https://teddybearsandfriends.com/wp-content/uploads/2013/12/Teddy-Bear-Miniature-US-Special-1984-97-98-1_.jpg', 'https://cdn8.bigcommerce.com/s-dee9d/images/stencil/1280x1280/products/354/2910/Sweetie-Tubs-mocha-brown-teddy-bear-65in_3__58929.1323818431.jpg?c=2', 'https://teddybears.co.uk/wp-content/uploads/2017/09/113321.jpg', 'https://www.fromme.co.zw/uploads/2020/08/Teddy-FM_.jpg', 'https://craftsmumship.com/wp-content/uploads/2013/04/Kina-dolls-size-knitted-cardigan.jpg', 'http://mylitter.com/wp-content/uploads/2019/02/bear.jpg', 'https://www.stuffedwithplushtoys.com/assets/full/9750-30.jpg?20180212090824', 'https://www.grabhub.co.uk/wp-content/uploads/2020/07/Peek-a-Boo-Teddy-Bear-1.jpg', 'https://images.wallpaperscraft.com/image/soft_toy_teddy_bear_bear_117110_938x1668.jpg', 'https://www.curiousmondo.com/images/2017/11/02/teddy-bear-making-04.jpg', 'http://1.bp.blogspot.com/-NosZBJngTnA/Tp_rt11Z4PI/AAAAAAAAAJg/GNVaaoWmesg/s1600/Teddy+bear+detail1.JPG', 'https://www.carouselshop.co.uk/media/catalog/product/cache/9/image/2000x/040ec09b1e35df139433887a97daa66f/D/1/D10F255704F7CE7FBEB25963EFF90A74.jpg', 'https://cdn0.rubylane.com/shops/738907/T722.1L.jpg?63']
    Images downloaded.
After checking images for issues, 256 (total) images remain.

"Only 100(x3) images?! How can you hope to train a sophistical computer vision model with such a small amount of data?" Transfer Learning, my friend.

Load the Data and Take a Look

Here are some examples of the images we grabbed:

def setup_dls(path):
    data = DataBlock(        # define fastai data structure
        blocks=(ImageBlock, CategoryBlock), 
        get_items=get_image_files, 
        splitter=RandomSplitter(valid_pct=0.2, seed=42),
        get_y=parent_label,
        item_tfms=RandomResizedCrop(224, min_scale=0.5),
        batch_tfms=aug_transforms())
    dls = data.dataloaders(path)    # define dataloader(s)
    return dls 

dls = setup_dls(path)
dls.show_batch()                # take a look

Define and Train the Model

...With my special "triangle plot" visualization ( as demonstrated in the Part 1 blog post) called from my VizPreds fastai Callback (described below). (If you run this notebook on Colab, you'll need to authorize Google Drive when prompted below, in order for the triangle plot image thumbnails to show).

In the plots that follow, mouse over the dots to see our bear images "move" as the model trains! You'll see one epoch where the "body" network's weights are frozen, and then four epochs where the full model trains.

learn = cnn_learner(dls, resnet18, metrics=[error_rate])
learn.fine_tune(4, cbs=VizPreds)  # fine_tune does 1 epoch 'frozen', then as many more epochs you specify
Generating (URLS of) thumbnail images...
Drive already mounted at /gdrive; to attempt to forcibly remount, call drive.mount("/gdrive", force_remount=True).
Thumbnails saved to Google Drive in /gdrive/My Drive/scraped_images_thumbs/
Waiting on Google Drive until URLs are ready.

epoch train_loss valid_loss error_rate time
0 1.788116 0.159182 0.019608 00:13
Epoch 0: Plotting 51 (= 51?) points:
epoch train_loss valid_loss error_rate time
0 0.327038 0.050930 0.000000 00:13
1 0.231127 0.067547 0.019608 00:13
2 0.170447 0.047806 0.019608 00:13
3 0.134644 0.027070 0.019608 00:13
Epoch 0: Plotting 51 (= 51?) points:
Epoch 1: Plotting 51 (= 51?) points:
Epoch 2: Plotting 51 (= 51?) points:
Epoch 3: Plotting 51 (= 51?) points:

Depending on which bear images get scraped on which day, even this may be trivially easy. When I ran this above, there was only one error: a tiny brown-colored bear cub that was classified by the model as grizzly but that was labeled (via DuckDuckGo) as a black bear. All the other points correctly "collapsed" very quickly nearly the poles.

If we look at the confusion matrix, we'll see (for the time I ran this), only the one error mentioned above:

interp = ClassificationInterpretation.from_learner(learn)
interp.plot_confusion_matrix()

And if we plot the top losses, we'll see (based on mousing-over in the triangle plot above) the images for the points furthest from the poles: first the mislabeled cub, then a grizzly mother and cub, then a teddy bear:

interp.plot_top_losses(6, nrows=1)

When I ran this, the top loss image was actually a small dog! I coulda/shoulda checked that above in the triangle plot!

We're not going to train this more or clean the dataset, instead let's just remember that in this case, for 3 classes our error rate was 0.019608 (= 1/51, i.e. 1 error out of 51 images in the validation set), i.e. we were ~98% accurate.

Four Classes

Let's add one more bear to the mix, the "spectacled bear", and repeat this process, and visualize in 3D (sadly no image thumbnail mouseovers for 3D plots). First we'll download and look at what we've got..

labels = 'grizzly','black','teddy','spectacled'
scrape_for_me(dl_path, [labels[-1]], search_suffix, erase_dir=False) # download one more class
dls = setup_dls(path)
dls.show_batch()  
spectacled bear: Got 100 image URLs. Downloading...
   urls =  ['http://4.bp.blogspot.com/-6xZLUXHh8Uc/UUxmEy9QZBI/AAAAAAAAXcY/TMXg3WwS3GA/s1600/Spectacled+Bear+2.jpg', 'https://www.coolearth.org/wp-content/uploads/2016/06/Spectacled-Bear-2.jpg', 'http://3.bp.blogspot.com/-Sg8TmR5qh88/UUxmNY4d0HI/AAAAAAAAXcw/dpL2qFHZvp0/s1600/Spectacled+Bear+5.jpg', 'https://i.natgeofe.com/n/804d9cdb-f8da-449a-93b0-aac7a448b7c0/spectacled-bear_thumb.JPG?w=1200', 'https://www.activewild.com/wp-content/uploads/2018/03/spectacled-bears-1024x683.jpg', 'http://www.rainforest-alliance.org/sites/default/files/2016-09/spectacled-bear-header.jpg', 'https://lh6.googleusercontent.com/-Sptgd7fYIqY/TYk4YVRbndI/AAAAAAAAB7E/MYqqcMu-isw/s1600/Spectacled_Bear_Tennoji_2.jpg', 'https://www.vanwageningen.net/i/upload/2014/10/29/20141029132015-bc5e40e5-me.jpg', 'https://media.buzzle.com/media/images-en/photos/mammals/bears/1200-1002804-spectacled-bear-face.jpg', 'http://justfunfacts.com/wp-content/uploads/2017/11/spectacled-bear.jpg', 'https://colombiareports.com/wp-content/uploads/2017/07/spectacled_bear.jpg', 'http://tenrandomfacts.com/wp-content/uploads/2016/07/Spectacled-Bear.jpg', 'https://static1.squarespace.com/static/56a1a14b05caa7ee9f26f47d/t/57390f5520c6471cf068c6cc/1463357302812/', 'http://theamazonianassignment.weebly.com/uploads/1/2/1/3/12136910/944137409_orig.jpg', 'https://www.aboutanimals.com/images/spectacled-bear-ecuadorian-andes-mountains-328x562.jpg?c14113', 'http://i1.treknature.com/photos/2959/bear_0111111.jpg', 'http://2.bp.blogspot.com/-vdZv8wGWMdo/UUxmNCvsvhI/AAAAAAAAXco/H5Pzgk5dtOk/s1600/Spectacled+Bear+6.jpg', 'https://media.sciencephoto.com/image/c0175188/800wm/C0175188-Spectacled_Bear.jpg', 'http://www.stlzoo.org/files/1014/0017/1158/ANDEANBEAR9410WINKELMAN2.jpg', 'https://www.tourradar.com/days-to-come/wp-content/uploads/2016/01/Spectacled-bear.jpg', 'https://www.zoochat.com/community/media/spectacled-bear.250657/full?d=1393011952', 'http://2.bp.blogspot.com/-1jh4WfVEyx4/T_A-OoNHGFI/AAAAAAAAMHM/Wm41l9WFfgs/s1600/Spectacled+Bear3.jpg', 'http://www.rainforest-alliance.org/sites/default/files/styles/750w_585h/public/2016-09/spectacled-bear-header.jpg?itok=0V7_KGpe', 'https://www.sustainability-times.com/wp-content/uploads/2019/06/AndeanBear_ZN.jpg', 'http://www.animalspot.net/wp-content/uploads/2015/12/Spectacled-Bear-Habitat.jpg', 'http://seethewild.org/wp-content/uploads/2016/05/features.jpeg', 'https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/spectacled-bear-portrait-rose-santuci-sofranko.jpg', 'http://kids.sandiegozoo.org/sites/default/files/2017-07/andean-bear-tree.jpg', 'https://southafricatoday.net/wp-content/uploads/2018/07/1532665810_1-1024x1000.jpg', 'https://upload.wikimedia.org/wikipedia/en/c/ce/Spectacled-bear.jpg', 'http://4.bp.blogspot.com/-zHQPWNws7VQ/TwK7vuoleYI/AAAAAAAAEuI/iZJGb0R9CEQ/s1600/spectacled_bear-spectacled_bear.jpg', 'http://www.ecns.cn/hd/2020/05/18/e41ef93a186c40a38726189b8901f6f3.jpg', 'http://www.animalspot.net/wp-content/uploads/2015/12/Baby-Spectacled-Bear.jpg', 'http://www.mammalwatching.com/wp-content/uploads/2018/01/EC-square-fox.jpg', 'http://newyorktrendnyc.com/wp-content/uploads/2013/11/andean-bear.jpg', 'https://home.bt.com/images/spectacled-bears-and-snow-leopards-among-creatures-getting-funding-boost-136427641293802601-180606124211.jpg', 'https://nationalzoo.si.edu/sites/default/files/animals/andeanbear-006.jpg', 'https://www.pitara.com/wordpress/wp-content/uploads/2001/02/spectacled-bear.jpg', 'http://3.bp.blogspot.com/-EGI8NqbPcvo/UUxmUJ6t1qI/AAAAAAAAXdA/fDUqD60Tv00/s1600/Spectacled+Bear.jpg', 'https://lh6.googleusercontent.com/-cc05A4QkDxc/TYk4S3w1qFI/AAAAAAAAB7A/3vb0t85A7GU/s1600/spectacled_bear_03.jpg', 'https://www.aboutanimals.com/images/spectacled-bear-rocks-820x545.jpg?c14113', 'https://i.ytimg.com/vi/VXFIYIQgEkg/maxresdefault.jpg', 'https://media.buzzle.com/media/images-en/photos/mammals/bears/1200-71192249-spectacled-bear.jpg', 'https://farm3.staticflickr.com/2913/14137750328_d101997a4c_z.jpg', 'http://www.realworldholidays.co.uk/blog/wp-content/uploads/2015/12/spectacled-bear1.jpg', 'http://justfunfacts.com/wp-content/uploads/2017/11/spectacled-bear-2.jpg', 'http://upload.wikimedia.org/wikipedia/commons/6/62/Spectacled_Bear_059.jpg', 'https://media.nbcwashington.com/2019/09/4621594915_9022bfd814_b.jpg?fit=1024%2C702', 'https://philadelphiazoo.org/wp-content/uploads/2019/10/Andean.SpectacledBear_Rosie_3395.jpg', 'http://2.bp.blogspot.com/-4bGjmY9K4pk/T_A-Yq5aNGI/AAAAAAAAMHc/pv9gEJ8O6Uo/s1600/Spectacled+Bear5.jpg', 'https://resize.hswstatic.com/w_907/gif/types-of-spectacled-bear0.jpg', 'http://1.bp.blogspot.com/-xGs4-W-3iSY/TjaZG6_XnOI/AAAAAAAABUE/AkEJ97L1HQc/s1600/156521.jpg', 'https://www.robertharding.com/watermark.php?type=preview&im=RM/RH/HORIZONTAL/1127-12838', 'https://i.pinimg.com/736x/fa/40/33/fa403340878f175322c07b860b9d6426--spectacled-bear-bolivia.jpg', 'http://img.izismile.com/img/img3/20100513/640/cute_spectacled_bear_640_03.jpg', 'https://ourplnt.com/wp-content/uploads/2016/03/Spectacled-bear.jpg', 'http://bearlegend.com/wp-content/uploads/2012/04/3956278926_328d1c6a54_o.jpg', 'http://cincinnatizoo.org/system/assets/uploads/2014/02/spectaculed-bear.jpg', 'http://3.bp.blogspot.com/-brSuqjGOIG0/URGtpFtyo_I/AAAAAAAAARg/vLE13RVoCsk/s1600/spectacled-bear.jpg', 'https://c2.staticflickr.com/2/1501/24144684635_73b9e79d88_b.jpg', 'https://critter.science/wp-content/uploads/2019/05/sb1.jpg', 'https://srcnaut.com/cdn-cgi/image/f=auto,fit=crop,g=0.5x0.5,w=2000,h=1125,q=90,d=1/upload/32/02/df/shutterstock-1188627676.jpg', 'http://seethewild.org/wp-content/uploads/2016/05/dreamstime_15373008-1.jpg', 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Spectacled_Bear_-_Houston_Zoo.jpg/1200px-Spectacled_Bear_-_Houston_Zoo.jpg', 'https://www.zoochat.com/community/media/spectacled-bear-at-chester-15-07-12.192796/full?d=1342391273', 'https://res.cloudinary.com/dk-find-out/image/upload/q_80,w_1440,f_auto/MA_00155387_i4leyu.jpg', 'http://2.bp.blogspot.com/-PQGmVUDZAhs/TwK5urRX1LI/AAAAAAAAEtw/s569QHCcx8Y/s1600/spectacled+bear.jpg', 'https://bw-1651cf0d2f737d7adeab84d339dbabd3-gallery.s3.amazonaws.com/images/image_2865567/db2b44df10ba2a567a8e5cc34ddfeed0_original.JPG', 'http://etc.usf.edu/clippix/pix/spectacled-bear-with-piece-of-food-in-its-mouth_medium.jpg', 'https://www.activewild.com/wp-content/uploads/2018/03/spectacled-bear-standing-768x1024.jpg', 'http://2.bp.blogspot.com/-1mdQ66udYmw/T_A-UjaJk5I/AAAAAAAAMHU/uJw0kPcz1vc/s1600/Spectacled+Bear4.jpg', 'https://www.worldatlas.com/upload/43/04/5c/shutterstock-92656222-min.jpg', 'https://www.si.edu/sites/default/files/newsdesk/photos/andean-bear.jpg', 'https://www.aboutanimals.com/images/spectacled-bear-ogimage.jpg', 'https://images.freeimages.com/images/large-previews/e0f/spectacled-bear-1561333.jpg', 'https://kentattractions.co.uk/wp-content/uploads/2016/09/Spectacled-Bear.jpg', 'http://gringosabroad.com/wp-content/uploads/2013/11/Male-Andean-Bear-face.jpg', 'https://rangerplanet.com/wp-content/uploads/2019/10/spectacled-bear.jpg', 'https://www.wisebirding.co.uk/wp-content/uploads/Spectacled-Bear.jpg', 'https://i.ytimg.com/vi/2TmnhBSyQoo/maxresdefault.jpg', 'https://vistapointe.net/images/spectacled-bear-5.jpg', 'https://www.aboutanimals.com/images/spectacled-bear-tree-820x513.jpg?d8bc0c', 'https://standfirst-whitl