-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from aai-institute/feature/trainer-criterion-loss
Feature/trainer criterion loss
- Loading branch information
Showing
16 changed files
with
159 additions
and
223 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
""" | ||
`continuity.trainer.criterion` | ||
Stopping criterion for Trainer in Continuity. | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
from .logs import Logs | ||
|
||
|
||
class Criterion(ABC): | ||
""" | ||
Stopping criterion base class for `fit` method of `Trainer`. | ||
""" | ||
|
||
@abstractmethod | ||
def __call__(self, logs: Logs): | ||
"""Evaluate stopping criterion. | ||
Called at the end of each epoch. | ||
Args: | ||
logs: Training logs. | ||
Returns: | ||
bool: Whether to stop training. | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
class TrainingLossCriterion(Criterion): | ||
""" | ||
Stopping criterion based on training loss. | ||
""" | ||
|
||
def __init__(self, threshold: float): | ||
self.threshold = threshold | ||
|
||
def __call__(self, logs: Logs): | ||
"""Callback function. | ||
Called at the end of each epoch. | ||
Args: | ||
logs: Training logs. | ||
Returns: | ||
bool: True if training loss is below threshold. | ||
""" | ||
return logs.loss_train < self.threshold |
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,21 @@ | ||
""" | ||
`continuity.trainer.logs` | ||
""" | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Logs: | ||
""" | ||
Logs for callbacks and criteria within Trainer in Continuity. | ||
Attributes: | ||
epoch: Current epoch. | ||
loss_train: Training loss. | ||
time: Time taken for epoch. | ||
""" | ||
|
||
epoch: int | ||
loss_train: float | ||
seconds_per_epoch: float |
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
Oops, something went wrong.