tensorflow: tf.keras computes incorrect loss values with 3+D data
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
Yes. For a minimal example, run
from tensorflow import keras
layer = keras.layers.Input(shape=(1, 1, 1))
model = keras.models.Model(inputs=layer, outputs=layer)
model.compile(optimizer='adam', loss='poisson', metrics=['poisson'])
data = [[[[[1]]], [[[2]]], [[[3]]]]]
model.fit(x=data, y=data, batch_size=2, verbose=1, epochs=10)
and observe that loss and poisson values are different, and loss values vary:
Epoch 1/10
3/3 [==============================] - 1s 236ms/sample - loss: 0.6740 - poisson: 0.4393
Epoch 2/10
3/3 [==============================] - 0s 2ms/sample - loss: 0.6740 - poisson: 0.4393
Epoch 3/10
3/3 [==============================] - 0s 40ms/sample - loss: 0.5452 - poisson: 0.4393
Epoch 4/10
3/3 [==============================] - 0s 96ms/sample - loss: 0.5452 - poisson: 0.4393
Epoch 5/10
3/3 [==============================] - 0s 1ms/sample - loss: 0.9772 - poisson: 0.4393
Epoch 6/10
3/3 [==============================] - 0s 2ms/sample - loss: 0.6740 - poisson: 0.4393
Epoch 7/10
3/3 [==============================] - 1s 201ms/sample - loss: 0.6740 - poisson: 0.4393
Epoch 8/10
3/3 [==============================] - 0s 2ms/sample - loss: 0.6740 - poisson: 0.4393
Epoch 9/10
3/3 [==============================] - 0s 999us/sample - loss: 0.9772 - poisson: 0.4393
Epoch 10/10
3/3 [==============================] - 1s 327ms/sample - loss: 0.9772 - poisson: 0.4393
-
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
-
TensorFlow installed from (source or binary):
pip install tensorflow
-
TensorFlow version (use command below): v1.13.0-rc1-19-gc865ec5621, 1.13.0-rc2
-
Python version: 3.7.2 x64
-
CUDA/cuDNN version: n/a
-
GPU model and memory: n/a
Describe the current behavior
When fitting a model with loss="poisson"
, I would expect reported loss
and poisson
values to be identical.
Describe the expected behavior
loss
values are incorrect. They vary from epoch to epoch.
Code to reproduce the issue See above.
Other info / logs
More code examples and investigations at https://stackoverflow.com/q/54802328/880783
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (4 by maintainers)
+1
same problem
@oO0oO0oO0o0o00 I have the same strange problem.
I have a similar problem. I have written my own test_step(self, data):
during the validation of my model in the fit call, I get these outputs for the validation:
I wonder why val_loss is not the same as val_student_loss, since they are supposed to be the same. When I call model.evaluate() after training, val_loss and val_student_loss are the same. I noticed that when the batch size for my generator is equal to the size of the dataset, the correct results are calculated. The generator is called in a tf.keras.utils.Sequence Object which is used for the validation data. I assume that the output is calculated based on the last batch only.