sepehr
(Sepehr Akhavan)
January 31, 2017, 4:09am
#1
Hi,
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,
-Sepehr
2 Likes
Gelu74
(Angel)
January 31, 2017, 3:11pm
#2
@sepher have you (re)compiled the model?
sepehr
(Sepehr Akhavan)
January 31, 2017, 8:21pm
#3
Hi @Gelu74 ,
Yes, I did using this line:
model.compile(optimizer=opt, loss='categorical_crossentropy',
metrics=['accuracy'])
Gelu74
(Angel)
January 31, 2017, 8:42pm
#4
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 ?
nimrack
(Ronald Teo)
January 31, 2017, 9:38pm
#5
@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 )
14 Likes
sepehr
(Sepehr Akhavan)
February 1, 2017, 1:08am
#6
@nimrack Awesome. That solved the issue. Thanks a lot.
1 Like
sepehr
(Sepehr Akhavan)
February 1, 2017, 1:08am
#7
Thanks for your help. Ronald’s solution of changing N to a lower case n actually solved the issue.
1 Like
Jiaxiang
(JiaxiangZheng)
March 30, 2017, 5:42pm
#8
Thanks, this really helps me.
sanjeev
(Sanjeev Sreetharan)
April 14, 2017, 6:00pm
#9
Thanks - ran into the same issue
Thanks, it helped me too.
rbwendt
(Ben Wendt)
August 22, 2017, 2:49pm
#11
So what happened here? Did the API change?
1 Like
I’m very curious about the underlying issue too!
cholo
(Jaime)
August 31, 2017, 3:34am
#13
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.
2 Likes
gopi34
(Gopi)
October 17, 2017, 11:27am
#15
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 ?
willc
November 6, 2017, 5:52am
#16
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’.