Skip to content

Commit

Permalink
Fix tqdm bug (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanwharris committed Nov 4, 2019
1 parent bd935a3 commit b31f2b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Deprecated
### Removed
### Fixed
- Fixed a bug when resuming an old state dict with tqdm enabled
- Fixed a bug in imaging where passing a title to `to_pyplot` was not possible

## [0.5.0] - 2019-09-17
Expand Down
8 changes: 8 additions & 0 deletions tests/callbacks/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def test_tqdm_on_epoch(self):
mock_tqdm.return_value.set_postfix_str.assert_called_once_with('test=0.9946')
self.assertEqual(mock_tqdm.return_value.close.call_count, 1)

def test_tqdm_keys(self):
state = {torchbearer.EPOCH: 1, torchbearer.MAX_EPOCHS: 10, torchbearer.HISTORY: [0, {'test': 0.99456}],
torchbearer.METRICS: {'test': 0.99456}}
tqdm = Tqdm(validation_label_letter='e', on_epoch=True)
tqdm.tqdm_module = MagicMock()

tqdm.on_start(state)

@patch('torchbearer.magics.is_notebook')
def test_tqdm_module_init_notebook(self, mock_is_notebook):
from tqdm import tqdm_notebook
Expand Down
11 changes: 9 additions & 2 deletions torchbearer/callbacks/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,15 @@ def on_start(self, state):

if n > 0:
metrics = dict(state[torchbearer.HISTORY][-1])
del metrics[str(torchbearer.TRAIN_STEPS)]
del metrics[str(torchbearer.VALIDATION_STEPS)]
try:
del metrics[str(torchbearer.TRAIN_STEPS)]
except KeyError:
pass

try:
del metrics[str(torchbearer.VALIDATION_STEPS)]
except KeyError:
pass
state[torchbearer.METRICS] = metrics
self._update(state)

Expand Down

0 comments on commit b31f2b2

Please sign in to comment.