Skip to content

Commit

Permalink
keras: fix resume from initial_epoch
Browse files Browse the repository at this point in the history
- set initial epochs
- update tests
  • Loading branch information
casperdcl committed May 3, 2021
1 parent 3f899b9 commit 74ec622
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
20 changes: 6 additions & 14 deletions tests/tests_keras.py
Expand Up @@ -38,9 +38,7 @@ def test_keras(capsys):
desc="training",
data_size=len(x),
batch_size=batch_size,
verbose=0,
)],
)
verbose=0)])
_, res = capsys.readouterr()
assert "training: " in res
assert "{epochs}/{epochs}".format(epochs=epochs) in res
Expand All @@ -59,9 +57,7 @@ def test_keras(capsys):
desc="training",
data_size=len(x),
batch_size=batch_size,
verbose=2,
)],
)
verbose=2)])
_, res = capsys.readouterr()
assert "training: " in res
assert "{epochs}/{epochs}".format(epochs=epochs) in res
Expand All @@ -74,8 +70,7 @@ def test_keras(capsys):
epochs=epochs,
batch_size=batch_size,
verbose=False,
callbacks=[TqdmCallback(desc="training", verbose=2)],
)
callbacks=[TqdmCallback(desc="training", verbose=2)])
_, res = capsys.readouterr()
assert "training: " in res
assert "{epochs}/{epochs}".format(epochs=epochs) in res
Expand All @@ -90,12 +85,9 @@ def test_keras(capsys):
epochs=epochs,
batch_size=batch_size,
verbose=False,
callbacks=[TqdmCallback(
desc="training",
verbose=2
)],
)
callbacks=[TqdmCallback(desc="training", verbose=0,
miniters=1, mininterval=0, maxinterval=0)])
_, res = capsys.readouterr()
assert "training: " in res
assert "{epochs}/{epochs}".format(epochs=initial_epoch - 1) not in res
assert "{epochs}/{epochs}".format(epochs=epochs) in res
assert "{batches}/{batches}".format(batches=batches) in res
3 changes: 2 additions & 1 deletion tqdm/keras.py
Expand Up @@ -74,7 +74,8 @@ def on_train_begin(self, *_, **__):

def on_epoch_begin(self, epoch, *_, **__):
if self.epoch_bar.n < epoch:
self.epoch_bar.update(epoch-self.epoch_bar.n)
ebar = self.epoch_bar
ebar.n = ebar.last_print_n = ebar.initial = epoch
if self.verbose:
params = self.params.get
total = params('samples', params(
Expand Down

0 comments on commit 74ec622

Please sign in to comment.