0

I'm trying to classify images data of blood and its spo2 value (oxygen percent in blood), spo2 value has 4 classes

X_train.shape => (8969, 224, 224, 3)
y_train.shape => (8969,)

output of model will be the percent of spo2

y_train.shape
>>> array([98, 98, 95, ..., 98, 95, 98])

Model Architecture

X_train = np.array(X_train)
y_train = np.array(y_train)

model = Sequential()
model.add(Conv2D(filters=64 , kernel_size=(3,3), activation='relu' , input_shape = (X_train.shape[1:])))
model.add(MaxPool2D(pool_size=(3,3)))
model.add(Conv2D(filters=32 , kernel_size=(3,3), activation='relu'))
model.add(MaxPool2D(pool_size=(3,3)))
model.add(Dense(units=512 , activation='relu'))  
model.add(Dense(units=128 , activation='relu'))  
model.add(Dense(units=4, activation='softmax')) 

model.compile(optimizer='adam' , loss='categorical_crossentropy' ,  metrics=(['accuracy']))
history = model.fit(X_train , y_train , epochs=5)

error appears when fit the model

ValueError: Shapes (None,) and (None, 24, 24, 4) are incompatible
  • 1
    It might help if you [edit] to include the full error traceback rather than just the last line, as that contains valuable information – G. Anderson Feb 24 '22 at 18:01

1 Answers1

0

This might not be the actual problem, but I got a similar error when I removed the flatten layer on my convolutional network. You are missing a Flatten() layer between the second max pooling layer and the first dense layer. Edit the code like so:

...
model.add(MaxPool2D(pool_size=(3,3)))
model.add(Flatten())
model.add(Dense(units=512 , activation='relu'))  
...

Here is more information about the Flatten layer: What is the role of "Flatten" in Keras?

mbostic
  • 903
  • 8
  • 17