diff --git a/src/finn/transformation/fpgadataflow/convert_to_hw_layers.py b/src/finn/transformation/fpgadataflow/convert_to_hw_layers.py index 9017b171dd..edea1a9d19 100644 --- a/src/finn/transformation/fpgadataflow/convert_to_hw_layers.py +++ b/src/finn/transformation/fpgadataflow/convert_to_hw_layers.py @@ -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]) diff --git a/src/finn/transformation/streamline/reorder.py b/src/finn/transformation/streamline/reorder.py index 797c554297..9d7dc0b7ce 100644 --- a/src/finn/transformation/streamline/reorder.py +++ b/src/finn/transformation/streamline/reorder.py @@ -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" diff --git a/tests/transformation/streamline/test_scale_resize_nhwc.py b/tests/transformation/streamline/test_scale_resize_nhwc.py index 47a34e4601..dfa2e7433a 100644 --- a/tests/transformation/streamline/test_scale_resize_nhwc.py +++ b/tests/transformation/streamline/test_scale_resize_nhwc.py @@ -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] @@ -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( @@ -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 @@ -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