Lesson 2 official topic

I suggest following along with the recent part 1 course. It combines the chapters of the book with updated materials & methods. And particularly the ‘is it a bird?’ example which uses an updated alternative to Bing to download images. (You won’t need to worry about trying to get Bing working)

thanks so much! I was in lesson 2, where it has bing search, i switched to duckduckgo, it works fine now.

Good day! Thank you very much for this great course. I have a couple of questions:

  1. Is there a way to display the name of the images that are part of the output of the plot_top_losses() function?

This is so I can know which to remove/change to clean my data properly.

  1. It seems like ImageClassifierCleaner does not work properly on Paperspace. An error appears as seen below:

Note that I already have run the following code to import the widgets:

from fastai.vision.widgets import *

Thank you, everyone!

I am on Lesson 2. Watching video and reading a book. Still have a question. Do I understand correctly that when training and validating, we assume that folder labels are correct? What if search_images (ddg in my case) downloaded incorrectly labeled images (ie. an image of a cat labeled as “grizzly bear” and put it in a “grizzly” folder)? What am I missing?

I am running a code for lesson 2 on my M2 mac. and I am getting the below error. Does it mean I better switch to Kaggle or Colab with GPU?

error. NotImplementedError: The operator ‘aten::_linalg_solve_ex.result’
is not currently implemented for the MPS device. If you want this op to be added in priority during the prototype phase of this feature, please comment on
https://github.com/pytorch/pytorch/issues/77764. As a temporary fix, you can set the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.

Hey team! I am using my local jupyter notebook, and simply trying to install & import fast ai.
I confirmed that I installed fastai the latest version is properly installed.

But whenever I do from fastai.vision.all import *, I am getting “ModuleNotFoundError: No module named ‘PIL’” error.
I see a similar issue reported a few years back, and it seems the fix was introduced backthen. (Ref: ModuleNotFoundError: No module named 'fastai.vision.all' on Kaggle Notebook)

So I am curious about what I am missing in my local jupyter notebook setup.
This is the full error message.


ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_22080\233410589.py in
----> 1 from fastai.vision.all import *

~\anaconda3\lib\site-packages\fastai\vision\all.py in
----> 1 from . import models
2 from …basics import *
3 from …callback.all import *
4 from .augment import *
5 from .core import *

~\anaconda3\lib\site-packages\fastai\vision\models_init_.py in
----> 1 from . import xresnet
2 from . import unet
3 from .tvm import *

~\anaconda3\lib\site-packages\fastai\vision\models\xresnet.py in
3 # %% …/…/…/nbs/11_vision.models.xresnet.ipynb 2
4 from future import annotations
----> 5 from …torch_basics import *
6 try: from torchvision.models.utils import load_state_dict_from_url
7 except ModuleNotFoundError: from torch.hub import load_state_dict_from_url

~\anaconda3\lib\site-packages\fastai\torch_basics.py in
7 os.environ[‘KMP_DUPLICATE_LIB_OK’] = ‘True’
8
----> 9 from .imports import *
10 from .torch_imports import *
11 from .torch_core import *

~\anaconda3\lib\site-packages\fastai\imports.py in
3 import io,operator,sys,os,re,mimetypes,csv,itertools,json,shutil,glob,pickle,tarfile,collections
4 import hashlib,itertools,types,inspect,functools,random,time,math,bz2,typing,numbers,string
----> 5 import multiprocessing,threading,urllib,tempfile,concurrent.futures,matplotlib,warnings,zipfile
6
7 from concurrent.futures import as_completed

~\anaconda3\lib\site-packages\matplotlib_init_.py in
107 # cbook must import matplotlib only within function
108 # definitions, so it is safe to import from it here.
→ 109 from . import _api, _version, cbook, docstring, rcsetup
110 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
111 from matplotlib.cbook import mplDeprecation # deprecated

~\anaconda3\lib\site-packages\matplotlib\rcsetup.py in
25 from matplotlib import _api, cbook
26 from matplotlib.cbook import ls_mapper
—> 27 from matplotlib.colors import Colormap, is_color_like
28 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
29 from matplotlib._enums import JoinStyle, CapStyle

~\anaconda3\lib\site-packages\matplotlib\colors.py in
49 from numbers import Number
50 import re
—> 51 from PIL import Image
52 from PIL.PngImagePlugin import PngInfo
53

ModuleNotFoundError: No module named ‘PIL’


FYI this is my current python & pip version.
image

The same code works really well on Google colab. Would love to know what can be the potential differences in setups.

Thanks :slight_smile:

It looks like Pillow (aka PIL) might not have installed for you. You can check by listing what packages are installed using the list command, in your screenshot it looks like you use “pip” so if you type “pip list” it should return a (possibly long) list of installed packages and “Pillow” is the one to look for.

If you don’t see it listed then you’ll need to install it. I’m not really up to speed myself on Python package managers and while it can be installed using pip but IIRC in the lectures I think Jeremy used conda / mambaforge?

https://anaconda.org/anaconda/pillow

2 Likes

The outcome of

cleaner = ImageClassifierCleaner(learn)
cleaner

is misaligned on paperspace and kaggle. Please see attached, is there an easy fix? Thank you!

Thank you for investing your time and sharing the answer here @anthony !!
Yeap you are right - I thought it got installed as I thought I installed fastai properly which would install Pillow.

But when I did the pip list on my local machine, I don’t see either of them :exploding_head:
I should have double-checked before I went with my assumption :smiley:
Thanks again for your help :pray:

1 Like

I am getting the following error when I push app.py, model.pkl, example images, and other related stuff.

Anything I can do to turn this around?

Hello!

I imported the notebook into kaggle and tried to run it there.
During executing the following part I experience something rather strange:
image

If I try to create those directories the subdirectories (grizzly, black, teddy) the directory bears is continuously loading… like it would continuously create subdirectories. But that is no endless loop, right? What is happening here?

Edit: I split the loop from the initial version of the notebook to see if the mkdir was the problem or the download.

Edit 2: I think it has nothing to do with the folders anymore. I created 3 folders for each bear type and try to download pictures into them. After some problems I am now at

image

I need to include the clean_url - otherwise I get an error (‘NoneType’ object has no attribute ‘split’).

I tried some stuff, but I got this:

What is your best recommendation for deploying a mobile app?

It needs the git-lfs extension installed for large binary files. GitHub - git-lfs/git-lfs: Git extension for versioning large files

The other option is to manually upload any missed files to the huggingface space via the web interface.

  • Navigate to the space,
  • click on the files tab/view
  • select ‘add file’
2 Likes

That second chapter is tough. I corrected the downloader of the images. But with
dls.valid.show_batch(max_n=4, nrows=1)

I get

UnidentifiedImageError: cannot identify image file ‘/kaggle/working/bears/grizzly/b0572ccc-1c3a-490a-8c9e-a5bff43918d1.jpg’

Anyone got any hint?

1 Like

You may need to delete that file as it is corrupted or something like that. If you’re using the Kaggle site I think you can open up the console at the bottom of the page and you may be able to use the rm command to remove that file. I don’t think it’s possible to delete files via the Kaggle UI in the right hand tab under “Data” so the console is all I can personally think of at the moment.

The console is this icon at the bottom of the Kaggle web page.

image

And the rm command in your case might be (you may need to alter the path I’m not 100%):

rm /kaggle/working/bears/grizzly/b0572ccc-1c3a-490a-8c9e-a5bff43918d1.jpg

And then try show_batch again?

I tried… but then there is an issue with another file. Mmaybe something with kaggle? Can’t even download properly. Even hat to manipulate url’s manually because the (if I remember correctily) the ? in the url’s didn’t work.
I now installed jupyter notebook locally. Hope this will work.

Hopefully running things locally works for you.

Where exactly is the model used for fine tuning in these lines of code:
learn = vision_learner(dls, resnet18, metrics=error_rate)
learn.fine_tune(3)

I assume it is the vision_learner from these docs:

However, I was anticipating a pkl file. How would we load our own model to fine tune?

Having trouble deploying the java script website, what could be wrong with the code:

---
title: 1. Single file
layout: page
---

<input id="photo" type="file">
<div id="results"></div>
<script>
  async function loaded(reader) {
    const response = await fetch('https://hiddenmiddle-fastai-lesson2.hf.space/predict', {
      method: "POST", body: JSON.stringify({ "data": [reader.result] }),
      headers: { "Content-Type": "application/json" }
    });
    const json = await response.json();
    const label = json['data'][0]['confidences'][0]['label'];
    results.innerHTML = `<br/><img src="${reader.result}" width="300"> <p>${label}</p>`
  }
  function read() {
    const reader = new FileReader();
    reader.addEventListener('load', () => loaded(reader))
    reader.readAsDataURL(photo.files[0]);
  }
  photo.addEventListener('input', read);
</script>

It just takes in a picture, but doesn’t actually do anything

I also noticed same behavior at Single file | Jeremy Howard - it just takes in a picture, but doesn’t classify