Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 782: tqdm_logger did not account for epoch_length argument #785

Merged
merged 3 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ignite/contrib/handlers/tqdm_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def __init__(self, description, metric_names=None, output_transform=None,
@staticmethod
def get_max_number_events(event_name, engine):
if event_name in (Events.ITERATION_STARTED, Events.ITERATION_COMPLETED):
return len(engine.state.dataloader)
return engine.state.epoch_length
if event_name in (Events.EPOCH_STARTED, Events.EPOCH_COMPLETED):
return engine.state.max_epochs
return 1
Expand Down
16 changes: 16 additions & 0 deletions tests/ignite/contrib/handlers/test_tqdm_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,19 @@ def test_pbar_on_callable_events(capsys):
actual = err[-1]
expected = u'Epoch: [90/100] 90%|█████████ [00:00<00:00]'
assert actual == expected


def test_tqdm_logger_epoch_length(capsys):
loader = list(range(100))
engine = Engine(update_fn)
pbar = ProgressBar(persist=True)
pbar.attach(engine)
engine.run(loader, epoch_length=50)

captured = capsys.readouterr()
err = captured.err.split('\r')
err = list(map(lambda x: x.strip(), err))
err = list(filter(None, err))
actual = err[-1]
expected = u'Epoch: [50/50] 100%|██████████ [00:00<00:00]'
assert actual == expected