Since Bing Image Search at Microsoft Azure is not available anymore (officially fully retired), I have rewritten the search_images_bing function of Lesson 2 in Python using free Unsplash API service:
import requests
import math
def search_images_bing(key, term, max_images=150):
photo_urls = [ ]
i = 1
while i <= math.ceil(max_images/30):
url = f’https://api.unsplash.com/search/photos?query={term}&per_page=30&page={i}&client_id={key}’
response = requests.get(url)
data = response.json()
for photo in data[‘results’]:
photo_urls.append(photo[‘urls’][‘regular’])
i = i + 1
return photo_urls
If you find this approach (function) helpful/useful, you need to adjust the next cell (right after the cell with search_images_bing) as follows:
also in the second after words “This seems to have worked nicely, so let’s use fastai’s download_images to download all the URLs for each of our search terms. We’ll put each in a separate folder:” code cell you need to replace the code line download_images(dest, urls=results.attrgot(‘contentUrl’)) by download_images(dest, urls=results)#).attrgot(‘contentUrl’))
… and by the way in this approach you need to assign key as it is, i.e. key = ‘XXXX’ (but not key = os.environ.get(‘AZURE_SEARCH_KEY’, ‘XXX’)). And yes, you need to register on Unsplash Developers Portal and get your API key there firstly.
Thank you for this course; I’m having a lot of fun
I have made a small app for learning the Georgian alphabet. I tried several ways to gather data for tuning my model. At first I gathered images from the internet like in the lesson, then I used this dataset kaggle/datasets/kipshidze/georgian-handwritten-letters-dataset/data plus my handwriting, but the accuracy still isn’t good. I wonder what else I can do to improve my model. I will keep working on it.
Study group, anyone? I’m here in 2025 looking for fastai accountabilibuddies.
I keep starting this course, even bought the O’Reilly book, but I keep getting distracted before I make it to like lesson 4. Hit me up, boscacci@proton.me. Maybe we could do weekly check-ins to discuss course topics and demo each other’s homework / projects.
Hello. I’m trying to follow along with deploying my Dog/Cat classifier on HuggingFace. But when I push my app.py to HF, it fails with this error:
UserWarning: load_learner uses Python’s insecure pickle module, which can execute malicious arbitrary code when loading. Only load files you trust.
If you only need to load model weights and optimizer state, use the safe Learner.load instead.
warn("load_learner uses Python's insecure pickle module, which can execute malicious arbitrary code when loading.
Is there a way to whitelist my app or model? I can’t find any documentation on replacing load_learner with Learner.load either. I’ve seen the docs describing Learner.load but it seems to be a different sort of function than learner_load.
Please can anyone point me to a way to get this up and running? It seems like an immensely critical and basic function to straight up not work any more!
I faced this issue as well. You can try to check my version with images as input (now I have base64 images). I’m a beginner in Python, so I used ChatGPT and DeepSeek for debugging. ChatGPT and DeepSeek are very helpful.
Thanks for the reply. I tried adding all the imports you have (essentially the only lines that are different in my file) but am still having the issue.
Could you share what’s in your requirements.txt ? Maybe it’s something in there?
Also I noticed this part of the error this time, perhaps I need to do something different with versions?
RuntimeError: Loading model fname='model.pkl', attempted to import from `fastcore.dispatch` and/or `fastcore.transform` which are deprecated in `fastai>=2.8.0`.
Downgrade to `fastai<2.8.0` if you want to load this model.
runtime error
Exit code: 1. Reason: Traceback (most recent call last):
File “/home/user/app/app.py”, line 12, in
learn = load_learner(“trash_classifier.pkl”)
File “/usr/local/lib/python3.10/site-packages/fastai/learner.py”, line 446, in load_learner
try: res = torch.load(fname, map_location=map_loc, pickle_module=pickle_module)
File “/usr/local/lib/python3.10/site-packages/torch/serialization.py”, line 809, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File “/usr/local/lib/python3.10/site-packages/torch/serialization.py”, line 1172, in _load
result = unpickler.load()
TypeError: code expected at most 16 arguments, got 18