Skip to content

Commit

Permalink
Apply pre-commit to the changes regarding resize
Browse files Browse the repository at this point in the history
  • Loading branch information
klassen9 committed Jul 7, 2024
1 parent e964e16 commit e21d543
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
28 changes: 16 additions & 12 deletions src/finn/transformation/fpgadataflow/convert_to_hw_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,30 @@ def apply(self, model):
scales = model.get_initializer(n.input[1])
elif len(n.input) == 3:
# Resize version 11 and up (no size input)
scales = model.get_initializer(n.input[2])
scales = model.get_initializer(n.input[2])
elif len(n.input) == 4:
# Resize version 11 and up
scales_exists = (model.get_initializer(n.input[2]) is not None) and (len(model.get_initializer(n.input[2])) != 0)
sizes_exists = (model.get_initializer(n.input[3]) is not None) and (len(model.get_initializer(n.input[3])) != 0)
assert (scales_exists ^ sizes_exists), (
"%s: Either scales or the target output size must "
scales_exists = (model.get_initializer(n.input[2]) is not None) and (
len(model.get_initializer(n.input[2])) != 0
)
sizes_exists = (model.get_initializer(n.input[3]) is not None) and (
len(model.get_initializer(n.input[3])) != 0
)
assert scales_exists ^ sizes_exists, (
"%s: Either scales or the target output size must "
"be specified. Specifying both is prohibited." % n.name
)
assert (model.get_initializer(n.input[1]) is None), (
"%s: Defining the ROI is not supported" % n.name
)
if (scales_exists):
)
assert model.get_initializer(n.input[1]) is None, (
"%s: Defining the ROI is not supported" % n.name
)
if scales_exists:
# Scales input
scales = model.get_initializer(n.input[2])
else:
# Convert sizes to scales
sizes = model.get_initializer(n.input[3])
data_input_size = model.get_tensor_shape(n.input[0])
scales = sizes/data_input_size
data_input_size = model.get_tensor_shape(n.input[0])
scales = sizes / data_input_size
in_shape = model.get_tensor_shape(n.input[0])

dt = model.get_tensor_datatype(n.input[0])
Expand Down
20 changes: 12 additions & 8 deletions src/finn/transformation/streamline/reorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,21 +763,25 @@ def apply(self, model):
else:
if len(n.input) == 2:
# Resize version 10
transformation_ind = 1
transformation_ind = 1
d_type = "float32"
elif len(n.input) == 3:
# Resize version 11 and up (no size input)
transformation_ind = 2
transformation_ind = 2
d_type = "float32"
elif len(n.input) == 4:
# Resize version 11 and up
scales_exists = (model.get_initializer(n.input[2]) is not None) and (len(model.get_initializer(n.input[2])) != 0)
sizes_exists = (model.get_initializer(n.input[3]) is not None) and (len(model.get_initializer(n.input[3])) != 0)
assert (scales_exists ^ sizes_exists), (
"%s: Either scales or the target output size must "
scales_exists = (model.get_initializer(n.input[2]) is not None) and (
len(model.get_initializer(n.input[2])) != 0
)
sizes_exists = (model.get_initializer(n.input[3]) is not None) and (
len(model.get_initializer(n.input[3])) != 0
)
assert scales_exists ^ sizes_exists, (
"%s: Either scales or the target output size must "
"be specified. Specifying both is prohibited." % n.name
)
if (scales_exists):
)
if scales_exists:
# Scales input
transformation_ind = 2
d_type = "float32"
Expand Down
8 changes: 6 additions & 2 deletions tests/transformation/streamline/test_scale_resize_nhwc.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def create_transpose_resize_transpose(ifm_dim, ifm_ch, scales, mode, idt):

return model


def create_resize_transpose_sizes(ifm_dim, ifm_ch, sizes, mode, idt):
ofm_dim_h = sizes[2]
ofm_dim_w = sizes[3]
Expand All @@ -189,7 +190,7 @@ def create_resize_transpose_sizes(ifm_dim, ifm_ch, sizes, mode, idt):

# Not actually used, only needed for compliance with the Resize node interface
roi = oh.make_tensor_value_info("roi", TensorProto.FLOAT, [4])

param = oh.make_tensor_value_info("sizes", TensorProto.INT64, [4])

outp_up = oh.make_tensor_value_info(
Expand Down Expand Up @@ -232,6 +233,7 @@ def create_resize_transpose_sizes(ifm_dim, ifm_ch, sizes, mode, idt):

return model


def check_transform(model):
graph = model.graph
node_ind = 0
Expand All @@ -251,7 +253,9 @@ def check_transform(model):
# scales
@pytest.mark.parametrize("scales", [[1, 1, i, j] for i in range(2, 5) for j in range(2, 5)])
# sizes
@pytest.mark.parametrize("sizes", [[1, 3, 2**i, 2**j] for i in range(6, 7) for j in range(6, 7)])
@pytest.mark.parametrize(
"sizes", [[1, 3, 2**i, 2**j] for i in range(6, 7) for j in range(6, 7)]
)
# mode
@pytest.mark.parametrize("mode", ["nearest"])
# input datatype
Expand Down

0 comments on commit e21d543

Please sign in to comment.