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

    def test_check_output(self):
        self.check_output()


if __name__ == '__main__':
29
    exit(0)
武毅 已提交
30
    unittest.main()