From 9626e45415c8fdc8865730e92b3fdffe347dc5b2 Mon Sep 17 00:00:00 2001 From: Alexander Lyulkov Date: Sun, 14 Apr 2024 23:15:52 +0300 Subject: [PATCH] Added tests for range layer --- testdata/dnn/onnx/data/input_range_float.npy | Bin 0 -> 144 bytes .../onnx/data/input_range_float_negative.npy | Bin 0 -> 144 bytes testdata/dnn/onnx/data/output_range_float.npy | Bin 0 -> 144 bytes .../onnx/data/output_range_float_negative.npy | Bin 0 -> 144 bytes testdata/dnn/onnx/generate_onnx_models.py | 29 ++++++++++++++++++ testdata/dnn/onnx/models/range_float.onnx | Bin 0 -> 360 bytes .../dnn/onnx/models/range_float_negative.onnx | Bin 0 -> 360 bytes 7 files changed, 29 insertions(+) create mode 100644 testdata/dnn/onnx/data/input_range_float.npy create mode 100644 testdata/dnn/onnx/data/input_range_float_negative.npy create mode 100644 testdata/dnn/onnx/data/output_range_float.npy create mode 100644 testdata/dnn/onnx/data/output_range_float_negative.npy create mode 100644 testdata/dnn/onnx/models/range_float.onnx create mode 100644 testdata/dnn/onnx/models/range_float_negative.onnx diff --git a/testdata/dnn/onnx/data/input_range_float.npy b/testdata/dnn/onnx/data/input_range_float.npy new file mode 100644 index 0000000000000000000000000000000000000000..2290dd06e97361facc21746576c8f36031b86987 GIT binary patch literal 144 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+l>qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= aXCxM+0{I$-ItnJ5ItsN4WCJb+Gynh%OdD(f literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/data/input_range_float_negative.npy b/testdata/dnn/onnx/data/input_range_float_negative.npy new file mode 100644 index 0000000000000000000000000000000000000000..2290dd06e97361facc21746576c8f36031b86987 GIT binary patch literal 144 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+l>qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= aXCxM+0{I$-ItnJ5ItsN4WCJb+Gynh%OdD(f literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/data/output_range_float.npy b/testdata/dnn/onnx/data/output_range_float.npy new file mode 100644 index 0000000000000000000000000000000000000000..f633fb3246c228500237c8432d177a4180ce232c GIT binary patch literal 144 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+l>qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= mXCxM+0{I$-ItnJ5ItsN4WCO0VXL{_@(%c-3jTZy)V+R0Aiy`y? literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/data/output_range_float_negative.npy b/testdata/dnn/onnx/data/output_range_float_negative.npy new file mode 100644 index 0000000000000000000000000000000000000000..13d97aa84e8c9a38ee1078fa17cb1e19cab82968 GIT binary patch literal 144 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+l>qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= mXCxM+0{I$-ItnJ5ItsN4WCJb+1`bCCh6@f13=@D@!2tjui5>L- literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/generate_onnx_models.py b/testdata/dnn/onnx/generate_onnx_models.py index 7ed85ba86..66ce03856 100644 --- a/testdata/dnn/onnx/generate_onnx_models.py +++ b/testdata/dnn/onnx/generate_onnx_models.py @@ -1903,6 +1903,35 @@ def forward(self, x): model = Gather() save_data_and_model("gather", x, model) +def create_range_test(name, np_dtype, onnx_dtype, start_val, end_val, step_val, inp, out): + start = onnx.helper.make_node("Constant", inputs=[], outputs=["start1"], name="node-c1", + value=onnx.helper.make_tensor(name="c1v", data_type=onnx_dtype, dims=[], vals=np.asarray([start_val,], dtype=np_dtype))) + end = onnx.helper.make_node("Constant", inputs=[], outputs=["end1"], name="node-c2", + value=onnx.helper.make_tensor(name="c2v", data_type=onnx_dtype, dims=[], vals=np.asarray([end_val,], dtype=np_dtype))) + step = onnx.helper.make_node("Constant", inputs=[], outputs=["step1"], name="node-c3", + value=onnx.helper.make_tensor(name="c3v", data_type=onnx_dtype, dims=[], vals=np.asarray([step_val,], dtype=np_dtype))) + + range = onnx.helper.make_node("Range", inputs=["start1", "end1", "step1"], outputs=["range_output1"], name="node-r1") + add = onnx.helper.make_node("Add", inputs=["input1", "range_output1"], outputs=["add_output1"], name="node-a1") + + graph = onnx.helper.make_graph([start, end, step, range, add], "graph123", + [onnx.helper.make_tensor_value_info("input1", onnx_dtype, [1, 4]),], + [onnx.helper.make_tensor_value_info("add_output1", onnx_dtype, [1, 4])]) + range_model = onnx.helper.make_model(graph, producer_name="model_range") + onnx.checker.check_model(range_model) + + input_np = np.array(inp, dtype=np_dtype) + output_np = np.array(out, dtype=np_dtype) + + onnx.save(range_model, os.path.join("models", name + ".onnx")) + input_file = os.path.join("data", "input_" + name) + np.save(input_file, input_np) + output_file = os.path.join("data", "output_" + name) + np.save(output_file, output_np) + +create_range_test("range_float", np.float32, onnx.TensorProto.FLOAT, 1.1, 8.5, 2.0, [[0, 0, 0, 0]], [[1.1, 3.1, 5.1, 7.1]]) +create_range_test("range_float_negative", np.float32, onnx.TensorProto.FLOAT, 8.5, 0.6, -2.0, [[0, 0, 0, 0]], [[8.5, 6.5, 4.5, 2.5]]) + class Conv(nn.Module): def forward(self, x, kernel): out = F.conv2d(x, kernel, groups=1) diff --git a/testdata/dnn/onnx/models/range_float.onnx b/testdata/dnn/onnx/models/range_float.onnx new file mode 100644 index 0000000000000000000000000000000000000000..6ce18679a3d58a3054755c59e52d907735777cc1 GIT binary patch literal 360 zcmd67#x7wj3JhBK^@5jwv-EEh!8K>7xDR}B?YB$4-^?Hu?B&B$7RIDmYD~V;X+j? z#GROuf~G6cP>IwehgHecsi;05~h*^?kxsVM&mv&+j G5Cs6$@myyB literal 0 HcmV?d00001 diff --git a/testdata/dnn/onnx/models/range_float_negative.onnx b/testdata/dnn/onnx/models/range_float_negative.onnx new file mode 100644 index 0000000000000000000000000000000000000000..f02515d08ce940f2102a95dda3a33b582044dc39 GIT binary patch literal 360 zcmd0{M>1h>I;V4