# AUTOGENERATED FILE! PLEASE DON'T EDIT
import k1lib, time
from .callbacks import Callback, Callbacks, Cbs
__all__ = ["ProgressBar"]
[docs]@k1lib.patch(Cbs)
class ProgressBar(Callback):
"""Displays the current progress, epoch and batch while running."""
def startRun(self):
self.startTime = time.time(); self.step = 0; self.progress = 0
self.l.loss = float("inf") # to make sure this variable exist
def startBatch(self):
self.elapsedTime = time.time() - self.startTime
self.step += 1
if self.l.batches is None: self.progress = self.l.epoch / self.l.epochs
else: self.progress = (self.l.batch / self.l.batches + self.l.epoch) / self.l.epochs
if self.step % 10 == 0:
a = str(round(100 * self.progress)).rjust(3)
b = f"{self.l.epoch}/{self.l.epochs}".rjust(k1lib.numDigits(self.l.epochs) * 2 + 1)
c = f"{self.l.batch}/{self.l.batches}".rjust(k1lib.numDigits(self.l.batches) * 2 + 1)
d = f"{round(self.elapsedTime, 2)}".rjust(6)
print(f"\rProgress: {a}%, epoch: {b}, batch: {c}, elapsed: {d}s, loss: {self.l.loss} ", end="")
@k1lib.patch(Callbacks, docs=ProgressBar)
def withProgressBar(self): return self.append(ProgressBar())