Prediction with tensorflow keras I'm trying to predict age from a given picture. I built the model below but the problem is that I'm getting very large loss value with low accuracy while fitting the model.

I think the problem is choosing the wrong loss function (here mean_squared_error). What can be the problem here?

import tensorflow as tf
from tensorflow import keras

X = X.reshape(-1, image_size[0], image_size[1], 1)
model = keras.models.Sequential()

model.add(keras.layers.Conv2D(32, (5, 5), activation='relu', input_shape=X.shape[1:]))
model.add(keras.layers.MaxPooling2D((2, 2)))

model.add(keras.layers.Conv2D(32, (3, 3), activation='relu'))
model.add(keras.layers.MaxPooling2D(2, 2))

model.add(keras.layers.Conv2D(64, (3, 3), activation='relu'))

model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(60, activation='relu'))
model.add(keras.layers.Dropout(0.4))
model.add(keras.layers.Dense(1, activation='softmax'))
model.compile(optimizer='adam', loss=keras.losses.mean_squared_error, metrics=['accuracy'])


model.fit(X, Y, epochs=170, shuffle=True, validation_split=0.1)


As another question, are my layers correct to predict a number for a given picture?
This is the problem: model.add(keras.layers.Dense(1, activation='softmax'))

For predicting real-valued data such as age, it is customary to set the activation as linear or in this case, you can probably use relu.

To illustrate, softmax will create a distribution over the output, in this case the output of the model will be always 1. Since the age is positive definite continuous number, you need an activation that has a range of real numbers >= 0 which the relu activation satisfies.


  As another question , are my layers good to predict a number for given picture ?


The architecture seems reasonable so try changing the model's final activation first.