Lesson 1 In-Class Discussion ✅

The 5 images are just a few from the whole set. The CategoryList is the category to which the image belongs.
The total images in the dataset are the items. In your case : 5912 items in Train and 1478 items in Valid

Hi All:
I am new for fastai. In the first lesson, when classifying the pets, we fine-tuned the model and then unfreezed the model, trained again. I checked the document and found that unfreeze means ‘Sets every layer group to trainable’. I wonder did this mean that in the second step, we retrain all parameters in the model (including the parameters in the resnet34)? Why we want to do this?

Also, in the first step, although we fine-tuned the resnet34, I found all the batch normalization layers in the resnet34 still trainable. I did not quite understand this part. In the BN layers, there have four parameters, alpha, beta, mean and variance. From my perspective, mean and variance will be different depending on different input layers. But how about alpha and beta? If fine-tune the model, these two parameters should be frozen, rather than trainable, right?

I would be appreciate if someone could help me to figure these out. Sincerely appreciate.

Ahhhh thank you so much Rohan!!! That was super helpful!

I get the following error when I try to add a cutout transform to the list of augmentation transforms. It is unclear why I need to pass the high argument.

tfms=get_transforms(flip_vert=True, max_rotate=25., max_lighting=0.1, max_zoom=1.25)
# add cutout transform to tfms
cutout_tfm=RandTransform(cutout, kwargs={"n_holes":1, "length":40}, p=0.75)
cutout_tfm
tfms[0].append(cutout_tfm)

np.random.seed(42)
train_folder_name="train"
test_folder_name="test"
valid_pct=0.2
seed=42

src=(ImageList
     #from_folder(path/train_folder_name)
     .from_df(df, path, folder=train_folder_name)
     .split_by_rand_pct(valid_pct, seed=seed)
     .label_from_df()
     .add_test_folder(test_folder_name)
    )
bs=64
sz=64
data32=(src
      .transform(tfms, size=sz)
      .databunch(bs=bs)
      .normalize(imagenet_stats)
     )
data=data32

ERROR:

TypeError                                 Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/fastai/data_block.py in _check_kwargs(ds, tfms, **kwargs)
    580         x = ds[0]
--> 581         try: x.apply_tfms(tfms, **kwargs)
    582         except Exception as e:

/opt/conda/lib/python3.6/site-packages/fastai/vision/image.py in apply_tfms(self, tfms, do_resolve, xtra, size, resize_method, mult, padding_mode, mode, remove_out)
    106         tfms = sorted(tfms, key=lambda o: o.tfm.order)
--> 107         if do_resolve: _resolve_tfms(tfms)
    108         x = self.clone()

/opt/conda/lib/python3.6/site-packages/fastai/vision/image.py in _resolve_tfms(tfms)
    520     "Resolve every tfm in `tfms`."
--> 521     for f in listify(tfms): f.resolve()
    522 

/opt/conda/lib/python3.6/site-packages/fastai/vision/image.py in resolve(self)
    499                 rand_func = self.tfm.params[k]
--> 500                 self.resolved[k] = rand_func(*listify(v))
    501             # ...otherwise use the value directly

TypeError: uniform_int() missing 1 required positional argument: 'high'

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-26-f2424f3774ad> in <module>
      1 sz=64
      2 data32=(src
----> 3       .transform(tfms, size=sz)
      4       .databunch(bs=bs)
      5       .normalize(imagenet_stats)

/opt/conda/lib/python3.6/site-packages/fastai/data_block.py in transform(self, tfms, **kwargs)
    491         if not tfms: tfms=(None,None)
    492         assert is_listy(tfms) and len(tfms) == 2, "Please pass a list of two lists of transforms (train and valid)."
--> 493         self.train.transform(tfms[0], **kwargs)
    494         self.valid.transform(tfms[1], **kwargs)
    495         if self.test: self.test.transform(tfms[1], **kwargs)

/opt/conda/lib/python3.6/site-packages/fastai/data_block.py in transform(self, tfms, tfm_y, **kwargs)
    707     def transform(self, tfms:TfmList, tfm_y:bool=None, **kwargs):
    708         "Set the `tfms` and `tfm_y` value to be applied to the inputs and targets."
--> 709         _check_kwargs(self.x, tfms, **kwargs)
    710         if tfm_y is None: tfm_y = self.tfm_y
    711         if tfm_y: _check_kwargs(self.y, tfms, **kwargs)

/opt/conda/lib/python3.6/site-packages/fastai/data_block.py in _check_kwargs(ds, tfms, **kwargs)
    581         try: x.apply_tfms(tfms, **kwargs)
    582         except Exception as e:
--> 583             raise Exception(f"It's not possible to apply those transforms to your dataset:\n {e}")
    584 
    585 class LabelList(Dataset):

Exception: It's not possible to apply those transforms to your dataset:
 uniform_int() missing 1 required positional argument: 'high'

FIX:

I found that passing these tuples as args fixes the error: n_holes":(1,1), "length":(40,40)
Is it the right way?

My understanding is that the function picks an integer from the tuple (one integer from the range of integers defined by the tuple) I pass to these arguments. Is it correct?

Hi there,

I have played around with Lesson 1 notebook and the code is here:

So far I have two questions:

  1. The show_batch function takes a long time to run and does not show the same images as shown in the example notebook. Since we have set up the random seed, I expect to see the same images. Does anyone what is causing the difference?

  2. When I used ClassificationInterpretation to plot_top_losses, the image is not shown correctly. Does anyone have the same issue?

Thank you,
Ryan

1 Like

Hi Paul,
I am also interested in drug design.
Best,
Bill (Βασίλης)

sir iam working on image classification project. it will see the hand gestures and will tell the the number the hand is showing. suppose if there is an image of hand with three fingers then it will tell us 3. have my own dataset in my a folder called HANDS. In That folder there are 10 folders.
folder 1 contains hand images related to gesture 1. Folder 2 contains hand images related to gesture 2. and so on upto 10 folders. So please tell me how can i provide folders the path to the jupyter notebook.

hello @colawhite ,
I think the heatmap option is set to “True” which is a default option.You can turn it off like the example below,
interp.plot_top_losses(9, figsize=(15,11),heatmap=False)

Why is more efficient for calculation

it takes too long time to train 5 GB dataset (food 101) on google colab. I don’t know if it’s okay speed of a training. Is there a way to check it?

Hi @amallya, did you fix this?

I compressed my dataset by 7z on a tar and then on a gzip, the path of my file stayed like this: https://s3-sa-east-1.amazonaws.com/amazons3meurango/fastai/dataset.tar.gz

And when I run

url = “https://s3-sa-east-1.amazonaws.com/amazons3meurango/fastai
path2 = untar_data(url)

I encounter the same issue: ReadError: not a gzip file

Hi @amiaram, Short answer is no. But these links might help you - Untar_data requires .tgz file ending
and https://github.com/fastai/fastai/issues/1130
I was working on a sagemaker notebook instance at that time. And in couple of days, that somehow stopped opening and I ended up working on different dataset in different notebook instance.

1 Like

Hi, thanks for the reply.

I found a solution in the Kishore Iyer post link Untar_data requires .tgz file ending

He had been missing many hours in that. One more time, thank you.

1 Like

Hi, Is there a way to retrieve the digits dataset in Kaggle with ImageDataBunch?
train.csv :

Hi I created a classifier and i use the learn.predict() to get the prediction.
If i try to predict a garbage photo of something not of one of the classes it still returns an answer.
I can see that the output losses is vector that sums to 1.
Is there a way to know if the classifier has chosen a class, but has very low confidence that it is right?

Hi,

predict” gives you the predicted probabilities (not the losses), which is why they sum to 1. So, yes, it should hopefully give you low values (i.e. low confidence) for class predictions if you input a garbage photo that is not of any of your model classes. Assuming your model was decently trained, of course : )

See the docs (I linked to it above) for more info.

Yijin

Hi, I just started working through lesson 1 and am confused by something in the notebook https://github.com/fastai/course-v3/blob/master/nbs/dl1/lesson1-pets.ipynb

after the first call to learn.fit_one_cycle(4), the first valid_loss is .357608 and after

learn.unfreeze()
learn.fit_one_cycle(1)

the notebook has a valid_loss of 0.314579 . now isn’t the valid_loss better after unfreezing? If so, I dont understand since unfreezing would loose all the resnet weights as described in about 1hr 20m of https://course.fast.ai/videos/?lesson=1?

1 Like

Hi all,

What is the SOTA accuracy for the Oxford Pet dataset?

I am not sure if I am correct, but unfreezing logically should not change the weights to random numbers. It should make it possible to use the RESNET weights as a base point and then retrain the model (so, even after one epoch you may see improvement).

1 Like

Hello fastai community,
I am struggling around this issue. I have looked up in the forums but don’t seem to find a solution for that.
I have trained a model which I properly saved in ‘/data/models/’ folder. Restarting the kernel and attempting to load the saved model: learn.load(‘model_name’) tells me: NameError: name ‘learn’ is not defined .

How to load that model without retraining it from the very start ?

Thank you in advance.