test_accuracy_op.py 717 字节
Newer Older
武毅 已提交
1 2 3 4 5 6 7 8
import unittest
import numpy as np
from op_test import OpTest


class TestAccuracyOp(OpTest):
    def setUp(self):
        self.op_type = "accuracy"
9 10 11
        n = 8192
        infer = np.random.randint(0, 2, (n, 1)).astype("int")
        label = np.random.randint(0, 2, (n, )).astype("int")
武毅 已提交
12 13
        self.inputs = {'Inference': infer, "Label": label}
        num_correct = 0
14
        for rowid in xrange(n):
武毅 已提交
15 16 17 18
            for ele in infer[rowid]:
                if ele == label[rowid]:
                    num_correct += 1
                    break
19
        self.outputs = {'Accuracy': [num_correct / float(n)]}
武毅 已提交
20 21 22 23 24 25 26

    def test_check_output(self):
        self.check_output()


if __name__ == '__main__':
    unittest.main()