Lesson 2 - fit_model()

I’m trying to run the the notebook for lesson 2. Under the topic “Modifying the model”, I tried to run the code to retrain the new last layer of the VGG model. When I run:

fit_model(model, batches, val_batches, nb_epoch=2)

I get the error below:

AttributeError: 'NumpyArrayIterator' object has no attribute 'N'

Jeremy had a note saying: “Careful! Now that we’ve modified the definition of model, be careful not to rerun any code in the previous sections, without first recreating the model from scratch! (Yes, I made that mistake myself, which is why I’m warning you about it now…)”

I thought maybe I should first run:

vgg = Vgg16()
model = vgg.model

and once I redefined the model, continue, but I still get the same error. Does anybody know how to fix this error?

Thanks for your help,


@sepher have you (re)compiled the model?

Hi @Gelu74,
Yes, I did using this line:

 model.compile(optimizer=opt, loss='categorical_crossentropy', 

mmm… it is hard to debug without knowing the exact steps you have taken, especially in defining batches

re-running the notebook form the begining should solve the issue, doesn’t it ?

@sepehr try using lowercase ‘N’ instead of uppercase

def fit_model(model, batches, val_batches, nb_epoch=1):
model.fit_generator(batches, samples_per_epoch=batches.n, nb_epoch=nb_epoch, validation_data=val_batches, nb_val_samples=val_batches.n)


@nimrack Awesome. That solved the issue. Thanks a lot.

1 Like

Thanks for your help. Ronald’s solution of changing N to a lower case n actually solved the issue.

1 Like

Thanks, this really helps me.

Thanks - ran into the same issue

Thanks, it helped me too.

So what happened here? Did the API change?

1 Like

I’m very curious about the underlying issue too!

Thanks! Helped me too!

In my scenario it was the other way around, code from git was using n and I had to replace with N.


This helped me as well!

I also ran into this same issue but changing N to lowecase n doesn’t solve my issue, I couldn’t figure out what’s happening ?

Same here - had to change batches.n to batches.N :

Thanks this helped me. Curiously though, I had to do the exact opposite: change ‘n’ by ‘N’.