| 32 | self._eval_step(loss, accuracy) |
| 33 | |
| 34 | def flush(self) -> None: |
| 35 | if self.is_train: |
| 36 | loss = self.epoch_state["loss"] / self.epoch_state["steps"] |
| 37 | accuracy = self.epoch_state["accuracy"] / self.epoch_state["steps"] |
| 38 | |
| 39 | print( |
| 40 | f"\r┃{self.epoch:12d} ┃{loss:12.4f} │{100*accuracy:10.2f} % ┃{self.learning_rate:12.3e} │{self._time():>12} ┃", |
| 41 | end="", |
| 42 | flush=True, |
| 43 | ) |
| 44 | |
| 45 | else: |
| 46 | loss = self.epoch_state["loss"] / self.epoch_state["steps"] |
| 47 | accuracy = self.epoch_state["accuracy"] / self.epoch_state["steps"] |
| 48 | |
| 49 | print(f"{loss:12.4f} │{100*accuracy:10.2f} % ┃", flush=True) |
| 50 | |
| 51 | if accuracy > self.best_accuracy: |
| 52 | self.best_accuracy = accuracy |
| 53 | |
| 54 | def _train_step(self, model, loss, accuracy, learning_rate: float) -> None: |
| 55 | self.learning_rate = learning_rate |