test_accuracy_op.py 699 字节
Newer Older
武毅 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import unittest
import numpy as np
from op_test import OpTest


class TestAccuracyOp(OpTest):
    def setUp(self):
        self.op_type = "accuracy"
        infer = np.random.randint(0, 2, (32, 1)).astype("int")
        label = np.random.randint(0, 2, (32, )).astype("int")
        self.inputs = {'Inference': infer, "Label": label}
        num_correct = 0
        for rowid in xrange(32):
            for ele in infer[rowid]:
                if ele == label[rowid]:
                    num_correct += 1
                    break
        self.outputs = {'Accuracy': [num_correct / 32.0]}

    def test_check_output(self):
        self.check_output()


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