-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactoring' into metrics
- Loading branch information
Showing
19 changed files
with
1,078 additions
and
339 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .config import ClassificationLoss, ImplementedLoss, LossConfig | ||
from .config import create_loss_config | ||
from .enum import ClassificationLoss, ImplementedLoss | ||
from .factory import get_loss_function |
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,50 @@ | ||
from enum import Enum | ||
|
||
from clinicadl.utils.enum import BaseEnum | ||
|
||
|
||
class ClassificationLoss(str, BaseEnum): | ||
"""Losses that can be used only for classification.""" | ||
|
||
CROSS_ENTROPY = "CrossEntropyLoss" # for multi-class classification, inputs are unormalized logits and targets are int (same dimension without the class channel) | ||
NLL = "NLLLoss" # for multi-class classification, inputs are log-probabilities and targets are int (same dimension without the class channel) | ||
MULTI_MARGIN = "MultiMarginLoss" # no particular restriction on the input, targets are int (same dimension without th class channel) | ||
BCE = "BCELoss" # for binary classification, targets and inputs should be probabilities and have same shape | ||
BCE_LOGITS = "BCEWithLogitsLoss" # for binary classification, targets should be probabilities and inputs logits, and have the same shape. More stable numerically | ||
|
||
|
||
class ImplementedLoss(str, Enum): | ||
"""Implemented losses in ClinicaDL.""" | ||
|
||
CROSS_ENTROPY = "CrossEntropyLoss" | ||
NLL = "NLLLoss" | ||
MULTI_MARGIN = "MultiMarginLoss" | ||
BCE = "BCELoss" | ||
BCE_LOGITS = "BCEWithLogitsLoss" | ||
|
||
L1 = "L1Loss" | ||
MSE = "MSELoss" | ||
HUBER = "HuberLoss" | ||
SMOOTH_L1 = "SmoothL1Loss" | ||
KLDIV = "KLDivLoss" # if log_target=False, target must be positive | ||
|
||
@classmethod | ||
def _missing_(cls, value): | ||
raise ValueError( | ||
f"{value} is not implemented. Implemented losses are: " | ||
+ ", ".join([repr(m.value) for m in cls]) | ||
) | ||
|
||
|
||
class Reduction(str, Enum): | ||
"""Supported reduction method in ClinicaDL.""" | ||
|
||
MEAN = "mean" | ||
SUM = "sum" | ||
|
||
|
||
class Order(int, Enum): | ||
"""Supported order of L-norm for MultiMarginLoss.""" | ||
|
||
ONE = 1 | ||
TWO = 2 |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
from .config import OptimizationConfig | ||
from .early_stopping import EarlyStopping | ||
from .lr_scheduler import create_lr_scheduler_config, get_lr_scheduler | ||
from .optimizer import create_optimizer_config, get_optimizer |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .config import ImplementedLRScheduler, LRSchedulerConfig | ||
from .config import create_lr_scheduler_config | ||
from .enum import ImplementedLRScheduler | ||
from .factory import get_lr_scheduler |
Oops, something went wrong.