From 5b2b990ccb5228bb8059d66c379ce8ca658a1ea4 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Thu, 5 May 2022 23:22:10 +0200 Subject: [PATCH] Idiotproof file operations --- eval_model.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/eval_model.py b/eval_model.py index fef402f..f83f923 100644 --- a/eval_model.py +++ b/eval_model.py @@ -31,11 +31,9 @@ def main(): loss_fn = torch.nn.MSELoss() loss = test(dataloader, model, loss_fn) - with open('evaluation_results.txt', 'r+') as f: - f.read() + with open('evaluation_results.txt', 'a+') as f: f.write(f'{str(loss)}\n') - f.flush() - f.seek(0) + with open('evaluation_results.txt', 'r') as f: values = [float(line) for line in f.readlines() if line] make_plot(values)