-
Notifications
You must be signed in to change notification settings - Fork 0
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 #39 from SFI-Visual-Intelligence/Jan/accuracy
Added accuracy and tests for it and Jan model, no clashes merging myself
- Loading branch information
Showing
5 changed files
with
70 additions
and
8 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
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
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 torch | ||
from torch import nn | ||
|
||
|
||
class Accuracy(nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, y_true, y_pred): | ||
""" | ||
Compute the accuracy of the model. | ||
Parameters | ||
---------- | ||
y_true : torch.Tensor | ||
True labels. | ||
y_pred : torch.Tensor | ||
Predicted labels. | ||
Returns | ||
------- | ||
float | ||
Accuracy score. | ||
""" | ||
return (y_true == y_pred).float().mean().item() | ||
|
||
|
||
if __name__ == "__main__": | ||
y_true = torch.tensor([0, 3, 2, 3, 4]) | ||
y_pred = torch.tensor([0, 1, 2, 3, 4]) | ||
|
||
accuracy = Accuracy() | ||
print(accuracy(y_true, y_pred)) |