I have 3 labels and the task is to label images. One image can have multiple labels. I built my CNN but I'm having issues with the last Dense layer:
model = Sequential()
model.add(Conv2D(32, (3,3), padding='same', activation='relu', input_shape=(32,32,3)))
model.add(Conv2D(32, (3,3), padding='same', activation='relu'))
model.add(MaxPooling2D((2,2)))
model.add(Dropout(.25))
model.add(Flatten())
model.add(Dense(3, activation='sigmoid'))
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(
optimizer=sgd,
loss="binary_crossentropy",
)
model.fit(x_train, y_train, epochs=10)
I one hot encoded my y_train, which has a y_train.shape of (120, 3, 3)
y_train[0]:
array([[1., 0., 0.],
[1., 0., 0.],
[1., 0., 0.]], dtype=float32)
x_train.shape:
(120, 32, 32, 3)
The error that I'm getting is that:
binary_crossentropy
return tf.nn.sigmoid_cross_entropy_with_logits(labels=target, logits=output)
ValueError: `logits` and `labels` must have the same shape, received ((32, 3) vs (32, 3, 3)).
In my last Dense layer, I'm not sure what number to put, as I want to keep activation sigmoid, which I understand is better for multi-label classification.