Skip to content
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

Fixed #42: crash when 'metrics' absent in params #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions keras_tqdm/tqdm_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def on_epoch_begin(self, epoch, logs={}):
self.running_logs = {}

def on_epoch_end(self, epoch, logs={}):
metrics = self.format_metrics(logs)
desc = self.inner_description_update.format(epoch=epoch, metrics=metrics)
if self.show_inner:
metrics = self.format_metrics(logs)
desc = self.inner_description_update.format(epoch=epoch, metrics=metrics)
self.tqdm_inner.desc = desc
# set miniters and mininterval to 0 so last update displays
self.tqdm_inner.miniters = 0
Expand All @@ -119,9 +119,9 @@ def on_batch_end(self, batch, logs={}):
self.inner_count += update
if self.inner_count < self.inner_total:
self.append_logs(logs)
metrics = self.format_metrics(self.running_logs)
desc = self.inner_description_update.format(epoch=self.epoch, metrics=metrics)
if self.show_inner:
metrics = self.format_metrics(self.running_logs)
desc = self.inner_description_update.format(epoch=self.epoch, metrics=metrics)
self.tqdm_inner.desc = desc
self.tqdm_inner.update(update)

Expand All @@ -137,7 +137,9 @@ def on_train_end(self, logs={}):
self.tqdm_outer.close()

def append_logs(self, logs):
metrics = self.params['metrics']
metrics = self.params.get('metrics')
if not metrics:
return
for metric, value in six.iteritems(logs):
if metric in metrics:
if metric in self.running_logs:
Expand All @@ -146,7 +148,10 @@ def append_logs(self, logs):
self.running_logs[metric] = [value[()]]

def format_metrics(self, logs):
metrics = self.params['metrics']
metrics = self.params.get('metrics')
if not metrics:
return ''

strings = [self.metric_format.format(name=metric, value=np.mean(logs[metric], axis=None)) for metric in metrics
if
metric in logs]
Expand Down