ValueError: Shapes (None, 1) and (None, 4) are incompatible - Covid-19 and Pneumonia Classification with Deep Learning

Hi, I’m getting an error in line 49 at validation_steps. It is something wrong with input shape but for now I cannot figure it out. Could someone help me?

course link: https://www.codecademy.com/paths/build-deep-learning-models-with-tensorflow/tracks/dlsp-classification-track/modules/dlsp-classification-challenge-project/projects/covid-19-and-pneumonia-deep-learning-classification

Code:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from sklearn.model_selection import train_test_split

from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras import layers

import matplotlib.pyplot as plt
import app

training_data_generator = ImageDataGenerator(rescale = 1.0/255)
data_generator = ImageDataGenerator()

print(training_data_generator.dict)

training_iterator = training_data_generator.flow_from_directory(directory = “augmented-data/train”,
class_mode = “sparse”,
color_mode = “grayscale”,
target_size = (256,256),
batch_size = 32)

validation_iterator = training_data_generator.flow_from_directory(directory = “augmented-data/test”,
class_mode = “sparse”,
color_mode = “grayscale”,
target_size = (256,256),
batch_size = 32)

model = tf.keras.Sequential()
model.add(tf.keras.Input(shape=(256, 256, 1)))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(16, activation = “relu”))
model.add(tf.keras.layers.Dense(4, activation=“softmax”))

model.summary()

model.compile(
optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
loss=tf.keras.losses.CategoricalCrossentropy(),
metrics=[tf.keras.metrics.CategoricalAccuracy(),tf.keras.metrics.AUC()])

model.fit(
training_iterator,
steps_per_epoch = 5,
epochs = 8,
validation_data = validation_iterator,
validation_steps = 5
)

Thanks in advance :slight_smile: