Exemplo n.º 1
0
 def test_functional_ignore_index_with_valid_index(self):
     actual = topk(self.predictions, self.targets, 3, ignore_index=1)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(40., actual)
Exemplo n.º 2
0
 def test_functional_ignore_index_with_different_value(self):
     actual = topk(self.predictions, self.targets, 3, ignore_index=-1)
     self.assertEqual((), actual.shape)
     self.assertAlmostEqual(50., float(actual), places=5)
Exemplo n.º 3
0
 def test_functional_standard(self):
     actual = topk(self.predictions, self.targets, 3)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(self.top_k_acc, actual)
Exemplo n.º 4
0
 def test_functional_on_gpu(self):
     actual = topk(self.predictions.cuda(), self.targets.cuda(), 3)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(self.top_k_acc, actual.cpu(), decimal=5)
Exemplo n.º 5
0
 def test_functional_none(self):
     actual = topk(self.predictions, self.targets, 3, reduction='none')
     self.assertEqual(self.targets.shape, actual.shape)
     self.assertTrue(torch.all(self.top_k_acc_none == actual))
Exemplo n.º 6
0
 def test_functional_sum(self):
     actual = topk(self.predictions, self.targets, 3, reduction='sum')
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(self.top_k_acc * len(self.predictions),
                                    actual,
                                    decimal=0)