Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added testdata/dnn/onnx/data/input_matmul_2d_init.npy
Binary file not shown.
Binary file added testdata/dnn/onnx/data/input_matmul_3d_init.npy
Binary file not shown.
Binary file added testdata/dnn/onnx/data/input_matmul_4d_init.npy
Binary file not shown.
Binary file added testdata/dnn/onnx/data/output_matmul_2d_init.npy
Binary file not shown.
Binary file added testdata/dnn/onnx/data/output_matmul_3d_init.npy
Binary file not shown.
Binary file added testdata/dnn/onnx/data/output_matmul_4d_init.npy
Binary file not shown.
35 changes: 35 additions & 0 deletions testdata/dnn/onnx/generate_onnx_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,41 @@ def forward(self, x):
x = Variable(torch.randn(1, 3, 2, 4))
save_data_and_model("matmul_4d", x, model)

########### MatMul init ###########
def generate_matmul_init(name, inputA, inputB):
output = inputA @ inputB
shapeA = inputA.shape
shapeB = inputB.shape
shapeY = output.shape

input_files = os.path.join("data", "input_" + name)
np.save(input_files, inputA.data)
output_files = os.path.join("data", "output_" + name)
np.save(output_files, np.ascontiguousarray(output.data))

A = onnx.helper.make_tensor_value_info('A', onnx.TensorProto.FLOAT, shapeA)
B = onnx.helper.make_tensor_value_info('B', onnx.TensorProto.FLOAT, shapeB)
Y = onnx.helper.make_tensor_value_info('output', onnx.TensorProto.FLOAT, shapeY)
B_INIT = onnx.helper.make_tensor("B", onnx.TensorProto.FLOAT, shapeB, inputB)


node = onnx.helper.make_node("MatMul", inputs=['A', "B",], outputs=['output'])
graph = onnx.helper.make_graph([node], name, [A, B], [Y], [B_INIT])
model = onnx.helper.make_model(graph, producer_name=name)
onnx.save(model, os.path.join("models", name + ".onnx"))

inputA = np.random.randn(2, 3).astype(np.float32)
inputB = np.random.randn(3, 4).astype(np.float32)
generate_matmul_init("matmul_2d_init", inputA, inputB)

inputA = np.random.randn(5, 2, 3).astype(np.float32)
inputB = np.random.randn(5, 3, 4).astype(np.float32)
generate_matmul_init("matmul_3d_init", inputA, inputB)

inputA = np.random.randn(6, 2, 3, 4).astype(np.float32)
inputB = np.random.randn(6, 2, 4, 5).astype(np.float32)
generate_matmul_init("matmul_4d_init", inputA, inputB)

x = np.random.rand(1, 3, 2)
output = np.mean(x, axis=1, keepdims=True)
save_onnx_data_and_model(x, output, 'reduce_mean_axis1', 'ReduceMean', axes=(1), keepdims=True)
Expand Down
16 changes: 16 additions & 0 deletions testdata/dnn/onnx/models/matmul_2d_init.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
matmul_2d_init:�

A
Boutput"MatMulmatmul_2d_init*;"0�8s?b��hdӽ�9�>(�>�%�?^�B?�0�= B�>]ת>�=�?R�BBZ
A


Z
B


b
output


B
19 changes: 19 additions & 0 deletions testdata/dnn/onnx/models/matmul_3d_init.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
matmul_3d_init:�

A
Boutput"MatMulmatmul_3d_init*�"�4�ο��Y�L=e��> �����k��QN�>.:�=�ݚ>�b"�6���^&,�Z��[*P���ܿ3�5>;�;W�п���>�Dh���T=��:?>�ב?������>�O/���^�~/�Ѓ���f=�#����f?Ok�>��Ŀ �?��?@�?7>8�l��F��?5mξy�? FU>z?�u�>��4?G,<h��?>�>���> �?^���A���b*x?�(�����?��Ӿ3Y?�BBZ
A



Z
B



b
output



B
Expand Down
Binary file added testdata/dnn/onnx/models/matmul_4d_init.onnx
Binary file not shown.