1

I'm using the multimodal MR image dataset. I don't understand what causes this error during training:

InvalidArgumentError:  logits and labels must have the same first dimension, got logits shape [64,4] and labels shape [9437184]    
sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits 

My code:

conv_base=VGG16(weights='imagenet',include_top=False, input_shape=(192,192,3))
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dense(512,activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(4, activation= 'softmax'))
model.compile(optimizer=optimizers.Adam(lr=3e-5), loss='sparse_categorical_crossentropy', metrics=['acc'])
h=model.fit(X_train, Y_train,batch_size=64,epochs=1,verbose=1,validation_data=(X_val,Y_val))

The shape of X_train is (162,192,192,3).

The shape of Y_train is (162,192,192,4).

Maurice
  • 11,482
  • 2
  • 25
  • 45
Elizabeth
  • 21
  • 2

1 Answers1

0

Thank you Marco Cerliani. For the benefit of community providing solution here

conv_base=VGG16(weights='imagenet',include_top=False, input_shape=(192,192,3))
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dense(512,activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(4, activation= 'softmax'))
model.compile(optimizer=optimizers.Adam(lr=3e-5), loss='categorical_crossentropy', metrics=['acc'])
h=model.fit(X_train, Y_train,batch_size=64,epochs=1,verbose=1,validation_data=(X_val,Y_val))