bstriner / keras-tqdm

Keras integration with TQDM progress bars
MIT License
348 stars 41 forks source link

KeyError: 'metrics' #44

Open simin75simin opened 2 years ago

simin75simin commented 2 years ago

os: ubuntu 18.04 python: 3.6.9 tf: 2.6.2 keras:2.6.0 cuda:11.4 running jupyter notebook in visual studio

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-517-732094f0204b> in <module>
     79             validation_data = gen_val,
     80             verbose=0,
---> 81             callbacks=[TQDMCallback()])

~/.local/lib/python3.6/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
   1187               logs = tmp_logs  # No error, now safe to assign to logs.
   1188               end_step = step + data_handler.step_increment
-> 1189               callbacks.on_train_batch_end(end_step, logs)
   1190               if self.stop_training:
   1191                 break

~/.local/lib/python3.6/site-packages/keras/callbacks.py in on_train_batch_end(self, batch, logs)
    433     """
    434     if self._should_call_train_batch_hooks:
--> 435       self._call_batch_hook(ModeKeys.TRAIN, 'end', batch, logs=logs)
    436 
    437   def on_test_batch_begin(self, batch, logs=None):

~/.local/lib/python3.6/site-packages/keras/callbacks.py in _call_batch_hook(self, mode, hook, batch, logs)
    293       self._call_batch_begin_hook(mode, batch, logs)
    294     elif hook == 'end':
--> 295       self._call_batch_end_hook(mode, batch, logs)
    296     else:
    297       raise ValueError('Unrecognized hook: {}'.format(hook))

~/.local/lib/python3.6/site-packages/keras/callbacks.py in _call_batch_end_hook(self, mode, batch, logs)
    313       self._batch_times.append(batch_time)
    314 
--> 315     self._call_batch_hook_helper(hook_name, batch, logs)
    316 
    317     if len(self._batch_times) >= self._num_batches_for_timing_check:

~/.local/lib/python3.6/site-packages/keras/callbacks.py in _call_batch_hook_helper(self, hook_name, batch, logs)
    351     for callback in self.callbacks:
    352       hook = getattr(callback, hook_name)
--> 353       hook(batch, logs)
    354 
    355     if self._check_timing:

~/.local/lib/python3.6/site-packages/keras/callbacks.py in on_train_batch_end(self, batch, logs)
    718     """
    719     # For backwards compatibility.
--> 720     self.on_batch_end(batch, logs=logs)
    721 
    722   @doc_controls.for_subclass_implementers

~/.local/lib/python3.6/site-packages/keras_tqdm/tqdm_callback.py in on_batch_end(self, batch, logs)
    115         self.inner_count += update
    116         if self.inner_count < self.inner_total:
--> 117             self.append_logs(logs)
    118             metrics = self.format_metrics(self.running_logs)
    119             desc = self.inner_description_update.format(epoch=self.epoch, metrics=metrics)

~/.local/lib/python3.6/site-packages/keras_tqdm/tqdm_callback.py in append_logs(self, logs)
    134 
    135     def append_logs(self, logs):
--> 136         metrics = self.params['metrics']
    137         for metric, value in six.iteritems(logs):
    138             if metric in metrics:

KeyError: 'metrics'
mfouesneau commented 2 years ago

Same issue

Viech commented 1 year ago

Quick workaround that disables metrics display:

from keras_tqdm import TQDMCallback as OutdatedTQDMCallback

class TQDMCallback(OutdatedTQDMCallback):
    def build_tqdm_inner(self, *args, **kwargs):
        self.inner_description_update = self.inner_description_initial
        return super().build_tqdm_inner(*args, **kwargs)

    def append_logs(self, logs):
        return

    def format_metrics(self, logs):
        return
EssamWisam commented 3 months ago

Or use from tqdm.keras import TqdmCallback