(Deep Learner) #1

I am getting the following error when I try to run the finetune method as shown in the Lesson 1 notebook.

‘DirectoryIterator’ object has no attribute ‘nb_class’

Tab completion on batches shows num_classes and not nb_classes.

Anyone face similar issue ?

(Ravi Teja Gutta) #2

Hi @deepdreams, what keras version are you using ? some of the methods/properties were deprecated for keras2.Part1 was taught in 1.2

(Deep Learner) #3

Thanks. Yeah, i had to modify the code a little bit to make it work. I am on Keras version 2.x. On a different note, are you running in the cloud or have set up everything locally.


Hey @deepdreams, would you mind sharing the code tweak you made to allow Keras v2 to work? I think it might help me. Thanks.

(Deep Learner) #5

Most of the changes need to be done in file. batches/val_batches/test_batches objects no longer have nb_class and nb_samples. These have been replaced with num_class and samples

If you don’t want to change, you can add something similar to the following in your main notebook.

(Deep Learner) #6

If you want to modify, her are some examples where code would have to change

Updated self.ft(batches.nb_class) to self.ft(batches.num_class)

Updated batches.nb_sample to batches.samples and val_batches.nb_sample to val_batches.samples

(Sathya Pradeep) #7


I am getting following when i execute
the following


AttributeErrorTraceback (most recent call last)
in ()
4 #val_batches.nb_class = val_batches.num_class
5 #val_batches.nb_sample = val_batches.sample
----> 6 vgg.finetune(batches)

/home/nbuser/courses/fastai/deeplearning1/nbs/vgg16.pyc in finetune(self, batches)
180 “”"
181 #self.ft(batches.nb_class) # commented this line due to error
–> 182 self.ft(batches.num_class)
183 classes = list(iter(batches.class_indices)) # get a list of all the class labels

AttributeError: ‘DirectoryIterator’ object has no attribute ‘num_class’

can someone help ?


Hi Pradeep,

Were you able to find a solution to this issue? I am facing the exact same issue. FYI, I am running to code on a local machine.

SOLVED: My bad. The path I had given was not correct.

Edit: I still have the same issue.

(Navin Kumar) #9

@saagr, which version of keras are running, part 1 of the course uses keras 1.1.0.

If you are using AWS setup as mentioned by jeremy the code should run without any modifications


@gnavink: I am using the latest keras version - 2.1.1. I have made changes to the utils and vgg16 files as recommended here and this thread.

I am not running it on AWS. I wanted to run it on my local machine.

(j.w) #12

same problem after modification.still can’t figure it out

(j.w) #13

I too am running it on my local PC and can not get rid of the effor of “AttributeError: ‘DirectoryIterator’ object has no attribute ‘num_class’”

(j.w) #14

figured it out that in Keras 2.1 we should use 'num_classes’ instead of ‘num_class’. Hope this will help for you.


Yes. This helped! Thanks.