I am receiving a value error when attempting to fit my model to the training set and am unsure how to reshape either my labels or logits to resolve this issue.
The code for the model is below, and for reference:
train_images.image_shape = (256, 256, 3), total of 1611 images
train_images.labels.shape = (1611,)
val_images.image_shape = (256, 256, 3), total of 537 images
val_images.labels.shape = (537,)
I used flow_from_directory to create the DirectoryIterator objects for the training/validation sets and set the class_mode to 'binary'.
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(16, (3,3), activation = 'relu', input_shape = (256, 256, 3)),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Conv2D(32, (3,3), activation = 'relu'),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Conv2D(64, (3,3), activation = 'relu'),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation = 'relu'),
tf.keras.layers.Dense(1, activation = 'sigmoid')
])
model.compile(optimizer = RMSprop(), loss = 'binary_crossentropy', metrics = ['accuracy'])
demo = model.fit(train_images, epochs = 5, validation_data = val_images)
Any advice would be much appreciated, thank you!
EDIT - adding generator code
Generator Code:
train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rescale = 1/255,
validation_split = 0.25
)
train_images = train_datagen.flow_from_directory(
directory = dir_path,
class_mode = 'binary',
target_size=(256, 256),
shuffle = True,
batch_size = 128,
subset = 'training'
)
val_images = train_datagen.flow_from_directory(
directory = dir_path,
class_mode = 'binary',
target_size=(256, 256),
shuffle = True,
batch_size = 16,
subset = 'validation'
)
Found 1611 images belonging to 2 classes.
Found 537 images belonging to 2 classes.