parent
c1696696a3
commit
2d807f2b4c
@ -1,23 +1,20 @@
|
||||
import unittest
|
||||
import numpy as np
|
||||
from op_test import OpTest
|
||||
|
||||
import numpy
|
||||
import paddle.v2.framework.core as core
|
||||
from paddle.v2.framework.op import Operator
|
||||
|
||||
from op_test_util import OpTestMeta
|
||||
|
||||
|
||||
class TestAddOp(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class TestAddOp(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "add"
|
||||
self.op_type = "add"
|
||||
self.inputs = {
|
||||
'X': numpy.random.random((102, 105)).astype("float32"),
|
||||
'Y': numpy.random.random((102, 105)).astype("float32")
|
||||
'X': np.random.random((102, 105)).astype("float32"),
|
||||
'Y': np.random.random((102, 105)).astype("float32")
|
||||
}
|
||||
self.outputs = {'Out': self.inputs['X'] + self.inputs['Y']}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,16 +1,17 @@
|
||||
import unittest
|
||||
from op_test_util import OpTestMeta
|
||||
import numpy
|
||||
import numpy as np
|
||||
from op_test import OpTest
|
||||
|
||||
|
||||
class TestFillZerosLikeOp(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class TestFillZerosLikeOp(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "fill_zeros_like"
|
||||
self.inputs = {'Src': numpy.random.random((219, 232)).astype("float32")}
|
||||
self.outputs = {'Dst': numpy.zeros_like(self.inputs['Src'])}
|
||||
self.op_type = "fill_zeros_like"
|
||||
self.inputs = {'Src': np.random.random((219, 232)).astype("float32")}
|
||||
self.outputs = {'Dst': np.zeros_like(self.inputs["Src"])}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,31 +1,22 @@
|
||||
import unittest
|
||||
import numpy as np
|
||||
from op_test_util import OpTestMeta
|
||||
from gradient_checker import GradientChecker, create_op
|
||||
from op_test import OpTest
|
||||
|
||||
|
||||
class TestLookupTableOp(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class TestLookupTableOp(OpTest):
|
||||
def setUp(self):
|
||||
self.type = 'lookup_table'
|
||||
table = np.random.random((17, 31)).astype('float32')
|
||||
ids = np.random.randint(0, 17, 4).astype('int32')
|
||||
self.op_type = "lookup_table"
|
||||
table = np.random.random((17, 31)).astype("float32")
|
||||
ids = np.random.randint(0, 17, 4).astype("int32")
|
||||
self.inputs = {'W': table, 'Ids': ids}
|
||||
self.outputs = {'Out': table[ids]}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
class TestLookupTableGradOp(GradientChecker):
|
||||
def test_grad(self):
|
||||
op = create_op('lookup_table')
|
||||
table = np.random.random((17, 31)).astype('float32')
|
||||
ids = np.random.randint(0, 17, 4).astype('int32')
|
||||
inputs = {'W': table, 'Ids': ids}
|
||||
# comapre gradients
|
||||
self.compare_grad(op, inputs, set(['Ids']))
|
||||
# check gradients
|
||||
self.check_grad(op, inputs, set('W'), 'Out')
|
||||
def test_check_grad(self):
|
||||
self.check_grad(['W'], 'Out', no_grad_set=set('Ids'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,24 +1,20 @@
|
||||
import unittest
|
||||
from op_test_util import OpTestMeta
|
||||
from gradient_checker import GradientChecker, create_op
|
||||
import numpy as np
|
||||
from op_test import OpTest
|
||||
|
||||
|
||||
class TestMeanOp(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class TestMeanOp(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "mean"
|
||||
self.inputs = {'X': np.random.random((32, 784)).astype("float32")}
|
||||
self.outputs = {'Out': np.mean(self.inputs['X'])}
|
||||
self.op_type = "mean"
|
||||
self.inputs = {'X': np.random.random((10, 10)).astype("float32")}
|
||||
self.outputs = {'Out': np.mean(self.inputs["X"])}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
class MeanGradOpTest(GradientChecker):
|
||||
def test_normal(self):
|
||||
op = create_op("mean")
|
||||
inputs = {"X": np.random.random((10, 10)).astype("float32")}
|
||||
self.check_grad(op, inputs, set("X"), "Out")
|
||||
def test_checkout_grad(self):
|
||||
self.check_grad(['X'], 'Out')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,30 +1,23 @@
|
||||
import unittest
|
||||
import numpy as np
|
||||
from gradient_checker import GradientChecker, create_op
|
||||
from op_test_util import OpTestMeta
|
||||
from op_test import OpTest
|
||||
|
||||
|
||||
class MinusOpTest(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class MinusOpTest(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "minus"
|
||||
self.op_type = "minus"
|
||||
self.inputs = {
|
||||
'X': np.random.random((32, 84)).astype("float32"),
|
||||
'Y': np.random.random((32, 84)).astype("float32")
|
||||
}
|
||||
self.outputs = {'Out': (self.inputs['X'] - self.inputs['Y'])}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
class MinusGradTest(GradientChecker):
|
||||
def test_left(self):
|
||||
op = create_op("minus")
|
||||
inputs = {
|
||||
"X": np.random.random((10, 10)).astype("float32"),
|
||||
"Y": np.random.random((10, 10)).astype("float32")
|
||||
}
|
||||
self.check_grad(op, inputs, ["X", 'Y'], "Out")
|
||||
def test_check_grad(self):
|
||||
self.check_grad(['X', 'Y'], 'Out')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,68 +1,51 @@
|
||||
import unittest
|
||||
import numpy as np
|
||||
from op_test_util import OpTestMeta
|
||||
from gradient_checker import GradientChecker, create_op
|
||||
from op_test import OpTest
|
||||
|
||||
|
||||
class TestRowwiseAddOp(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
def setUp(self):
|
||||
self.type = "rowwise_add"
|
||||
self.inputs = {
|
||||
'X': np.random.random((32, 84)).astype("float32"),
|
||||
'b': np.random.random(84).astype("float32")
|
||||
}
|
||||
self.outputs = {'Out': np.add(self.inputs['X'], self.inputs['b'])}
|
||||
|
||||
|
||||
class TestRowwiseAddOp2(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class TestRowwiseAddOp(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "rowwise_add"
|
||||
self.op_type = "rowwise_add"
|
||||
self.inputs = {
|
||||
'X': np.random.random((13, 6, 7, 8)).astype("float32"),
|
||||
'b': np.random.random((7, 8)).astype("float32")
|
||||
'X': np.random.uniform(0.1, 1, [5, 10]).astype("float32"),
|
||||
'b': np.random.uniform(0.1, 1, [10]).astype("float32")
|
||||
}
|
||||
self.outputs = {'Out': np.add(self.inputs['X'], self.inputs['b'])}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
class TestRowwiseAddGradOp(GradientChecker):
|
||||
def setUp(self):
|
||||
self.op = create_op("rowwise_add")
|
||||
self.inputs = {
|
||||
"X": np.random.uniform(0.1, 1, [5, 10]).astype("float32"),
|
||||
"b": np.random.uniform(0.1, 1, [10]).astype("float32")
|
||||
}
|
||||
def test_check_grad_normal(self):
|
||||
self.check_grad(['X', 'b'], 'Out')
|
||||
|
||||
def test_normal(self):
|
||||
self.check_grad(self.op, self.inputs, ["X", "b"], "Out")
|
||||
def test_check_grad_ingore_b(self):
|
||||
self.check_grad(['X'], 'Out', no_grad_set=set('b'))
|
||||
|
||||
def test_ignore_b(self):
|
||||
self.check_grad(self.op, self.inputs, ["X"], "Out", no_grad_set={"b"})
|
||||
def test_check_grad_ingore_x(self):
|
||||
self.check_grad(['b'], 'Out', no_grad_set=set('X'))
|
||||
|
||||
def test_ignore_x(self):
|
||||
self.check_grad(self.op, self.inputs, ["b"], "Out", no_grad_set={"X"})
|
||||
|
||||
|
||||
class TestRowwiseAddGradOp2(GradientChecker):
|
||||
class TestRowwiseAddOp2(OpTest):
|
||||
def setUp(self):
|
||||
self.op = create_op("rowwise_add")
|
||||
self.op_type = "rowwise_add"
|
||||
self.inputs = {
|
||||
"X": np.random.uniform(0.1, 1, [2, 3, 2, 5]).astype("float32"),
|
||||
"b": np.random.uniform(0.1, 1, [2, 5]).astype("float32")
|
||||
'X': np.random.uniform(0.1, 1, [2, 3, 2, 5]).astype("float32"),
|
||||
'b': np.random.uniform(0.1, 1, [2, 5]).astype("float32")
|
||||
}
|
||||
self.outputs = {'Out': np.add(self.inputs['X'], self.inputs['b'])}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
def test_normal(self):
|
||||
self.check_grad(self.op, self.inputs, ["X", "b"], "Out")
|
||||
def test_check_grad_normal(self):
|
||||
self.check_grad(['X', 'b'], 'Out')
|
||||
|
||||
def test_ignore_b(self):
|
||||
self.check_grad(self.op, self.inputs, ["X"], "Out", no_grad_set={"b"})
|
||||
def test_check_grad_ignore_b(self):
|
||||
self.check_grad(['X'], 'Out', no_grad_set=set('b'))
|
||||
|
||||
def test_ignore_x(self):
|
||||
self.check_grad(self.op, self.inputs, ["b"], "Out", no_grad_set={"X"})
|
||||
def test_check_grad_ignore_x(self):
|
||||
self.check_grad(['b'], 'Out', no_grad_set=set('X'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,43 +1,34 @@
|
||||
import unittest
|
||||
from op_test_util import OpTestMeta
|
||||
from gradient_checker import GradientChecker, create_op
|
||||
import numpy as np
|
||||
from paddle.v2.framework.op import Operator
|
||||
from op_test import OpTest
|
||||
|
||||
|
||||
class IdentityTest(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class IdentityTest(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "identity"
|
||||
self.inputs = {'X': np.random.random((32, 784)).astype("float32")}
|
||||
self.op_type = "identity"
|
||||
self.inputs = {'X': np.random.random((10, 10)).astype("float32")}
|
||||
self.outputs = {'Out': self.inputs['X']}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
class IdentityGradOpTest(GradientChecker):
|
||||
def test_normal(self):
|
||||
op = create_op("identity")
|
||||
inputs = {"X": np.random.random((10, 10)).astype("float32")}
|
||||
self.check_grad(op, inputs, set("X"), "Out")
|
||||
|
||||
def test_check_grad(self):
|
||||
self.check_grad(['X'], 'Out')
|
||||
|
||||
class ScaleTest(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class ScaleTest(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "scale"
|
||||
self.inputs = {'X': np.random.random((32, 784)).astype("float32")}
|
||||
self.op_type = "scale"
|
||||
self.inputs = {'X': np.random.random((10, 10)).astype("float32")}
|
||||
self.attrs = {'scale': -2.3}
|
||||
self.outputs = {'Out': self.inputs['X'] * self.attrs['scale']}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
class ScaleGradTest(GradientChecker):
|
||||
def test_normal(self):
|
||||
op = Operator("scale", X="X", Out="Out", scale=3.2)
|
||||
self.check_grad(op,
|
||||
{"X": np.random.random((10, 10)).astype("float32")},
|
||||
set("X"), "Out")
|
||||
def test_check_grad(self):
|
||||
self.check_grad(['X'], 'Out')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,21 +1,22 @@
|
||||
import unittest
|
||||
import numpy
|
||||
from op_test_util import OpTestMeta
|
||||
import numpy as np
|
||||
from op_test import OpTest
|
||||
|
||||
|
||||
class TestSGD(unittest.TestCase):
|
||||
__metaclass__ = OpTestMeta
|
||||
|
||||
class TestSGD(OpTest):
|
||||
def setUp(self):
|
||||
self.type = "sgd"
|
||||
w = numpy.random.random((102, 105)).astype("float32")
|
||||
g = numpy.random.random((102, 105)).astype("float32")
|
||||
self.op_type = "sgd"
|
||||
w = np.random.random((102, 105)).astype("float32")
|
||||
g = np.random.random((102, 105)).astype("float32")
|
||||
lr = 0.1
|
||||
|
||||
self.inputs = {'param': w, 'grad': g}
|
||||
self.attrs = {'learning_rate': lr}
|
||||
self.outputs = {'param_out': w - lr * g}
|
||||
|
||||
def test_check_output(self):
|
||||
self.check_output()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Loading…
Reference in new issue