From 7b3d9f02ec4abfd1ad9b5c492d5672e3f3584995 Mon Sep 17 00:00:00 2001 From: idow09 Date: Wed, 31 Jul 2019 15:12:27 +0300 Subject: [PATCH] prevent failure when no training_results available (#409) Use `chkpt.get('training_results')` instead of `chkpt.get('training_results')` so if the dict doesn't contain this key it won't throw a `KeyError --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 1a264e95..ad86edbb 100644 --- a/train.py +++ b/train.py @@ -131,7 +131,7 @@ def train(cfg, optimizer.load_state_dict(chkpt['optimizer']) best_fitness = chkpt['best_fitness'] - if chkpt['training_results'] is not None: + if chkpt.get('training_results') is not None: with open('results.txt', 'w') as file: file.write(chkpt['training_results']) # write results.txt