VGG16 and LSTM Model Performance Issues
My model has been performing poor recently and I was wondering what are some things I can do bolster its performance. So far its training ACC is low, and validation is constant and not improving
import copy
import matplotlib.pyplot as plt
import numpy as np
import os
from scipy.ndimage.filters import gaussian_filter
from skimage.transform import rescale
from sklearn.feature_extraction.image import img_to_graph
import shutil
import time
import tensorflow as tf
from tensorflow.compat.v1.losses import softmax_cross_entropy as SCE
from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input
from tensorflow.keras.callbacks import TensorBoard, ModelCheckpoint, LearningRateScheduler, EarlyStopping, CSVLogger
from tensorflow.keras.layers import Flatten, Dense, Dropout, Reshape, Conv2D, MaxPooling2D, LSTM, TimeDistributed,Bidirectional,BatchNormalization,LayerNormalization, ActivityRegularization, GaussianNoise, Activation
from tensorflow.keras.metrics import Accuracy, AUC, BinaryAccuracy, CategoricalAccuracy
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import SGD as tf_SGD
from tensorflow.keras.optimizers import RMSprop, Nadam
from tensorflow.keras.optimizers.schedules import ExponentialDecay, InverseTimeDecay
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.regularizers import L1,L2
My model training accuracy always remains constant, and I have tried adding more layers however it is not improving the validation accuracy always stays constant as well. I have been implementing regularization, and normalization to see if it would perform better however to no avail.
for layer in model.layers[:10]:
layer.trainable = False
cnn = Sequential([])
cnn.add(GaussianNoise(.1))
cnn.add(model)
cnn.add(ActivityRegularization(l2=0.01))
cnn.add(LayerNormalization())
cnn.add(BatchNormalization())
cnn.add(TimeDistributed(Flatten()))
cnn.add(LSTM(8,bias_regularizer= L2(0.01),activity_regularizer= L1(0.01),activation=softmax, return_sequences=True))#activation= tanh,recurrent_activation=sigmoid))(cnn)
cnn.add(LayerNormalization())
cnn.add(BatchNormalization())
cnn.add(Flatten())
cnn.add(Dense(1,kernel_initializer=HeNormal))
cnn.add(Activation(softmax))
initial_learning_rate = 10e1
decay_steps = 1.0
decay_rate = 0.5
learning_schedule = InverseTimeDecay(initial_learning_rate, decay_steps, decay_rate)
def custom_loss(y_true, y_pred):
return SCE(y_true, y_pred)
cnn.compile(loss = custom_loss,
optimizer = tf_SGD(learning_rate =learning_schedule, momentum=.9),#lr_schedule1), #tf_SGD = .25000
metrics= [AUC(num_thresholds=10,from_logits=True,name=auc), Accuracy(name=ACC)])
I have also tried tampering with the Data Augmentation to see if I can lead to better its training.
train_datagen = ImageDataGenerator(
rescale = 1./255,
horizontal_flip = True,
fill_mode = reflect,
shear_range=0.1,
zoom_range = 0.1,
width_shift_range = 0.1,
height_shift_range=0.1,
rotation_range=5,
preprocessing_function= lambda x:np.array(x)
)
test_datagen = ImageDataGenerator(
preprocessing_function=preprocess_input
#rescale = 1./255,
#horizontal_flip = True,
#fill_mode = nearest,
#zoom_range = 0.1,
#width_shift_range = 0.1,
#height_shift_range=0.1,
#rotation_range=5
)
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size = (224, 224),
#batch_size = 10,
class_mode = binary)
validation_generator = test_datagen.flow_from_directory(
validation_data_dir,
target_size = (224, 224),
#batch_size = 10,
class_mode = binary
)
validation_generator.class_indices
```
Category Data Science