Reputation: 43
I was working through the Keras implementation of Age and Gender Detection model described in the research paper Age and Gender Classification using Convolutional Neural Networks'. It was originally a Caffe model but I thought to convert it to Keras. But while I was training the model, the accuracy of the model got stuck around 49 - 52%. It means that the model is not learning at all. Also, the loss can be seen exponentially increasing and at times becomes nan. I was training on google collab with GPU hardware accelerator.
My input was a folder of images whose labels are in its file name.I loaded all the images as a numpy array and labels were a collection of 10 elements (2 for gender and 8 classes for 8 different age groups as described in the paper).
model = Sequential()
model.add(Conv2D(96,(7,7),
activation= 'relu',
strides= 4,
use_bias= 1,
bias_initializer= 'Zeros',
data_format= 'channels_last',
kernel_initializer = RandomNormal(stddev= 0.01),
input_shape= (200,200,3)))
model.add(MaxPooling2D(pool_size= 3,
strides= 2))
model.add(BatchNormalization())
model.add(Conv2D(256,(5,5),
activation= 'relu',
strides= 1,
use_bias= 1,
data_format= 'channels_last',
bias_initializer= 'Ones',
kernel_initializer = RandomNormal(stddev= 0.01)
))
model.add(MaxPooling2D(pool_size= 3,
strides= 2))
model.add(BatchNormalization())
model.add(Conv2D(384,
(3,3),
strides= 1,
data_format= 'channels_last',
use_bias= 1,
bias_initializer= 'Zeros',
padding= 'same',
kernel_initializer = RandomNormal(stddev= 0.01),
activation= 'relu'))
model.add(MaxPooling2D(pool_size= 3,
strides= 2))
model.add(Flatten())
model.add(Dense(512,
use_bias= 1,
bias_initializer= 'Ones',
kernel_initializer= RandomNormal(stddev= 0.05),
activation= 'relu'))
model.add(Dropout(0.5))
model.add(Dense(512,
use_bias= 1,
bias_initializer= 'Ones',
kernel_initializer= RandomNormal(stddev= 0.05),
activation= 'relu'))
model.add(Dropout(0.5))
model.add(Dense(10,
use_bias= 1,
kernel_initializer= RandomNormal(stddev= 0.01),
bias_initializer= 'Zeros',
activation= 'softmax'))
model.compile(loss= 'categorical_crossentropy', metrics= ['accuracy'], optimizer= SGD(lr= 0.0001, decay= 1e-7, nesterov= False))
model.summary()
Inputs to the model were shuffled:
X_train, X_test, y_train, y_test = train_test_split(images,labels,test_size= 0.2,shuffle= True, random_state= 42)
You can see my training results here I have used correct optimizers and correct initializers along with biases to prevent vanishing gradients.
Upvotes: 3
Views: 1195
Reputation:
Would suggest to follow the below approach to improve the accuracy of the model -
Hope I have answered your question. Happy Learning!
Upvotes: 1