keras
                                
                                
                                
                                    keras copied to clipboard
                            
                            
                            
                        Better error message for Unexpected result of `train_function` (Empty logs). Please use `Model.compile(..., run_eagerly=True)`, or `tf.config.run_functions_eagerly(True)` for more information of where went wrong, or file a issue/bug to `tf.keras`
Hi!
This error message pops up when empty arrays are passed to Model.fit or Model.predict. The solution suggested in the error message does not work and in some sense is not logical. Either the error message should be updated or the mentioned functions should have additional assertions to check for empty input arrays.
Could you please provide some simple reproducible code and the error message which you are getting currently in order to expedite the troubleshooting process. Thanks!
To be precise, this issue popped up in tensorflow==2.7.0 and keras==2.7.0 and their recent versions.
Currently, I have python==3.8.6, tensorflow==2.8.0 and keras==2.8.0.
The minimal code to reproduce the issue:
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
import numpy as np
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
Y = np.array([0, 1, 1, 0])
model = Sequential()
model.add(Dense(16, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='Adam', loss='binary_crossentropy', metrics=['acc'])
idx = []
model.fit(X[idx], Y[idx])
                                    
                                    
                                    
                                
This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.
i have the same issue and i didnt know what is the solution
Fix this error message to something more logical. Asap
Can you check also this case: https://discuss.tensorflow.org/t/text-based-tensorflow-unexpected-result-of-train-function-empty-logs/11075
Hi all,
Is there any solution to this issue?
Thank you in advance.
Hi all,
Is there any solution to this issue?
Thank you in advance.
Did you find a solution to this?
Any update on a different (more informative) error message?
I've been working with TF for a while now and just have to say that this generic error message requires a lot more time to debug code than it seems like it should. Having a more informative message would really help code development.
@pwernette , There is a PR created for this issue here https://github.com/keras-team/keras/pull/16216, but there is no update from the author.
I also came across this error, but when using a tf.data.Dataset with step calculations and large batch sizes on small datasets.
I would also expect to get a better error message if I were to give steps_per_epoch=0 to fit.
Example:
import tensorflow as tf
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
import numpy as np
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
Y = np.array([0, 1, 1, 0])
ds = tf.data.Dataset.from_tensor_slices((X, Y))
ds = ds.repeat()
steps = 0  # from calculations such as len//batchsize
model = Sequential()
model.add(Dense(16, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='Adam', loss='binary_crossentropy', metrics=['acc'])
model.fit(ds, steps_per_epoch=steps)
also results in the error:
ValueError: Unexpected result of `train_function` (Empty logs). Ple
ase use `Model.compile(..., run_eagerly=True)`, or `tf.config.run_f
unctions_eagerly(True)` for more information of where went wrong, o
r file a issue/bug to `tf.keras`.
Also if compiling the model with run_eagerly=True, as the error message suggest, you get the same error.
In the hope of helping someone in a similar situation, I had the same error message, but my problem was my .fit() call was using a backup I had created using keras' BackupAndRestore callback. After deleting the backup, training could be launched.