I want to classify 6 different categories of x-ray scans, What's wrong with the code?
model = Sequential()
model.add(Conv2D(256, (3, 3), input_shape=X.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Dense(6))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
model.fit(X, y, batch_size=32, epochs=3, validation_split=0.1)
The shapes of input are: (50, 50, 1)
Should I remove one of the MaxPooling layers?
I've seen it's good manners here to post the traceback aswell, so here it is:
Epoch 1/3
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
(...)
ValueError: in user code:
C:\Python38\lib\site-packages\tensorflow\python\keras\engine\training.py:571 train_function *
outputs = self.distribute_strategy.run(
C:\Python38\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:951 run **
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
C:\Python38\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2290 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
C:\Python38\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2649 _call_for_each_replica
return fn(*args, **kwargs)
C:\Python38\lib\site-packages\tensorflow\python\keras\engine\training.py:532 train_step **
loss = self.compiled_loss(
C:\Python38\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:205 __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
C:\Python38\lib\site-packages\tensorflow\python\keras\losses.py:143 __call__
losses = self.call(y_true, y_pred)
C:\Python38\lib\site-packages\tensorflow\python\keras\losses.py:246 call
return self.fn(y_true, y_pred, **self._fn_kwargs)
C:\Python38\lib\site-packages\tensorflow\python\keras\losses.py:1527 categorical_crossentropy
return K.categorical_crossentropy(y_true, y_pred, from_logits=from_logits)
C:\Python38\lib\site-packages\tensorflow\python\keras\backend.py:4561 categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
C:\Python38\lib\site-packages\tensorflow\python\framework\tensor_shape.py:1117 assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (None, 1) and (None, 6) are incompatible