Skip to content
Snippets Groups Projects
Commit 5a82356d authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Test] make test_renaming stronger

parent a0c1b50a
No related branches found
No related tags found
No related merge requests found
from pkgutil import get_data
import numpy as np
import onnx
import onnx.numpy_helper as np_helper
import finn.core.onnx_exec as oxe
import finn.transformation.general as tg
import finn.transformation.infer_shapes as si
from finn.core.modelwrapper import ModelWrapper
......@@ -12,9 +17,31 @@ def test_renaming():
model = model.transform_single(si.infer_shapes)
model = model.transform_single(tg.give_unique_node_names)
model = model.transform_single(tg.give_readable_tensor_names)
# do some basic checks
assert model.graph.input[0].name == "global_in"
assert model.graph.output[0].name == "global_out"
assert model.graph.node[1].op_type == "Conv"
assert model.graph.node[1].name == "Conv_0"
assert model.graph.node[1].input[1] == "Conv_0_param0"
assert model.graph.node[6].op_type == "Add"
assert model.graph.node[6].name == "Add_1"
assert model.graph.node[6].input[1] == "Add_1_param0"
# ensure running renaming twice still yields the same names
model = model.transform_single(tg.give_unique_node_names)
model = model.transform_single(tg.give_readable_tensor_names)
assert model.graph.node[1].op_type == "Conv"
assert model.graph.node[1].name == "Conv_1"
assert model.graph.node[1].input[1] == "Conv_1_param0"
assert model.graph.node[1].name == "Conv_0"
assert model.graph.node[1].input[1] == "Conv_0_param0"
assert model.graph.node[6].op_type == "Add"
assert model.graph.node[6].name == "Add_6"
assert model.graph.node[6].input[1] == "Add_6_param0"
assert model.graph.node[6].name == "Add_1"
assert model.graph.node[6].input[1] == "Add_1_param0"
# run renamed model to make sure we did not mess up the topology
raw_i = get_data("finn", "data/onnx/mnist-conv/test_data_set_0/input_0.pb")
raw_o = get_data("finn", "data/onnx/mnist-conv/test_data_set_0/output_0.pb")
input_tensor = onnx.load_tensor_from_string(raw_i)
output_tensor = onnx.load_tensor_from_string(raw_o)
input_dict = {"global_in": np_helper.to_array(input_tensor)}
output_dict = oxe.execute_onnx(model, input_dict)
assert np.isclose(
np_helper.to_array(output_tensor), output_dict["global_out"], atol=1e-3
).all()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment