AttributeError: 'DirectoryIterator' object has no attribute 'nb_class'

(Gertjan Brouwer) #1


I am trying to get the first model to work, which is the vgg16 model, everything looks to load fine and I did not change anything in the file only changed something in the first 6 sentences of the notebook.

This is the code i am currently using:

import tensorflow.contrib.keras as keras
import vgg16; reload(vgg16)
from vgg16 import Vgg16
vgg = Vgg16()
path = '/home/gertjan/Documents/data/'
batches = vgg.get_batches(path + ‘train’, batch_size=64)
val_batches = vgg.get_batches(path + ‘validation’, batch_size=64)
vgg.finetune(batches), val_batches, nb_epoch=2)

When i run this i get the following error:

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

I found the nb_class being called like this : batches.nb_class in the finetune function and I have tried some things but can not figure out why it is not working, any help would be greatly appreciated.

Thanks in advance.

(Gertjan Brouwer) #2

Apparantly the problem was because of keras2, it has name changes for nb_class. In this post there is a solution + some extra information about what changed: Keras 2 Released

(philip) #3

You would need to do the following .First modify VGG
Updated self.ft(batches.nb_class) to self.ft(batches.num_class)
Next update the following .in the function def fit in
batches.nb_sample to batches.samples and val_batches.nb_sample to val_batches.samples

Update for Keras 2.1 - we should use 'num_classes’ instead of ‘num_class’ change the same in Hope this will help for you.