M. Ungheretti
M. Ungheretti

Reputation: 51

Validation loss is zero on first epoch only

Problem

I am trying to build a regression model in tensorflow using the dataset and keras API's. The target contains quite a lot of zero's and the non-zero values are roughly distributed normally though all are positive.

When I try to create the linear model below I notice that on the first epoch the validation loss and both of the validation metrics are exactly 0, though the training loss and metrics are not. This problem disappears after the first epoch. Though this doesn't keep me from creating the model I still can not explain why this happens and what I might do about it.

Tried so far

What I have unsuccesfully tried to pinpoint where the problem lies:

My code

train = tf.data.experimental.make_csv_dataset(...)
test = tf.data.experimental.make_csv_dataset(...) # a smaller csv file

model = Sequential([
    DenseFeatures(features),
    Dense(1, activation='linear') # we are doing a regression
])
model.compile(
    optimizer='adam',
    loss='mean_squared_error',
    metrics=['mean_squared_error', 'mean_absolute_error']
)
model.fit(train,
          epochs=2, 
          validation_data=test
)

Upvotes: 4

Views: 2752

Answers (1)

Federico Andreoli
Federico Andreoli

Reputation: 465

This is completely normal because normal metrics and validation metrics are computed in different times.

Nomral metrics are computed during the epoch, so you can see what is the loss score and other values that come from the training.

Validation metrics are used to see wether the parameters computed during a certain epoch are good. This means that some of the training data used in a specific epoch (you can specify the percentage) are not used for training, but they're used intead to compute the network accuracy. So theese values are computed at the end of the epoch, when you have a certain parameter configuration.

Upvotes: 1

Related Questions