forked from nitrain/nitrain
-
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.
nitrain#39 metrics were not printed after each epoch (validation metr…
…ics). Refactored for version 0.1.3. TODO update history.batch_metrics
- Loading branch information
1 parent
4c64f2d
commit 209b830
Showing
4 changed files
with
62 additions
and
29 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
import torch | ||
from torch.autograd import Variable | ||
|
||
from torchsample.metrics import CategoricalAccuracy | ||
|
||
class TestMetrics(unittest.TestCase): | ||
|
||
def test_categorical_accuracy(self): | ||
metric = CategoricalAccuracy() | ||
predicted = Variable(torch.eye(10)) | ||
expected = Variable(torch.LongTensor(list(range(10)))) | ||
self.assertEqual(metric(predicted, expected), 100.0) | ||
|
||
# Set 1st column to ones | ||
predicted = Variable(torch.zeros(10, 10)) | ||
predicted.data[:, 0] = torch.ones(10) | ||
self.assertEqual(metric(predicted, expected), 55.0) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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