0

I'm learning neural networks and I created a CNN that based on a dataset with faces determine whether someone is of an infant, a teenager, young adult, adult... Basically is determines your age category.

The results I get regarding val_loss and val_mae are ok (~0.5 val loss, ~0.5 val mae), however, my val_accuracy is barely changing. It's usually stuck at 0.088 and barely changes at all. And even if changes, it goes back to 0.088 in the next epoch. It changes after 10 or so epochs, but it starts decreasing.

I'm not sure what could be causing this. Can you help me?

I'm doing it for the first time and the model is mine, so I'm not sure whether I created it correctly.

This is my neural network:

x_train,x_validation,y_train,y_validation = train_test_split(pictures,ages,train_size=.85, shuffle=True,random_state=100) 

input = Input(shape=(200,200,3)) 
conv1 = Conv2D(filters=64,kernel_size=(3,3),activation="relu")(input)
maxPool1 = MaxPool2D((2,2))(conv1)
conv2 = Conv2D(filters=128,kernel_size=(3,3),activation="relu")(maxPool1)
maxPool2 = MaxPool2D((2,2))(conv2)
conv3 = Conv2D(filters=256,kernel_size=(3,3),activation="relu")(maxPool2)
maxPool3 = MaxPool2D((2,2))(conv3)
conv4 = Conv2D(filters=512,kernel_size=(3,3),activation="relu")(maxPool3)
maxPool4 = MaxPool2D((2,2))(conv4)
conv5 = Conv2D(filters=1024,kernel_size=(3,3),activation="relu")(maxPool4)
GAP = tf.keras.layers.GlobalAveragePooling2D()(conv5)

age = Dense(64,activation="relu")(GAP)
age = Dense(32,activation="relu")(age)
drop=Dropout(rate=.4, seed=123)(age)
age = Dense(1,activation="linear")(drop)

model = Model(inputs=input,outputs=age)
model.compile(optimizer="adam",loss=["mse","sparse_categorical_crossentropy"],metrics=['mae','accuracy'])
Igor
  • 1
  • This has been asked hundreds of times, it makes no sense to use accuracy (a classification metric) for regression. – Dr. Snoopy Jan 26 '22 at 20:25
  • @Dr.Snoopy How is it a regression? I'm literally using classes for ages. Am I missing something? – Igor Jan 26 '22 at 20:32
  • You have a linear activation at the output, and a mean squared error loss, the model is configured to perform regression, not classification. – Dr. Snoopy Jan 26 '22 at 20:36
  • @Dr.Snoopy That's why I'm asking, I didn't know that. But my goal is to perform classification, I mentioned that in the question. – Igor Jan 26 '22 at 20:38
  • @Dr.Snoopy What activation should I have at output for classification? – Igor Jan 26 '22 at 20:39
  • @Dr.Snoopy Also if I remove MSE from loss function, I get NAN as loss and mae. – Igor Jan 26 '22 at 20:40
  • This is the kind of stuff you learn in a neural networks course, but just for sake of completeness, you need to use a softmax activation with neurons equal to the number of classes, and a categorical cross-entropy loss. You also need to have one-hot encoded labels. As you see failing to do any of these will result in a model not learning or producing NaNs. – Dr. Snoopy Jan 26 '22 at 20:49
  • @Dr.Snoopy What do you mean neurons equal to the number of classes? So if I have 5 classes, in my last dense layer I should have 5 neurons? Do I understand correctly? – Igor Jan 26 '22 at 20:58

0 Answers0