Lesson 2 discussion


Hi Jeremy,

A question about the operation of Jupyter notebook.

Near the end of the first part,
I noticed you can hide the content below a header and later on you can expand it.
How did you do that, what did you type?



Hi, I have two questions about the linear model example at the beginning of the Lesson 2 notebook.

  1. Why doesn’t the loss estimate of the last fit iteration match the loss of the evaluated model? I think this must be because the loss is calculated slightly differently, but it’s not obvious to me from the documentation how this could be. Or maybe it is because of dropout? [edit: found answer to this one above]

  2. Why don’t the parameter estimates have a similar level of accuracy as the loss estimate? For how small the loss estimate is I would expect the parameters estimates to maybe not be exactly correct, but much closer than they are. For example, after 10 fit iterations my parameter estimates are off by ~0.005, while my loss is ~e-6. My guess is that the way the loss is calculated averages across the error induced by the parameter estimation errors and thus is reduced.

Many thanks

(Partha Roy) #277

Hi All,

Sorry but I am getting the below error while trying to open lesson1 notebook

Unreadable Notebook: /home/ubuntu/lesson1.ipynb NotJSONError('Notebook does not appear to be JSON: ‘\n\n\n …’,)

Looks like the file is getting downloaded as HTML.

Can anybody please advise ?


I went to https://github.com/fastai/courses , then clicked “clone or download”, and “download ZIP”.

(Partha Roy) #279

Thanks so much !! It worked.

(Ravi) #280

restarting jupyter notebook is not required; just restart the kernal of that open notebook from the Kernal menu.

(Fenil Suchak) #281

Oh yea! , thanks its SGD , I forgot , was considering full batch gradient descent, thanks!

(Svetlin Stefanov) #282

So why should we use a lower learning rate if training more layers?

(WG) #283

I believe it is so that we don’t overstep our move down via SGD.

We are dealing with an already pretty good fitted model. If the learning rate is too big, we could be jumping around in our path downwards which could mean that our results get worse. A smaller learning rate recognizes we are pretty close to a good solution and tells SGD to take little steps, thus mitigating that problem.


A question about the operation of Jupyter notebook.

Near the end of the first part of the video,
I noticed you can hide the content below a header and later on you can expand it.
How did you do that, what did you type?


try type ‘o’


nothing happens after typing ‘o’.

(Andrea de Luca) #287

Hi! Apologies in advance if my question is inappropriate or if this is not the place where it should be posted.

Anyway, I’m referring to statefarm-sample.ipynb, where a validation set and a sample are created for the State Farm dataset (which comprises just train and test in its vanilla version).

The notebook begins by entering the train directory, then creates the appropriate directories. Note that at no point a valid/ folder is created in the dataset root (rather it is only created in sample/).
Then, the script generated the sample set by shuffling train, picking 1500 imgs, and copying them into sample/train.

Immediately afterwards (we still are in dataset-root/train/), the following magic command is issued:

%cd …/valid/

But no such folder exists, since the original dataset didn’t have a validation dir.

So, I gather I have NOT to reshuffle my ‘g’. Instead, I should just pick the following 1000 images, create a dataset-root/valid/ folder, and copy those images in it.

Am I right?

(Navin Kumar) #288


I was following the notebook of lesson2. I could not understand certain code areas. attaching the screen shots:

Here I believe val_classes is assigned the classes of the validation batch val_batches. Its intuitive…
But where can I get the documentation that the attributes of the object val_batches has??

  1. Similarly
    model.fit_generator uses the arguments samples_per_epoch = batches.n .
    How can i know that batches.n is what should be assigned to sample_per_epoch?

I tried to see the keras documentation mentioned in the FastAI wiki page (http://wiki.fast.ai/index.php/Main_Page pointing to

I tried looking in https://faroit.github.io/keras-docs/1.1.1/preprocessing/image/ . Even though that page is a great tutorial of how to use those API’s I couldn’t get the info what I wanted…

Even though the tab operator of jupyter notebook gives options of different attributes I do not know how to get info what those represent.

any ideas on this…


(Callum Yap) #289

Hey fam, I’m running into this error when I try to create my validation and sample set. Does anyone know how to fix it? Thanks


get_batches() calls image.ImageDataGenerator().flow_from_directory() as in vgg16.py, which returns a
DirectoryIterator object. And you can see classes is one of its attributes.
Check file: keras/preprocessing/image.py in keras github.

You can find fit_generator() models.py in keras/models.py code as well, and you can see what input arguments are needed.

(Navin Kumar) #291

thanks @nzhang . Seen the files suggested by you. got the info needed.

Need to dig into the code with some knowledge of python to decipher what the attributes of the DirectoryIterator object contains…

I believe there is no documentation yet in keras website where I can find what each attribute of the DirectoryIterator represent… Am i right??
By the way, the keras documentation is excellent…


(Sambhavi) #292


I did AWS setup as told by Jeremy and initially used a t2.micro instance to get a hang of AWS.

I was able to successfully execute Lesson1 code in my local laptop itself. I was able to run vgg.test without any hassles. Later moved to a p2.xlarge instance. Tried to execute Dogs Vs Cats Redux and do a kaggle submission. Am unable to go past batches, preds = vgg.test(test_path, batch_size = 64).

It gives me the following error:
imageimage.png1116x268 12.3 KB
I took utils.py, vgg16.py, vgg16bn.py from github. For whatever reasons, copy link address and wget saved .py files as .html. So I did a cat > utils.py and pasted contents from git. I’d missed the line return test_batches in vgg.test method initially. I figured that out and corrected. But no use.

I initially ran 3 epochs, but since I wanted to get this up and running, I changed to 1 epoch and re-executed. Noticed below in ft0.h5 under results folder

imageimage.png1116x268 12.3 KB
But I don’t see any error or warning message in notebook for that cell execution. Am sure something is wrong.

Went through all possible discussions in Lesson1 and Lesson2 forum, but looks like none has faced this.

Would somebody be able to help me ? Dying to make my 1st kaggle submission :slight_smile: Thanks in advance.

Unknowingly, opened a new discussion topic. Below is the link which has snapshots of my error messages.


I am not aware of documentation for attributes of the DirectoryIterator. Source code is good enough :slight_smile:


Might be directory setup. Your images should be under: