0

I'm trying to work with a image classification model for gravity waves detection.

So I want to check if there is something I could do to lower validation loss %, or more importantly, increase validation accuracy %.

The dataset is about a total of 460 images, split into

300 images that belong to 2 classes 60 images belonging to 2 classes 100 images belonging to 2 classes

For context, this is the code for pre processing:

batch_size = 32

Data Augmentation:

train_datagen = ImageDataGenerator(
        rescale=1./255,
        shear_range=0.2,
        horizontal_flip=True,
        )

test_datagen = ImageDataGenerator(
        rescale=1./255)

The generator that reads images to generate batches of augmented image data

train_generator = train_datagen.flow_from_directory(
        './train',  target directory
        target_size=(256, 256), images resized to 150x150
        batch_size=batch_size,
        # batch_size=40, 
        class_mode='binary') 


validation_generator = train_datagen.flow_from_directory(
        './validation',
        target_size=(256, 256),
        batch_size=batch_size,
        # batch_size=20, 
        class_mode='binary')


test_generator = test_datagen.flow_from_directory(
        './test',
        target_size=(256, 256),
        # batch_size=batch_size,
        batch_size=batch_size,
        #class_mode=None,
        class_mode= None,
        shuffle=False)

And this is the model used:

from tensorflow.keras.applications.inception_v3 import InceptionV3
import tensorflow as tf

from keras import regularizers


base_model = InceptionV3(input_shape = (256,256,3), include_top = False, weights = 'imagenet')

x = layers.Flatten()(base_model.output)


x = layers.Dense(1024, activation='relu')(x)

x = layers.Dropout(0.2)(x)

x = layers.Dense(1, activation='sigmoid')(x)
 
model = Model(base_model.input, x)

model.compile(optimizer = tf.keras.optimizers.SGD(learning_rate=0.001), loss = 'binary_crossentropy', metrics = ['accuracy'])

fitness = model.fit(        
        train_generator,
        steps_per_epoch= 120,
        epochs = 100,
        validation_data=validation_generator,
        validation_steps= 64)

So far the accuracy and loss % have been around:

Average training accuracy:  0.9237500047683715
Average training loss:  0.17309745135484264
Average validation accuracy:  0.6489999979734421
Average validation loss:  0.9121886402368545

The predicitons have been around:

validation predictions:

(24, 36)

test predictions:

(45, 55)

And the confusion matrix:

Confusion Matrix: 

array([[12, 18],
       [12, 18]])
Gillian
  • 1
  • 2
  • Have you tried training without data augmentations? Also have you tried adjusting the learning rate? The training curve would also be useful to see, if you could upgrade your post with it? – Djinn Jul 07 '22 at 01:54
  • Yes I have tried without data augmentation. Got better results with a learning rate of 0.001, accuracy up to 85%. I tried applying k-fold cross validation to test different results, but anyways, still can't achieve the 90%. – Gillian Jul 10 '22 at 02:36
  • Maybe you need more feature extraction layers? Like more convolutional layer after InceptionV3 possibly. – Djinn Jul 10 '22 at 17:57
  • Please try again by changing the optimizer as 'Adam'. This also depends on the dataset size if you have more dataset size to train the model, the model will learn and predict better. –  Jul 30 '22 at 13:25

0 Answers0