Lesson 1 official topic

I have the exact same issue, were u able to solve it somehow

Hi!

Here is my first homework:

There was an issue with ddg search function, I’ve found a fix for that

1 Like

IMDB Movie Review - how satisfactory is the result? - How to improve it?

Hello all,
as the very first example, I tried the code on p. 43 of the book in order to have classified my own reviews. I am completely new so I don’t know what quality to expect from an AWD_LSTM architecture, but I was astonished to find as response to my request
learn.predict("I don't recommend this movie.")
the answer
('pos', tensor(1), tensor([0.0418, 0.9582]))

Is it expected that the “don’t” does not seem to be interpreted together with “recommend”? Only if I asked the prediction of a sentence with a clearly negative adjective, like “This movie is boring.”, I got an actual negative result.

I would like to try a different model (or should I try different settings of the model, or of the fine_tuneing?), but I am unsure how to find some. I noticed this model is the only one defined in the respective .py file fastai\text\models\awdlstm.py, and the folder does not contain more models; I tried to search docs.fast.ai for the AWD_LSTM to locate feasible alternatives but didn’t succeed.

Best regards,
Martin

I am facing the same issue. can anyone help?

I found an answer somewhere in this forum, to solve it firstly add fastbook to pip install and then rewrite search_images as:

from fastbook import search_images_ddg

def search_images(term, max_images=30):
    print(f"Searching for '{term}'")
    return search_images_ddg(term, max_images=max_images)
6 Likes

I also had an issue with urlopen not working with DDGS, but I got past it, feel free to have a look here:

Basically, I rewrote download_images to use the Python Requests library, an update to urllib.

However, further down, I had to address the urllib issue directly. I had to create an unverified SSL context:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Note: this may entail some security issues, but I’m not sure what exactly. I know I can make HTTPS calls with the Python Requests library just fine, not sure why urllib verification was not working. But the code that calls urllib is too deep in the fastai code to work around, and all it is doing is grabbing the resnet18 weights from PyTorch Hub, so if you trust your local network and domain server I think it’s ok.

1 Like

I saw the link to the https://course.fast.ai/datasets is showing a 404. Is it browseable?

I think you probably saw that link with the previous version (2020) of the course which is now located here:

This is different than the 2022 version of the course which I do not believe has a specific section url for datasets.

1 Like

Thank you!

1 Like

Lesson One Homework:

Does anyone have any working examples on how to use the download_images() function using a text or csv file in kaggle? The file would contain the list of urls of images I want to use as part of my dataset for the homework.

I’ve tried both. I uploaded them into kaggle under notebook ‘input data’, and they appear as data sets, with the file there.

searchTerm = 'blonde woman'
path = Path('blondes')
print(path)
dest.mkdir(exist_ok=True, parents=True)
download_images(dest, url_file= '/kaggle/input/brit-csv/brittany_list.csv')

The error that I’m seeing is:

File /opt/conda/lib/python3.10/site-packages/fastai/vision/utils.py:39, in download_images(dest, url_file, urls, max_pics, n_workers, timeout, preserve_filename)
     37 def download_images(dest, url_file=None, urls=None, max_pics=1000, n_workers=8, timeout=4, preserve_filename=False):
     38     "Download images listed in text file `url_file` to path `dest`, at most `max_pics`"
---> 39     if urls is None: urls = url_file.read_text().strip().split("\n")[:max_pics]
     40     dest = Path(dest)
     41     dest.mkdir(exist_ok=True)

AttributeError: 'str' object has no attribute 'read_text'

Any ideas? I think it’s how I’m referencing the file, but not sure.

It’s clear that url_file.read_text() isn’t working, but I don’t know where that .read_text() function is defined so I could further debug.

Instead of search giving me the dataset, I wanted ot reference my own dataset, where the the urls I want to specifically point to for images would be contained in the csv.

As a reply to my own question…

It’s because it needs to be a Path() object. That wasn’t clear from the documentation in terms of the type required.

Thanks!

1 Like

Is is necessary to read the book after each lecture? I realize it would be ideal, but I have limited time due to working and wonder if it is a bit overkill and necessary?

To anyone who watch the lectures and read the book, did you find it necessary? Or do you feel the lectures alone are adequate to learn everything and move onto learning by doing and then going on to the next lecture?

Thank you! This saved me from going down a DDGS/httpx hole.

Friends I am getting error while running the below command in Kaggle Jupyter
!pip install -Uqq fastai duckduckgo_search

ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/opt/conda/lib/python3.10/site-packages/nest_asyncio-1.5.8.dist-info/METADATA

Please suggest

Hi, I am getting an HttpError while running Is it a Bird? notebook. Can anyone please help resolve this issue ?

1 Like

Hello!

I have created a spin-off from the bird vs. forest code that Jeremy provided.
I trained the model to detect a mouse, cat, dog, and eagle.
When I test the code using images of actual mice, cats, dogs, and eagles, it works perfectly fine.
However, when I test the model with an image of a computer, it tells me that the probability of it being a mouse is 0.9993.
Can someone explain why this is?

Thank you.

Any help or suggestion would very helpful

Hey, same problem here. :frowning:

This error crops up because the API for the duckduckgo-search library has changed slightly since the notebook was originally published.

A couple of ways to get the notebook working:
(1) Replace ddg_images with search_images_ddg from the fastbook library. This is the quickest way to get it going. The fix with a code example is originally mentioned here: Lesson 1 official topic - #608 by SergeyF
(2) Rewrite the search_images function using the updated DDGS class. Example:

from duckduckgo_search import DDGS

def search_img_urls(keywords: str, max_results: int) -> list:
    """
    Searches DDG using the keywords string and returns a list of 
    matching image urls up to length max_results.
    """
    with DDGS() as ddgs:
        keywords = keywords
        ddgs_images_gen = ddgs.images(
            keywords,
            max_results=max_results
        )
        r = [result["image"] for result in ddgs_images_gen]
    return r
2 Likes

Hello! I have a question

is_mario_or_luigi,_,probs = learn.predict(PILImage.create('mario.jpg'))
print(f"This is a: {is_mario_or_luigi}.")
print(f"Probability it's Mario or Luigi: {probs[0]:.4f}")
This is a: mario.
Probability it's Mario or Luigi: 0.0353

I’m confused why the probs are so low, any help?

My notebook: Google Colab