Skip to content

Commit e70ae1f

Browse files
committed
add tests cases
1 parent 327acfd commit e70ae1f

10 files changed

Lines changed: 490 additions & 2 deletions

tests/onnxbase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def __init__(self, func, name, ver_list, delta=1e-6, rtol=1e-5):
6464
self.seed = 33
6565
np.random.seed(self.seed)
6666
paddle.seed(self.seed)
67-
self.delta = 1e-6
68-
self.rtol = 1e-5
67+
self.delta = 1e-10
68+
self.rtol = 1e-11
6969
self.func = func
7070
if paddle.device.is_compiled_with_cuda() is True:
7171
self.places = ['gpu', 'cpu']

tests/test_broadcast_to.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from onnxbase import APIOnnx
17+
from onnxbase import randtool
18+
19+
20+
class Net(paddle.nn.Layer):
21+
"""
22+
simplr Net
23+
"""
24+
25+
def __init__(self):
26+
super(Net, self).__init__()
27+
28+
def forward(self, inputs):
29+
"""
30+
forward
31+
"""
32+
x = paddle.broadcast_to(inputs, shape=[2, 3])
33+
return x
34+
35+
36+
def test_broadcast_to_base():
37+
"""
38+
api: paddle.broadcast_to
39+
op version: 9, 10, 11, 12
40+
"""
41+
op = Net()
42+
op.eval()
43+
# net, name, ver_list, delta=1e-10, rtol=1e-11
44+
obj = APIOnnx(op, 'broadcast_to', [9, 10, 11, 12])
45+
obj.set_input_data("input_data", paddle.to_tensor([1, 2, 3], dtype='int32'))
46+
obj.run()

tests/test_floor_divide.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from onnxbase import APIOnnx
17+
from onnxbase import randtool
18+
19+
20+
class Net(paddle.nn.Layer):
21+
"""
22+
simplr Net
23+
"""
24+
25+
def __init__(self):
26+
super(Net, self).__init__()
27+
28+
def forward(self, inputs, inputs_):
29+
"""
30+
forward
31+
"""
32+
x = paddle.floor_divide(inputs, inputs_)
33+
return x
34+
35+
36+
def test_floor_divide_base():
37+
"""
38+
api: paddle.floor_divide
39+
op version: 10
40+
"""
41+
op = Net()
42+
op.eval()
43+
# net, name, ver_list, delta=1e-10, rtol=1e-11
44+
obj = APIOnnx(op, 'floor_divide', [9, 10, 11, 12])
45+
obj.set_input_data("input_data",
46+
paddle.to_tensor([2, 3, 8, 7]),
47+
paddle.to_tensor([1, 5, 3, 3]))
48+
obj.run()

tests/test_mod.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from onnxbase import APIOnnx
17+
from onnxbase import randtool
18+
19+
20+
class Net(paddle.nn.Layer):
21+
"""
22+
simplr Net
23+
"""
24+
25+
def __init__(self):
26+
super(Net, self).__init__()
27+
28+
def forward(self, inputs, inputs_):
29+
"""
30+
forward
31+
"""
32+
x = paddle.mod(inputs, inputs_)
33+
return x
34+
35+
36+
def test_mod_10():
37+
"""
38+
api: paddle.mod
39+
op version: 10
40+
"""
41+
op = Net()
42+
op.eval()
43+
# net, name, ver_list, delta=1e-6, rtol=1e-5
44+
obj = APIOnnx(op, 'mod', [10])
45+
obj.set_input_data("input_data",
46+
paddle.to_tensor([2, 3, 8, 7]),
47+
paddle.to_tensor([1, 5, 3, 3]))
48+
obj.run()
49+
50+
51+
def test_mod_11():
52+
"""
53+
api: paddle.mod
54+
op version: 11
55+
"""
56+
op = Net()
57+
op.eval()
58+
# net, name, ver_list, delta=1e-6, rtol=1e-5
59+
obj = APIOnnx(op, 'mod', [11])
60+
obj.set_input_data("input_data",
61+
paddle.to_tensor([2, 3, 8, 7]),
62+
paddle.to_tensor([1, 5, 3, 3]))
63+
obj.run()
64+
65+
66+
def test_mod_12():
67+
"""
68+
api: paddle.mod
69+
op version: 12
70+
"""
71+
op = Net()
72+
op.eval()
73+
# net, name, ver_list, delta=1e-6, rtol=1e-5
74+
obj = APIOnnx(op, 'mod', [12])
75+
obj.set_input_data("input_data",
76+
paddle.to_tensor([2, 3, 8, 7]),
77+
paddle.to_tensor([1, 5, 3, 3]))
78+
obj.run()

tests/test_nn_GRU.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from onnxbase import APIOnnx
17+
from onnxbase import randtool
18+
19+
20+
class Net(paddle.nn.Layer):
21+
"""
22+
simplr Net
23+
"""
24+
25+
def __init__(self):
26+
super(Net, self).__init__()
27+
self._gru = paddle.nn.GRU(16, 32, 2)
28+
29+
def forward(self, inputs, inputs_):
30+
"""
31+
forward
32+
"""
33+
x, h = self._gru(inputs, inputs_)
34+
return x
35+
36+
37+
def test_GRU_base():
38+
"""
39+
api: paddle.nn.GRU
40+
op version: 9, 10, 11, 12
41+
"""
42+
op = Net()
43+
op.eval()
44+
# net, name, ver_list, delta=1e-10, rtol=1e-11
45+
obj = APIOnnx(op, 'nn_GRU', [9, 10, 11, 12])
46+
obj.set_input_data("input_data",
47+
paddle.randn((4, 23, 16)), paddle.randn((2, 4, 32)))
48+
obj.run()

tests/test_nn_MaxPool1D.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from onnxbase import APIOnnx
17+
from onnxbase import randtool
18+
19+
20+
class Net(paddle.nn.Layer):
21+
"""
22+
simplr Net
23+
"""
24+
25+
def __init__(self):
26+
super(Net, self).__init__()
27+
self._max_pool = paddle.nn.MaxPool1D(
28+
kernel_size=2,
29+
stride=None,
30+
padding=0,
31+
ceil_mode=False,
32+
return_mask=False,
33+
name=None)
34+
35+
def forward(self, inputs):
36+
"""
37+
forward
38+
"""
39+
x = self._max_pool(inputs)
40+
return x
41+
42+
43+
def test_MaxPool1D_base():
44+
"""
45+
api: paddle.MaxPool1D
46+
op version: 9, 10, 11, 12
47+
"""
48+
op = Net()
49+
op.eval()
50+
# net, name, ver_list, delta=1e-6, rtol=1e-5
51+
obj = APIOnnx(op, 'nn_MaxPool1D', [9, 10, 11, 12])
52+
obj.set_input_data(
53+
"input_data",
54+
paddle.to_tensor(
55+
randtool("float", -1, 1, [3, 1, 10]).astype('float32')))
56+
obj.run()

tests/test_nn_MaxPool2D.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from onnxbase import APIOnnx
17+
from onnxbase import randtool
18+
19+
20+
class Net(paddle.nn.Layer):
21+
"""
22+
simplr Net
23+
"""
24+
25+
def __init__(self):
26+
super(Net, self).__init__()
27+
self._max_pool = paddle.nn.MaxPool2D(
28+
kernel_size=2,
29+
stride=None,
30+
padding=0,
31+
ceil_mode=False,
32+
return_mask=False,
33+
data_format='NCHW',
34+
name=None)
35+
36+
def forward(self, inputs):
37+
"""
38+
forward
39+
"""
40+
x = self._max_pool(inputs)
41+
return x
42+
43+
44+
def test_MaxPool2D_base():
45+
"""
46+
api: paddle.MaxPool2D
47+
op version: 9, 10, 11, 12
48+
"""
49+
op = Net()
50+
op.eval()
51+
# net, name, ver_list, delta=1e-6, rtol=1e-5
52+
obj = APIOnnx(op, 'nn_MaxPool2D', [9, 10, 11, 12])
53+
obj.set_input_data(
54+
"input_data",
55+
paddle.to_tensor(
56+
randtool("float", -1, 1, [3, 1, 10, 10]).astype('float32')))
57+
obj.run()

tests/test_nn_PixelShuffle.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle
16+
from onnxbase import APIOnnx
17+
from onnxbase import randtool
18+
19+
20+
class Net(paddle.nn.Layer):
21+
"""
22+
simplr Net
23+
"""
24+
25+
def __init__(self):
26+
super(Net, self).__init__()
27+
self.shuffle = paddle.nn.PixelShuffle(
28+
upscale_factor=3, data_format='NCHW', name=None)
29+
30+
def forward(self, inputs):
31+
"""
32+
forward
33+
"""
34+
x = self.shuffle(inputs)
35+
return x
36+
37+
38+
def test_PixelShuffle_base():
39+
"""
40+
api: paddle.nn.PixelShuffle
41+
op version: 9, 10, 11, 12
42+
"""
43+
op = Net()
44+
op.eval()
45+
# net, name, ver_list, delta=1e-10, rtol=1e-11
46+
obj = APIOnnx(op, 'nn_PixelShuffle', [9, 10, 11, 12])
47+
obj.set_input_data("input_data", paddle.rand((2, 9, 4, 4)))
48+
obj.run()

0 commit comments

Comments
 (0)