Skip to content
Advertisement

Using pretrained model with keras: AttributeError: ‘NoneType’ object has no attribute ‘shape’

I’m running a Keras Neural Network model for a binary classification of images.
I use the first layer of a pretrained VGG16 model and i created the last fully connected layers from the tutorial:
https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

With Tensorflow backend 2.3.1, Python 3.6, Keras 2.4.3

While i’m training my model (using presaved weights) with an ImageDataGenerator, this exception occurs:

JavaScript

That’s my code

JavaScript

The full error message is the following:

JavaScript

Can someone explain me where is the problem and how i can fix it? Thank you

Advertisement

Answer

The error is here:

JavaScript

From the docs:

class_mode: One of “categorical”, “binary”, “sparse”, “input”, or None. Default: “categorical”. Determines the type of label arrays that are returned: – “categorical” will be 2D one-hot encoded labels, – “binary” will be 1D binary labels, “sparse” will be 1D integer labels, – “input” will be images identical to input images (mainly used to work with autoencoders). – If None, no labels are returned (the generator will only yield batches of image data, which is useful to use with model.predict()). Please note that in case of class_mode None, the data still needs to reside in a subdirectory of directory for it to work correctly.

You’re not giving any labels to your model. You seem to have 2 classes so it should be:

JavaScript
Advertisement