Skip to content

Commit

Permalink
Fix tensor printing in trainer.test() (#5138)
Browse files Browse the repository at this point in the history
* Fix showing test results for tensors

* Fix docs

* Update pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>

* Fix lint issues

Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
  • Loading branch information
2 people authored and Borda committed Feb 4, 2021
1 parent 7d33abe commit 6c96db0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/source/starter/introduction_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ Once you train your model simply call ``.test()``.
--------------------------------------------------------------
TEST RESULTS
{'test_loss': tensor(1.1703, device='cuda:0')}
{'test_loss': 1.1703}
--------------------------------------------------------------
You can also run the test from a saved lightning model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def get_evaluate_epoch_results(self):
print('-' * 80)
for result_idx, results in enumerate(self.eval_loop_results):
print(f'DATALOADER:{result_idx} TEST RESULTS')
pprint(results)
pprint({k: (v.item() if v.numel() == 1 else v.tolist()) if isinstance(v, torch.Tensor) else v
for k, v in results.items()})
print('-' * 80)

results = self.eval_loop_results
Expand Down

0 comments on commit 6c96db0

Please sign in to comment.