Skip to content

Commit 9626e45

Browse files
author
Alexander Lyulkov
committed
Added tests for range layer
1 parent be9cf63 commit 9626e45

File tree

7 files changed

+29
-0
lines changed

7 files changed

+29
-0
lines changed
144 Bytes
Binary file not shown.
Binary file not shown.
144 Bytes
Binary file not shown.
Binary file not shown.

testdata/dnn/onnx/generate_onnx_models.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,35 @@ def forward(self, x):
19031903
model = Gather()
19041904
save_data_and_model("gather", x, model)
19051905

1906+
def create_range_test(name, np_dtype, onnx_dtype, start_val, end_val, step_val, inp, out):
1907+
start = onnx.helper.make_node("Constant", inputs=[], outputs=["start1"], name="node-c1",
1908+
value=onnx.helper.make_tensor(name="c1v", data_type=onnx_dtype, dims=[], vals=np.asarray([start_val,], dtype=np_dtype)))
1909+
end = onnx.helper.make_node("Constant", inputs=[], outputs=["end1"], name="node-c2",
1910+
value=onnx.helper.make_tensor(name="c2v", data_type=onnx_dtype, dims=[], vals=np.asarray([end_val,], dtype=np_dtype)))
1911+
step = onnx.helper.make_node("Constant", inputs=[], outputs=["step1"], name="node-c3",
1912+
value=onnx.helper.make_tensor(name="c3v", data_type=onnx_dtype, dims=[], vals=np.asarray([step_val,], dtype=np_dtype)))
1913+
1914+
range = onnx.helper.make_node("Range", inputs=["start1", "end1", "step1"], outputs=["range_output1"], name="node-r1")
1915+
add = onnx.helper.make_node("Add", inputs=["input1", "range_output1"], outputs=["add_output1"], name="node-a1")
1916+
1917+
graph = onnx.helper.make_graph([start, end, step, range, add], "graph123",
1918+
[onnx.helper.make_tensor_value_info("input1", onnx_dtype, [1, 4]),],
1919+
[onnx.helper.make_tensor_value_info("add_output1", onnx_dtype, [1, 4])])
1920+
range_model = onnx.helper.make_model(graph, producer_name="model_range")
1921+
onnx.checker.check_model(range_model)
1922+
1923+
input_np = np.array(inp, dtype=np_dtype)
1924+
output_np = np.array(out, dtype=np_dtype)
1925+
1926+
onnx.save(range_model, os.path.join("models", name + ".onnx"))
1927+
input_file = os.path.join("data", "input_" + name)
1928+
np.save(input_file, input_np)
1929+
output_file = os.path.join("data", "output_" + name)
1930+
np.save(output_file, output_np)
1931+
1932+
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]])
1933+
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]])
1934+
19061935
class Conv(nn.Module):
19071936
def forward(self, x, kernel):
19081937
out = F.conv2d(x, kernel, groups=1)
360 Bytes
Binary file not shown.
360 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)