-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: validation metrics not logged per epoch, only per batch #10
Comments
Hi Ilya, Thank you very much for flagging this on the intercom and writing this comprehensive issue. As we discussed, I will work on a general solution for it and let you know once we merge the PR! |
Unfortunately, it doesn't solve it @twolodzko. IssueWhen you pass validation split or validation dataset Keras logs the validation metrics with key names starting with This is metric introduces a new metric field
Proposed Fix 🛠️PR: #22 |
Upon closer and deeper inspection I found out the following:
Below is a full example of my experiment and results. Test code class CustomCallback(keras.callbacks.Callback):
def _log_metrics(self, logs, category: str, trigger: str):
if not logs:
return
for metric, value in logs.items():
if metric in ("batch", "size"):
continue
print(f"{category}/{trigger}/{metric} ---> {value}")
print("\n")
def on_train_end(self, logs=None): # pylint:disable=unused-argument
print('on_train_end')
self._log_metrics(logs, 'train', 'epoch')
def on_test_end(self, logs=None): # pylint:disable=unused-argument
print('on_test_end')
self._log_metrics(logs, 'test', 'epoch')
def on_epoch_end(self, epoch, logs=None): # pylint:disable=unused-argument
print('on_epoch_end')
self._log_metrics(logs, 'train', 'epoch')
model = get_model()
model.fit(
x_train,
y_train,
batch_size=128,
epochs=1,
verbose=0,
validation_split=0.5,
callbacks=[CustomCallback()]
) Output:
As you can see, Therefore, I'm closing this issue and PR #22 for now. Let me know if this logic makes sense or if I may have overlooked something. Note: If I did indeed overlook something, I'm more than happy to re-open this issue and continue on the quest of getting to the solution. |
When I add the callback and pass validation set or validation split to Keras, validation per-batch metrics are logged under 'test/batch/...', but validation per-epoch metrics are not logged.
These metrics' names begin with
val
and this is filtered out inimpl/__init__.py:23
since merge request #9.Removing this filtering lets them being logged under
train/epoch/val_...
. But then there is inconsistency between the categories: per-batch is under test, and per-epoch is under train.It seems that
on_test_batch_end
is invoked after validation, andon_test_end
is not.This happens with Tensorflow 2.2.0, and with Tensorflow 2.9.1 as well.
I hope this can be straightened.
The text was updated successfully, but these errors were encountered: