I'm currently studying about neural network and I'm having problem when try to learn about CNN, I'm trying to train data which contains Spectrogram about music genres. My data consists of 27000 Spectrogram and divided into 3 class (genre). My data splitted in 9:1 ratio for training and validation
Can anyone help me why is the result for my validation loss/accuracy is fluctuating? I'm using MobileNetV2 from Keras and connect it with 3 Dense layers. Here is the snippet of my codes:
train_datagen = ImageDataGenerator(
preprocessing_function=preprocess_input,
validation_split=0.1)
train_generator = train_datagen.flow_from_dataframe(
dataframe=traindf,
directory="...",
color_mode='rgb',
x_col="ID",
y_col="Class",
subset="training",
batch_size=32,
seed=42,
shuffle=True,
class_mode="categorical",
target_size=(64, 64))
valid_generator = train_datagen.flow_from_dataframe(
dataframe=traindf,
directory="...",
color_mode='rgb',
x_col="ID",
y_col="Class",
subset="validation",
batch_size=32,
seed=42,
shuffle=True,
class_mode="categorical",
target_size=(64, 64))
base_model = MobileNetV2(weights='imagenet', include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1025, activation='relu')(x)
x = Dense(1025, activation='relu')(x)
x = Dense(512, activation='relu')(x)
preds = Dense(3, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=preds)
model.compile(optimizer='adam', loss='categorical_crossentropy',
metrics=['accuracy'])
step_size_train = train_generator.n//train_generator.batch_size
step_size_valid = valid_generator.n//valid_generator.batch_size
history = model.fit_generator(
generator=train_generator,
steps_per_epoch=step_size_train,
validation_data=valid_generator,
validation_steps=step_size_valid,
epochs=75)
These are the picture of my validation loss and validation accuracy curve that fluctuating too much
Is there anyway to reduce the fluctuation or to make it better? Am i having overfitting or under fitting problem here? I have tried using Dropout() but it just made it worse. What do i need to do to fix this problem?
Thanks before, Aquilla Setiawan Kanadi.