-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: logging of train and eval better aligned (#105)
- Loading branch information
1 parent
562c65f
commit c971f82
Showing
4 changed files
with
68 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import numpy as np | ||
|
||
|
||
class LogGenerator: | ||
def __init__(self, name, losses, metrics, prefix: str = ''): | ||
self._losses = losses | ||
self._metrics = metrics | ||
self._prefix = prefix | ||
self._name = name | ||
|
||
def __call__(self): | ||
if self._prefix: | ||
prefix = f'{self._prefix} | ' | ||
else: | ||
prefix = '' | ||
return f'{prefix}{self._name}: {self.get_statistic()}' | ||
|
||
def get_statistic(self): | ||
return f'L={self.mean_loss():>8} A={self.mean_metric():>4}' | ||
|
||
def mean_loss(self): | ||
return LogGenerator.get_log_value(self._losses) | ||
|
||
def mean_metric(self): | ||
return LogGenerator.get_log_value(self._metrics) | ||
|
||
@staticmethod | ||
def get_log_value(data): | ||
mean = np.mean(data) | ||
if mean < 1e5: | ||
return f'{mean:.2f}' | ||
else: | ||
return f'{mean:.2e}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters