CNN W 1 Programming Validation_data

My code passes all checkpoints, including splitting the data correctly. During model.fit_generator, my code runs the train_generator just fine, but when it reaches validation_data = validation_generator, it gives me the following error:

ValueError: A target array with shape (10, 1) was passed for an output of shape (None, 17, 17, 1) while using as loss binary_crossentropy. This loss expects targets to have the same shape as the output.

Could you please help debug?
Below is my code and a screenshot of the error message.

TRAINING_DIR = ‘/tmp/cats-v-dogs/training’
train_datagen = ImageDataGenerator(rescale = 1./255.)
train_generator = train_datagen.flow_from_directory(TRAINING_DIR,
target_size = (150,150),
batch_size = 10,
class_mode = ‘binary’)

VALIDATION_DIR = ‘/tmp/cats-v-dogs/testing’
validation_datagen = ImageDataGenerator(rescale = 1./255.)
validation_generator = validation_datagen.flow_from_directory(VALIDATION_DIR,
target_size = (150,150),
batch_size = 10,
class_mode = ‘binary’)

Hi @JeainnyKim,

That’s weird… How did you define your model? Maybe problem is there.


You’re totally right. I forgot the Flatten() layer! :relaxed: