I am working on a skin cancer recognition model. I am trying to train my model using keras and tensorflow but I noticed that the val_accuracy doesn't change it's stuck in 54% while the accuracy and loss as well as val_loss are changing. I used pre trained weights for ResNet50 layer then I added other layers and freezed the first layer to train the rest. Here is my model:
model = keras.Sequential()
model.add(ResNet50(include_top=False,input_tensor=None, input_shape=(224,224,3)
,pooling='avg',classes=2,weights=resnet_weights_path))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(BatchNormalization())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(BatchNormalization())
model.add(Dense(1, activation='sigmoid'))
model.layers[0].trainable = False
model.summary()
model.compile(optimizer=SGD(lr=0.001),loss='binary_crossentropy',metrics=['accuracy'])
red_lr= ReduceLROnPlateau(monitor='val_accuracy',patience=3,verbose=1,factor=0.7)
batch_size=64
epochs=150
History = model.fit_generator(datagen.flow(x_train,y_train,batch_size=batch_size),validation_data=(x_val,y_val),
epochs= epochs, steps_per_epoch=x_train.shape[0]//batch_size,verbose=1,callbacks=[red_lr]
)
And here is the log for the trainig:
Epoch 1/150
25/25 [==============================] - 200s 8s/step - loss: 0.1236 - accuracy: 0.9498 - val_loss: 2.0365 - val_accuracy: 0.5470
Epoch 2/150
25/25 [==============================] - 195s 8s/step - loss: 0.1251 - accuracy: 0.9530 - val_loss: 2.0819 - val_accuracy: 0.5470
Epoch 3/150
25/25 [==============================] - 199s 8s/step - loss: 0.1314 - accuracy: 0.9500 - val_loss: 2.1083 - val_accuracy: 0.5470
And so on So if you can see what's wrong with my model please help! Thank you!