-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics 구현 완료, train 코드 진행, 텐서플로우 레거시 제거
- Loading branch information
Showing
7 changed files
with
296 additions
and
296 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 |
---|---|---|
@@ -1,35 +1,40 @@ | ||
import torch | ||
from typing import List | ||
import torch.nn.functional as F | ||
|
||
from typing import Dict | ||
|
||
|
||
class _Metric(torch.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, input: torch.Tensor, target: torch.Tensor): | ||
pass | ||
raise NotImplementedError() | ||
|
||
|
||
class CategoricalAccuracy(_Metric): | ||
class Accuracy(_Metric): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, input: torch.Tensor, target: torch.Tensor): | ||
pass | ||
bool_acc = input == target | ||
return bool_acc.sum() / bool_acc.numel() | ||
|
||
|
||
class Accuracy(_Metric): | ||
class CategoricalAccuracy(Accuracy): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, input: torch.Tensor, target: torch.Tensor): | ||
pass | ||
categorical_input = input.argmax(-1) | ||
return super().forward(categorical_input, target) | ||
|
||
|
||
class MetricsSet(_Metric): | ||
def __init__(self, metrics: List[_Metric]): | ||
def __init__(self, metric_dict: Dict): | ||
super().__init__() | ||
self.metrics = metrics | ||
self.metrics = metric_dict | ||
|
||
def forward(self, input: torch.Tensor, target: torch.Tensor): | ||
return [metric(input, target) for metric in self.metrics] | ||
# return [metric(input, target) for metric in self.metrics] | ||
return {k: metric(input, target) for k, metric in self.metrics.items()} |
File renamed without changes.
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.