Lesson 1 In-Class Discussion ✅

Thanks! @jithinrocs

I do see for this course they are using a machine image using gradient on paperspace, do you know if there will be any resources on configuring a base image on paperspace with either shell scripts and conda?

I would like retain the existing paperspace instance already have and just run commands from there to obtain all resources for v3. Thanks!

You can also add padding by using:

data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=224, bs=bs, padding_mode=‘border’)


Hi All

Thanks @Jeremy for wonderful course.

May I know what is cheapest option for GPU.


Options and prices are discussed here https://course.fast.ai/index.html

I have a problem with the first lesson/notebook on Windows: I am getting an AttributeError: 'NoneType' object has no attribute 'group' when creating the ImageDataBunch. I am using Anaconda with Python 3.7, Pytorch 1.0 Stable, fastai 1.0.38 installed via conda and the current master-branch of the coursework from Github.

This seems to be the same problem encountered by Johan1us here but I wanted to cross-post it in this thread, as it concerns the 2019 version of the course.

Thanks in advance for any help!


OK I worked through lesson one using my own dataset of images captured at my birdfeeder. I previously created a binary classifier using a commercial product Classificationbox and achieved 92% accuracy, but by following the lesson plan and using resnet34 I am getting almost 98% accuracy, so a great result :slight_smile: Notebook on kyso -> https://kyso.io/robmarkcole/birds-vs-not-birds-image-classification-using-fastai

1 Like

I worked through lesson 1 so I decided to do some home work. Found a flowers data set on Kaggle that has 102 different species of flowers. I copied the data set to my AWS instance, duplicated the lesson 1 notebook, then modified it to analyse the new data set. The initial results weren’t too promising with the vanilla Resnet34 model, with error rates around 70% for the first epoch. However I noticed a constant drop in error rate in subsequent epochs so I did a few more before I noticed over fitting starting to occur.

epoch train_loss valid_loss error_rate
1 2.832304 2.504375 0.610024
2 2.836951 2.441141 0.618582
3 2.752767 2.284255 0.574572
4 2.632155 2.179777 0.566015
5 2.481018 2.057612 0.525672
6 2.365763 2.012151 0.517115
7 2.291214 1.961817 0.504890
8 2.255578 1.995377 0.517115

50% is still pretty ordinary. Unfreezing and adjusting the learning rate didn’t help much either.

I had much better results using Resnet50 however. The first few epochs produced significantly lower error rates.

epoch train_loss valid_loss error_rate
1 2.498133 0.902909 0.179707
2 0.813650 0.290062 0.066015
3 0.337723 0.185570 0.039120
4 0.189965 0.168703 0.042787
5 0.102328 0.141482 0.039120
6 0.057604 0.116635 0.036675
7 0.045057 0.111272 0.033007
8 0.030797 0.111127 0.031785

Unfreezing and adjusting the learning rates I managed to get it down to < 3%.

epoch train_loss valid_loss error_rate
1 0.030077 0.105205 0.028117
2 0.026734 0.103359 0.029340
3 0.023275 0.101132 0.025672

I was quite surprised by the difference in results between Resnet34 and Resnet50. I assumed there would be some kind of “diminishing returns” as more layers are added to the model. If there is, I would assume “peak layer” hasn’t been hit yet - at least not for flower classification :slight_smile:

Onwards to Lesson 2!


Try changing the regex patter to windows format
pat = re.compile(r'\\([^\\]+)_\d+.jpg$')

Worked for me.


Good work!

For this dataset more layers do seem to help - here I get to 98.9% with DenseNet201 https://gist.github.com/AlisonDavey/5742c87aa45da57511b7b10bb4f8bd51 . People also get very good results with Resnet152.

In Lesson 1, why do we call unfreezing all the layers in the model fine-tuning? It feels we are doing the opposite.

PS: Not sure if this is the right place to ask this kind of questions. I am having issues understanding how Discourse works :open_mouth:

@gstrack @ritika26 thanks for the help you both. This community rocks :). Are these changes something I should put in a pull request? Or are notebooks only changed in exentuating circumstances by Jeremy?

1 Like

Thanks Aaron!

A community makes everything better!

In regards to changes to the git repo, I believe that’s managed by Jeremy and Rachel.

For me, I had to make a manual edits to resolve a couple of errors I encountered running my Lesson 1 notebook on my AWS instance. Here is a summary of the edits I made:

2nd Code Cell:
from fastai import *
from fastai.vision import *
#from fastai.metrics import error_rate

9th Code Cell:
#pat = re.compile(r’/([^/]+)\d+.jpg$’)
pat = r’/([^/]+)

10th Code Cell:
#data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=224, bs=bs
data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=224, bs=bs, padding_mode=‘zeros’)

C?? - Resnet50 Code Cell:
data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(),
size=299, bs=bs//2, padding_mode=‘zeros’).normalize(imagenet_stats)

I figure with so many different platforms, OS versions, library versions, etc. there is always going to be the odd tweak required here or there. I’ve found most of the errors are easily resolved by Googling the error message and/or searching this forum.

Happy coding!


I figured out why I wasn’t getting great results with resnet32. I had set the size of the data files to 24 instead of 224. Just a small typo but it made a huge difference in results.

epoch train_loss valid_loss error_rate
1 2.749509 0.876414 0.163814
2 0.885891 0.314874 0.066015
3 0.395196 0.244511 0.056235
4 0.263029 0.226939 0.055012

I was playing around with lesson 1 three weeks ago with 102 flowers too (not sure if its the same 102 cos I just got the data from kaggle), but a resnet18 got me 0.0378 error rate here. I did not try res50 or res32 though.

1 Like

It is called fine-tuning because you are only changing the pre-trained weights a little.

At the beginning you load the weights that work well on ImageNet onto the model, then you retrain the head the model of the model, adjusting just the weights of this part, to your specific data with the desired number of classes.

Once this is working well, you unfreeze the whole model, and allow all the weights to change – with a small learning rate so they just change a little – hence fine-tuning.

Hi all,

Since yesterday, I have been trying to load an external dataset of images (Fashion MNIST) but was unsuccessful.

I have tried untar_data() but it didn’t work. It seems to load the dataset since the .gz file appeared in the data folder (left panel in my screenshot below) but I get an error.

  • "Downloaded file {fname} does not match checksum expected! Remove that file from {data_dir} and try your code again."

Should I be using another function, if so, which one ?

Thanks for your help.
(P.S. I am using Google Colab)


Thanks Alison. Didn’t realise we were changing hem just a little from their current status. Thought it relaunched the learning from pre-trained status.

2nd UPDATE & FIX: see Unofficial Setup thread (Local, AWS) for better setup instructions. It seems the instructions I was using were out of date. I’ll keep my post below in case someone else hits the same issue.

Trying out Lesson 1 I am hitting an error in the call data.show_batch(rows=3, figsize=(7,6)) and also when I call learn.fit_one_cycle(4), the stack looks like this for the first call:

RuntimeError: Traceback (most recent call last):
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in <listcomp>
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/data_block.py", line 486, in __getitem__
    x = x.apply_tfms(self.tfms, **self.tfmargs)
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/image.py", line 113, in apply_tfms
    else: x = tfm(x)
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/image.py", line 498, in __call__
    return self.tfm(x, *args, **{**self.resolved, **kwargs}) if self.do_run else x
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/image.py", line 445, in __call__
    if args: return self.calc(*args, **kwargs)
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/image.py", line 450, in calc
    if self._wrap: return getattr(x, self._wrap)(self.func, *args, **kwargs)
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/image.py", line 167, in coord
    self.flow = func(self.flow, *args, **kwargs)
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/transform.py", line 227, in symmetric_warp
    return _perspective_warp(c, targ_pts, invert)
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/transform.py", line 213, in _perspective_warp
    return _apply_perspective(c, _find_coeffs(_orig_pts, targ_pts))
  File "/home/rallen/anaconda3/envs/fastaiv3/lib/python3.7/site-packages/fastai/vision/transform.py", line 194, in _find_coeffs
    return torch.gesv(B,A)[0][:,0]
RuntimeError: B should have at least 2 dimensions, but has 1 dimensions instead

I do see other messages asking about this issue Developer chat and Verify_images error but no resolution as yet, or just a suggestion that nightly pytorch should fix it. My versions for fastai=1.0.34 & pytorch=1.0.0.dev20190127

UPDATE: If you do the default instructions, installing torchvision after pytorch-nightly, you will actually end up with pytorch 0.4.1 installed. Check this with import torch; print(torch.__version__)

The current Lesson 1 doc seems to only work with pytorch 0.4.1. If I follow the default instructions & don’t force-reinstall nightly, things work okay–modulo the fixes some folks above have done. Mainly, the change to add `padding_mode=‘zeros’ to ImageDataBunch.from_name_re() seems to be a way to get fastai to work with pytorch 0.4.1.

I hit this error because I forced pytorch 1.0 to be installed since installing pytorch nightly was the guidance given in the setup. Does fastai really want us to be running with 1.0.xxx or with 0.4.1?