# Buggy code
def __init__(
    self,
    metrics_separator: str = " - ",
    overall_bar_format: str = "{l_bar}{bar} {n_fmt}/{total_fmt} ETA: "
    "{remaining}s,  {rate_fmt}{postfix}",
    epoch_bar_format: str = "{n_fmt}/{total_fmt}{bar} ETA: {remaining}s - {desc}",
    metrics_format: str = "{name}: {value:0.4f}",
    update_per_second: int = 10,
    leave_epoch_progress: bool = True,
    leave_overall_progress: bool = True,
    show_epoch_progress: bool = True,
    show_overall_progress: bool = True,
):
    try:
        # import tqdm here because tqdm is not a required package
        # for addons
        import tqdm

        version_message = "Please update your TQDM version to >= 4.36.1, "
        "you have version {}. To update, run !pip install -U tqdm"
        assert tqdm.__version__ >= "4.36.1", version_message.format(tqdm.__version__)
        from tqdm.auto import tqdm

        self.tqdm = tqdm
    except ImportError:
        raise ImportError("Please install tqdm via pip install tqdm")

    self.metrics_separator = metrics_separator
    self.overall_bar_format = overall_bar_format
    self.epoch_bar_format = epoch_bar_format
    self.leave_epoch_progress = leave_epoch_progress
    self.leave_overall_progress = leave_overall_progress
    self.show_epoch_progress = show_epoch_progress
    self.show_overall_progress = show_overall_progress
    self.metrics_format = metrics_format

    # compute update interval (inverse of update per second)
    self.update_interval = 1 / update_per_second

    self.last_update_time = time.time()
    self.overall_progress_tqdm = None
    self.epoch_progress_tqdm = None
    self.num_epochs = None
    self.logs = None
    self.metrics = None


# Traceback (KeyError)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-23-fdbb03f574a1> in <module>
48 #   class_weight=class_weights,
49     verbose=VERBOSE,
---> 50     callbacks=model_callbacks,
51 )

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
63   def _method_wrapper(self, *args, **kwargs):
64     if not self._in_multi_worker_mode():  # pylint: disable=protected-access
---> 65       return method(self, *args, **kwargs)
66
67     # Running inside `run_distribute_coordinator` already.

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow/python/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, **kwargs)
763       self.stop_training = False
764       train_function = self.make_train_function()
--> 765       callbacks.on_train_begin()
766       # Handle fault-tolerance for multi-worker.
767       # TODO(omalleyt): Fix the ordering issues that mean this has to

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_train_begin(self, logs)
445     logs = self._process_logs(logs)
446     for callback in self.callbacks:
--> 447       callback.on_train_begin(logs)
448
449   def on_train_end(self, logs=None):

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow_addons/callbacks/tqdm_progress_bar.py in on_train_begin(self, logs)
100     def on_train_begin(self, logs=None):
101         self.num_epochs = self.params["epochs"]
--> 102         self.metrics = self.params["metrics"]
103
104         if self.show_overall_progress:

KeyError: 'metrics'

# Fixed code
def __init__(
    self,
    metrics_separator: str = " - ",
    overall_bar_format: str = "{l_bar}{bar} {n_fmt}/{total_fmt} ETA: "
    "{remaining}s,  {rate_fmt}{postfix}",
    epoch_bar_format: str = "{n_fmt}/{total_fmt}{bar} ETA: {remaining}s - {desc}",
    metrics_format: str = "{name}: {value:0.4f}",
    update_per_second: int = 10,
    leave_epoch_progress: bool = True,
    leave_overall_progress: bool = True,
    show_epoch_progress: bool = True,
    show_overall_progress: bool = True,
):
    try:
        # import tqdm here because tqdm is not a required package
        # for addons
        import tqdm

        version_message = "Please update your TQDM version to >= 4.36.1, "
        "you have version {}. To update, run !pip install -U tqdm"
        assert tqdm.__version__ >= "4.36.1", version_message.format(tqdm.__version__)
        from tqdm.auto import tqdm

        self.tqdm = tqdm
    except ImportError:
        raise ImportError("Please install tqdm via pip install tqdm")

    self.metrics_separator = metrics_separator
    self.overall_bar_format = overall_bar_format
    self.epoch_bar_format = epoch_bar_format
    self.leave_epoch_progress = leave_epoch_progress
    self.leave_overall_progress = leave_overall_progress
    self.show_epoch_progress = show_epoch_progress
    self.show_overall_progress = show_overall_progress
    self.metrics_format = metrics_format

    # compute update interval (inverse of update per second)
    self.update_interval = 1 / update_per_second

    self.last_update_time = time.time()
    self.overall_progress_tqdm = None
    self.epoch_progress_tqdm = None
    self.num_epochs = None
    self.logs = None
    super().__init__()