Skip to content

Commit e5c1316

Browse files
committed
Merge branch 4.x
2 parents 02de719 + f0609ac commit e5c1316

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
@@ -1925,6 +1925,35 @@ def forward(self, x):
19251925
model = Gather()
19261926
save_data_and_model("gather", x, model)
19271927

1928+
def create_range_test(name, np_dtype, onnx_dtype, start_val, end_val, step_val, inp, out):
1929+
start = onnx.helper.make_node("Constant", inputs=[], outputs=["start1"], name="node-c1",
1930+
value=onnx.helper.make_tensor(name="c1v", data_type=onnx_dtype, dims=[], vals=np.asarray([start_val,], dtype=np_dtype)))
1931+
end = onnx.helper.make_node("Constant", inputs=[], outputs=["end1"], name="node-c2",
1932+
value=onnx.helper.make_tensor(name="c2v", data_type=onnx_dtype, dims=[], vals=np.asarray([end_val,], dtype=np_dtype)))
1933+
step = onnx.helper.make_node("Constant", inputs=[], outputs=["step1"], name="node-c3",
1934+
value=onnx.helper.make_tensor(name="c3v", data_type=onnx_dtype, dims=[], vals=np.asarray([step_val,], dtype=np_dtype)))
1935+
1936+
range = onnx.helper.make_node("Range", inputs=["start1", "end1", "step1"], outputs=["range_output1"], name="node-r1")
1937+
add = onnx.helper.make_node("Add", inputs=["input1", "range_output1"], outputs=["add_output1"], name="node-a1")
1938+
1939+
graph = onnx.helper.make_graph([start, end, step, range, add], "graph123",
1940+
[onnx.helper.make_tensor_value_info("input1", onnx_dtype, [1, 4]),],
1941+
[onnx.helper.make_tensor_value_info("add_output1", onnx_dtype, [1, 4])])
1942+
range_model = onnx.helper.make_model(graph, producer_name="model_range")
1943+
onnx.checker.check_model(range_model)
1944+
1945+
input_np = np.array(inp, dtype=np_dtype)
1946+
output_np = np.array(out, dtype=np_dtype)
1947+
1948+
onnx.save(range_model, os.path.join("models", name + ".onnx"))
1949+
input_file = os.path.join("data", "input_" + name)
1950+
np.save(input_file, input_np)
1951+
output_file = os.path.join("data", "output_" + name)
1952+
np.save(output_file, output_np)
1953+
1954+
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]])
1955+
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]])
1956+
19281957
class Conv(nn.Module):
19291958
def forward(self, x, kernel):
19301959
out = F.conv2d(x, kernel, groups=1)
360 Bytes
Binary file not shown.
360 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)