The tensorflow tutorial at this link (see "train the model" section) shows that it is possible to provide a dataset (data, label) to tf.keras.model.fit. However, when I assign my dataset to val_data, as shown below, the loss on the validation data is 0, irrespectively of the state of the training (see graph below). ¨
history = model.fit(
train_ds,
validation_data=val_ds,
epochs=EPOCHS,
verbose=1,
)
IMAGE: Result of training from history, the validation loss is stuck at 0
This issue shows that this problem happens when the val_data is presented in the form of an array [x_val, y_val], instead of a tuple (x_val, y_val). However, in my case, I am providing a dataset, exactly as the tensorflow tutorial above does.
I am using tensorflow 2.1.
My dataset contains tuples structured as described below:
(<tf.Tensor: shape=(batch_size, 128, 128, 3), dtype=uint8, numpy=
array>, <tf.Tensor: shape=(batch_size, 10), dtype=float32, numpy=
array>)
The first is the image, and the second is the label (in this case I have 10 values per image as label).
Does anyone know why I get constant 0 validation loss in the history? How can I make it work? --> see update below
UPDATE:
It seems that this problem only happens when the validation batch size is different than the training batch size. I also noticed that for some batch sizes the validation loss is not exactly zero, but is still close to zero and much lower than the training loss. If the batch size of the validation dataset is set as equal to the batch size of the training dataset everything works correctly. I am now wondering why this happens.