I am in need of help, my keras model almost always predicts the same thing. My loss and val_loss both converge to about .6 and .4 respectively, which seems odd, but I have tried so many different methods from dropout, augmentation, standardization, tuning, etc etc. but nothing is working.
datagen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
reduce_lr = tf.keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=2, mode="auto", min_delta=0.0001, cooldown=0, min_lr=0)
train_generator = datagen.flow(X, y_train_array)
val_generator = datagen.flow(train_array_val, y_val_array)
pred_generator = datagen.flow(train_array_val, shuffle=False)
initializer = tf.keras.initializers.HeNormal()
imgModel = models.Sequential([
layers.Input(shape=(128, 128, 3)),
layers.RandomFlip("horizontal"),
layers.RandomZoom(.2),
layers.RandomRotation(0.2),
layers.Conv2D(64, kernel_size=(3, 3), activation='relu', kernel_initializer=initializer),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(32, kernel_size=(3, 3), activation='relu', kernel_initializer=initializer),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(64, kernel_size=(3, 3), activation='relu', kernel_initializer=initializer),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Flatten(),
layers.Dense(128, activation='relu', kernel_initializer=initializer, input_dim=81),
layers.Dropout(0.2),
layers.Dense(128, activation='relu', kernel_initializer=initializer),
layers.Dropout(0.2),
layers.Dense(64, activation='relu', kernel_initializer=initializer),
layers.Dropout(0.2),
layers.Dense(32, activation='relu', kernel_initializer=initializer),
layers.Dropout(0.2),
layers.Dense(1, activation='linear')
])
imgModel.compile(optimizer=Adam(learning_rate=0.001), loss='huber', metrics=['mae'])
history = imgModel.fit(train_generator, epochs=300, shuffle=True, batch_size=32, validation_data=val_generator, callbacks=[early_stopping, reduce_lr])
predictions = imgModel.predict(pred_generator)
I am trying to predict a trait between 0.0 and 5.0 from an image dataset of 9500. The dataset is correctly loading which I have checked and is in the correct order to assign each image their trait. I’ve tried using Datagen, without datagen (and yes I’m rescaling by 1/255), with and without standardization, different dense layers, different conv layers, and none of it is working. I’ve tried using pre-trained models as well with no luck. Please help!
Once it reaches its ‘stopping point’ then it doesn’t seem to matter how many epochs, it stays around the same loss. Then it predicts and I see the predictions are barely different. Here is the intended val prediction and the actual prediction below.
Predictions
EvanAbrahamson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.