Ejemplo n.º 1
0
 def testBadTarget(self):
     predictions = [[0.1, 0.3, 0.2, 0.4], [0.1, 0.2, 0.3, 0.4]]
     target = [0, 80000]
     with self.test_session():
         with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
                                      "target.*out of range"):
             nn_ops.in_top_k(predictions, target, 2).eval()
Ejemplo n.º 2
0
 def testBadTarget(self):
   predictions = [[0.1, 0.3, 0.2, 0.4], [0.1, 0.2, 0.3, 0.4]]
   target = [0, 80000]
   with self.test_session():
     with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
                                  "target.*out of range"):
       nn_ops.in_top_k(predictions, target, 2).eval()
Ejemplo n.º 3
0
 def _validateInTopK(self, predictions, target, k, expected):
     np_ans = np.array(expected)
     with self.cached_session(use_gpu=True):
         precision = nn_ops.in_top_k(predictions, target, k)
         out = self.evaluate(precision)
         self.assertAllClose(np_ans, out)
         self.assertShapeEqual(np_ans, precision)
Ejemplo n.º 4
0
 def _validateInTopK(self, predictions, target, k, expected):
     np_ans = np.array(expected)
     with self.test_session():
         precision = nn_ops.in_top_k(predictions, target, k)
         out = precision.eval()
         self.assertAllClose(np_ans, out)
         self.assertShapeEqual(np_ans, precision)
Ejemplo n.º 5
0
 def _validateInTopK(self, predictions, target, k, expected):
   np_ans = np.array(expected)
   with self.test_session():
     precision = nn_ops.in_top_k(predictions, target, k)
     out = precision.eval()
     self.assertAllClose(np_ans, out)
     self.assertShapeEqual(np_ans, precision)
Ejemplo n.º 6
0
 def _validateInTopK(self, predictions, target, k, expected):
   np_ans = np.array(expected)
   with self.cached_session(use_gpu=True):
     precision = nn_ops.in_top_k(predictions, target, k)
     out = self.evaluate(precision)
     self.assertAllClose(np_ans, out)
     self.assertShapeEqual(np_ans, precision)
Ejemplo n.º 7
0
 def testTensorK(self):
     predictions = [[0.1, 0.3, 0.2, 0.4], [0.1, 0.2, 0.3, 0.4]]
     target = [0, 2]
     k = constant_op.constant(3)
     np_ans = np.array([False, True])
     with self.cached_session():
         precision = nn_ops.in_top_k(predictions, target, k)
         out = self.evaluate(precision)
         self.assertAllClose(np_ans, out)
         self.assertShapeEqual(np_ans, precision)
Ejemplo n.º 8
0
 def testTensorK(self):
   predictions = [[0.1, 0.3, 0.2, 0.4], [0.1, 0.2, 0.3, 0.4]]
   target = [0, 2]
   k = constant_op.constant(3)
   np_ans = np.array([False, True])
   with self.cached_session():
     precision = nn_ops.in_top_k(predictions, target, k)
     out = precision.eval()
     self.assertAllClose(np_ans, out)
     self.assertShapeEqual(np_ans, precision)
Ejemplo n.º 9
0
 def in_topk(predictions, targets, k=k):
     return nn_ops.in_top_k(predictions, targets, k)