Coverage for tvo/exp/_EpochLog.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-01 11:33 +0000

1# -*- coding: utf-8 -*- 

2# Copyright (C) 2019 Machine Learning Group of the University of Oldenburg. 

3# Licensed under the Academic Free License version 3.0 

4 

5from tvo.utils.parallel import pprint 

6from tvo.utils import get 

7 

8 

9class EpochLog: 

10 """Experiment epoch log.""" 

11 

12 def __init__(self, epoch, results, runtime=None): 

13 self.epoch = epoch 

14 self.runtime = runtime 

15 

16 self._results = results 

17 

18 def print(self): 

19 """Print epoch log. 

20 

21 In MPI runs, this method is no-op for all processes but the one with rank 0. 

22 """ 

23 if self.epoch == 0: 

24 pprint("Start") 

25 else: 

26 pprint(f"Epoch {self.epoch}") 

27 for data_kind in "train", "test": 

28 if data_kind + "_F" not in self._results: 

29 continue 

30 # log_kind is one of "train", "valid" or "test" 

31 # (while data_kind is one of "train" or "test") 

32 log_kind = "valid" if data_kind == "test" and "train_F" in self._results else data_kind 

33 F, subs = get(self._results, f"{data_kind}_F", f"{data_kind}_subs") 

34 pprint(f"\t{log_kind} F/N: {F:<10.5f} avg subs: {subs:<6.2f}") 

35 if self.runtime is not None: 

36 pprint(f"\ttotal epoch runtime: {self.runtime:<5.2f} s")