I am training a model for image classification, my training accuracy is increasing and training loss is also decreasing but validation accuracy remains constant.
Here is my code:
from keras.applications.vgg19 import VGG19 model= VGG19(include_top=False, weights='imagenet',
input_tensor=None, input_shape=(224,224,3), pooling=None, classes=1000) x=model.output
x=Conv2D(filters=1024,kernel_size=2)(x)
x=MaxPooling2D()(x)
x=Flatten()(x)
x=Dense(1024,activation='relu')(x)
x=BatchNormalization(axis=1)(x)
x=Dropout(0.8)(x)
x=Dense(64,activation='relu')(x)
x=Dense(4,activation='softmax')(x)
model = Model(inputs=model.input,outputs=x)
for layer in model.layers[:12]:
layer.trainable = False
for layer in model.layers[12:]:
layer.trainable=True
opt = Adam(lr=0.0001, decay=1e-6)
model.compile(loss='sparse_categorical_crossentropy',
optimizer=opt, metrics=['accuracy'])
checkpoint_path="/content/drive/My Drive/Model/model_vgg19_6.h5"
checkpoint = ModelCheckpoint(checkpoint_path, monitor="val_acc", mode="max",
save_best_only = True,verbose=1)
reduce_lr = ReduceLROnPlateau(monitor = 'val_acc', mode="max", factor = 0.7,
patience = 5, verbose = 1, min_delta =0.00001)
earlystop = EarlyStopping(monitor = 'val_acc', mode="max", min_delta = 0, patience = 30, verbose = 1,
restore_best_weights = True)
callbacks = [reduce_lr,checkpoint]
model.fit_generator(aug_train, steps_per_epoch=int((len(data_x)/128)+1), validation_data=
(val_x,val_y), validation_steps=int((len(val_x)/128)+1), workers=-1,
use_multiprocessing=True, shuffle=True, epochs=300, callbacks=callbacks )