enter preformatted text here
I am creating a model which does multi-class classification, and I tried to optimize it by using weighted loss.
My dataset contains 7 classes. Here is the number of data points I have for each:
MEL: 1113
NV: 6705
BCC: 514
AKIEC: 327
BKL: 1099
DF: 115
VASC: 142
Could the model be “exploiting” this weighted loss by only returning “AKIEC” every time?
In other words, I by making certain classes “more wrong”, is it making those classes “more right” and other ones “less wrong”?
(not sure why it isn’t returning VASC every time, but AKIEC is what I observed)
Here is the output my model gave on a “MEL” image:
[1.9501211e-02, 8.6555272e-02, 7.0136093e-02, 5.3331017e-02, 7.6896048e-01,
1.2218184e-03, 2.9415233e-04]
And here is the weighted loss weights my model used:
{0: 0.888866699950075, 1: 0.3305042436345482, 2: 0.9486769845232151, 3: 0.9673489765351972, 4: 0.8902646030953569, 5: 0.9885172241637543, 6: 0.9858212680978532}
This resulted in a categorical cross-entropy loss of ~0.33 and a binary accuracy of ~80% in validation. However, separate testing on individual images suggested otherwise.
And in case if it’s necessary, here is my model code:
def classi(input_shape):
inputs = layers.Input(shape=input_shape)
vgg19 = k.applications.VGG19(include_top=False, weights="imagenet", input_tensor=inputs)
x = vgg19(inputs, training=False)
x = layers.Conv2D(64, 3, padding="same")(x)
x = layers.Activation("relu")(x)
x = layers.BatchNormalization()(x)
#classi layers
for filters in [96, 128, 256]:#, 320]:#, 512]:#, 1024, 2048]:
x = layers.Conv2D(filters, 3, padding="same")(x)
x = layers.Activation("relu")(x)
x = layers.BatchNormalization()(x)
x = layers.Conv2D(filters, 3, padding="same")(x)
x = layers.Activation("relu")(x)
x = layers.BatchNormalization()(x)
x = layers.MaxPool2D(3, strides=2, padding="same")(x)
#output
x = layers.Dropout(rate=0.3)(x)
x = layers.Flatten()(x)
x = layers.Dense(128, activation="sigmoid")(x)
output = layers.Dense(7, activation="softmax")(x)
model = k.Model(inputs=inputs, outputs=output, name="classification")
return model
My model was trained with:
batch_size=8
steps_per_epoch = 10015//batch_size
epochs = 60
Is the problem here because of my weighted loss, or is my model just not “good” enough? (not trained enough, too few layers…) Or does it seem like a bug/logic error in my code?