test_accuracy_op.py 771 字节
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
        n = 8192
        infer = np.random.randint(0, 2, (n, 1)).astype("int")
F
fengjiayi 已提交
11
        label = np.random.randint(0, 2, (n, 1)).astype("int")
武毅 已提交
12 13
        self.inputs = {'Inference': infer, "Label": label}
        num_correct = 0
14
        for rowid in xrange(n):
武毅 已提交
15
            for ele in infer[rowid]:
F
fengjiayi 已提交
16
                if ele == label[rowid][0]:
武毅 已提交
17 18
                    num_correct += 1
                    break
Y
Yang Yang(Tony) 已提交
19 20 21
        self.outputs = {
            'Accuracy': np.array([num_correct / float(n)]).astype("float32")
        }
武毅 已提交
22 23 24 25 26 27 28

    def test_check_output(self):
        self.check_output()


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