3
$\begingroup$

I am using GTZAN dataset to make a CNN and classify by musical genres.

I'm getting very good results except Val. loss (See Image)

Results

I am processing the audio files using Librosa, obtaining the spectogram and then using the power_to_db function.

This is my CNN Model:

class CNNModel(object):

def __init__(self, config, X):
    self.filters = 32 # number of convolutional filters to use
    self.pool_size = (2, 2)  # size of pooling area for max pooling
    self.kernel_size = (3, 3)  # convolution kernel size
    self.nb_layers = 4
    self.input_shape = (128, 625, 1) # cambiar por x.shape


def build_model(self, nb_classes):

    model = Sequential()
    model.add(
            Conv2D(
                self.filters,
                self.kernel_size,
                padding ='same',
                input_shape = self.input_shape))
    model.add(BatchNormalization(axis=1))
    model.add(Activation('relu'))

    model.add(
            Conv2D(
                self.filters,
                self.kernel_size))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size = self.pool_size))
    model.add(Dropout(0.25))

    model.add(
        Conv2D(
            self.filters + 32,
            self.kernel_size,
            padding ='same'))
    model.add(Activation('relu'))

    model.add(
        Conv2D(
            self.filters + 32,
            self.kernel_size,
            padding ='same'))
    model.add(MaxPooling2D(pool_size = self.pool_size))
    model.add(Dropout(0.25))

    model.add(Flatten())
    model.add(Dense(512))
    model.add(Activation('relu'))
    model.add(Dropout(0.5))
    model.add(Dense(nb_classes))
    model.add(Activation("softmax")) #mirar

    return model

I leave the link of my github in case you want to see the whole code.

https://github.com/xexuew/Music-Genre-Classification

Every song is (128, 625) Shape, I used MinMaxScale to Scale the data.

This is my loss function and my optimizer

loss = losses.categorical_crossentropy,
optimizer = optimizers.SGD(lr=0.001, momentum=0, decay=1e-5, nesterov=True)

I have read about overfitting and that seems to be the cause but I do not know how to solve it at the code level.

Update 1: With Dropout(0.9) I get this results: Results 2 Thank you

$\endgroup$
2
$\begingroup$

You can test with higher values of Dropout (0.5,0.7,0.9) and/or try L1/L2 Regularization to combat overfitting : Keras Regularizers.

Update: You can play with a combination of l1/l2 regularization and dropout for your convolutional and FC layers. Start with low values of lambda (0.001) and increase it thereon. A common practice is to have dropout only in the FC layers, see if it helps your problem.

Also, from the looks of your loss curve, your model probably hasn't converged.You can train it until your validation loss starts going up/becomes stable.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for your answer, I have obtained these results (New Image on the top), can I improve by putting a regularization? I loss value of Accuracy but I think if I put more epochs will be the same. $\endgroup$ – Joseew May 27 '18 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.