Lesson 2 official topic

I assume you are talking about the output when using fine_tune? It is showing the output in two parts, initial frozen epochs followed by the unfrozen epochs.

Fine tune with Learner.freeze for freeze_epochs , then with Learner.unfreeze for epochs , using discriminative LR.

docs: learner.fine_tune

More on Unfreezing and Transfer Learning in the fastai book CH05_pet_breeds

tip: when working through the notebooks, you can use ?? to find out more about a function. e.g learn.fine_tune?? or can also use doc(learn.fine_tune).

Thanks Allen. I got it now.

Gordon

I am following the book and lecture 2 fastai (2022) on the grizzly bear chapter…all the cells are working except when I put the code and attempt to run:
dls = bears.dataloaders(path)

I get this error message:

TypeError Traceback (most recent call last)
/tmp/ipykernel_27/3866548988.py in
----> 1 dls = bears.dataloaders(path)

/opt/conda/lib/python3.7/site-packages/fastai/data/block.py in dataloaders(self, source, path, verbose, **kwargs)
153 **kwargs
154 ) → DataLoaders:
→ 155 dsets = self.datasets(source, verbose=verbose)
156 kwargs = {**self.dls_kwargs, **kwargs, ‘verbose’: verbose}
157 return dsets.dataloaders(path=path, after_item=self.item_tfms, after_batch=self.batch_tfms, **kwargs)

/opt/conda/lib/python3.7/site-packages/fastai/data/block.py in datasets(self, source, verbose)
145 splits = (self.splitter or RandomSplitter())(items)
146 pv(f"{len(splits)} datasets of sizes {‘,’.join([str(len(s)) for s in splits])}", verbose)
→ 147 return Datasets(items, tfms=self._combine_type_tfms(), splits=splits, dl_type=self.dl_type, n_inp=self.n_inp, verbose=verbose)
148
149 def dataloaders(self,

/opt/conda/lib/python3.7/site-packages/fastai/data/core.py in init(self, items, tfms, tls, n_inp, dl_type, **kwargs)
452 ):
453 super().init(dl_type=dl_type)
→ 454 self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
455 self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))
456

/opt/conda/lib/python3.7/site-packages/fastai/data/core.py in (.0)
452 ):
453 super().init(dl_type=dl_type)
→ 454 self.tls = L(tls if tls else [TfmdLists(items, t, **kwargs) for t in L(ifnone(tfms,[None]))])
455 self.n_inp = ifnone(n_inp, max(1, len(self.tls)-1))
456

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in call(cls, x, *args, **kwargs)
96 def call(cls, x=None, *args, **kwargs):
97 if not args and not kwargs and x is not None and isinstance(x,cls): return x
—> 98 return super().call(x, *args, **kwargs)
99
100 # %% …/nbs/02_foundation.ipynb 46

/opt/conda/lib/python3.7/site-packages/fastai/data/core.py in init(self, items, tfms, use_list, do_setup, split_idx, train_setup, splits, types, verbose, dl_type)
366 if do_setup:
367 pv(f"Setting up {self.tfms}", verbose)
→ 368 self.setup(train_setup=train_setup)
369
370 def _new(self, items, split_idx=None, **kwargs):

/opt/conda/lib/python3.7/site-packages/fastai/data/core.py in setup(self, train_setup)
395 x = f(x)
396 self.types.append(type(x))
→ 397 types = L(t if is_listy(t) else [t] for t in self.types).concat().unique()
398 self.pretty_types = ‘\n’.join([f’ - {t}’ for t in types])
399

TypeError: ‘NoneType’ object is not iterable

It looks like you either haven’t specified what path is, or there is no data file where path is pointing.

Sharing a quick “bay area birds classifier” prototype: https://jingyun.xyz/bay-area-birds

(well, it only classifies the 10 bay area birds that I’ve personally seen…)

I am so impressed with these free prototyping tools! I’ve been out of datascience for ~3 years, and I feel like all this used to take so much work to set up. It was so much work to collect and clean data, so much work to load in models, so much work to deploy. Makes me feel old…

Amazing that this can now be built in a day. A true prototype experience.

1 Like

Hi jingyun,

Thanks for the response. I simply took the code from the book:

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)
results = search_images_ddg(key, f’{o} bear’)
download_images(dest, urls=results.attrgot(‘contentUrl’))

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)

At this point, I got the error messages but as you can see, I defined the path. Prior to this, I downloaded from ddg

ims = search_images_ddg(‘grizzly bear’)
len(ims)

dest = ‘images/grizzly.jpg’
download_url(ims[0], dest)

In addition,
when I run the code:

fns = get_image_files(path)
fns

It outputs [0] files

before I got there, I used:
search_images_ddg

and ims outputs 200 images when I call
len(ims)

when I run
ims

I get:
[‘http://www.kristitrimmer.com/wp-content/uploads/2014/06/6-4-14-Grizzly-Bear-Nose.jpg’,‘http://2.bp.blogspot.com/-e6e4YOB-K9I/UQEz1wt72TI/AAAAAAAAC0s/YZUgPnIwTks/s640/Grizzly+bear.jpg’,‘http://www.bearsoftheworld.net/images/bears/grizzly_bear04.jpg’,‘http://www.famouscutouts.com/images/detailed/0/675-Bear.jpg’,‘http://endangeredanimalsiy.yolasite.com/resources/grizzly_bear_1a.jpg’,‘http://4.bp.blogspot.com/-ocppOkj9hTc/UNMpyLQ-XCI/AAAAAAAAADU/SrOUp6pvTSA/s1600/grizzly+bear.jpg’,‘http://survival-mastery.com/wp-content/uploads/2015/06/Grizzly-Bear-1-680x485.jpg’,‘http://wallsdesk.com/wp-content/uploads/2017/01/Grizzly-Bear-Download.jpg’,‘http://2.bp.blogspot.com/-yZMfP4l4ArQ/T74-7rfY_rI/AAAAAAAADf8/2fVC197XAtQ/s1600/Grizzly+Bear7.jpg’,'http://mediad.publicbroadcasting.net/p/kufm/files/styles/x_large/public/201809/grizzly-bear-02_Istock.jpg’…]

So everything check out until I get to
fns = get_image_files(path)
fns

and get (#0)

Thank you Tanishq for the incredibly thought you put into putting these educational resources!

I am having issue with bing search. i signed up for cognitive services and use subscription key. but still get a “permission error”. Did anyone else have the same issue? Thanks!

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’).