Skip to content

Commit 86b0c40

Browse files
committed
make conv_same_pad also trigger on depthwise, varius bug fixes
1 parent 0925a3d commit 86b0c40

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

hls4ml/backends/vivado/passes/conv_same_pad.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from hls4ml.model.layers import Conv1D, Conv2D, SeparableConv1D, SeparableConv2D
1+
from hls4ml.model.layers import Conv1D, Conv2D, DepthwiseConv1D, DepthwiseConv2D, SeparableConv1D, SeparableConv2D
22
from hls4ml.model.optimizer import OptimizerPass
33

44

@@ -7,7 +7,7 @@ class InsertZeroPaddingBeforeConv1D(OptimizerPass):
77

88
def match(self, node):
99
is_match = (
10-
isinstance(node, (Conv1D, SeparableConv1D))
10+
isinstance(node, (Conv1D, DepthwiseConv1D, SeparableConv1D))
1111
and ((node.get_attr('padding') == 'same') or (node.get_attr('padding') == 'causal'))
1212
and node.get_attr('filt_width') != 1
1313
)
@@ -55,7 +55,7 @@ class InsertZeroPaddingBeforeConv2D(OptimizerPass):
5555

5656
def match(self, node):
5757
is_match = (
58-
isinstance(node, (Conv2D, SeparableConv2D))
58+
isinstance(node, (Conv2D, DepthwiseConv2D, SeparableConv2D))
5959
and node.get_attr('padding') == 'same'
6060
and node.get_attr('filt_height') != 1
6161
and node.get_attr('filt_width') != 1

hls4ml/model/layers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def __init__(self, model, name, attributes, inputs, outputs=None):
100100

101101
layer_config = self.model.config.get_layer_config(self)
102102
for config_key, config_value in layer_config.items():
103-
print(f'{config_key=}, {config_value=}')
104103
config_key = convert_to_snake_case(config_key)
105104
if config_key in self.attributes:
106105
print(
@@ -494,9 +493,9 @@ class DepthwiseConv1D(Conv1D):
494493
Attribute('stride_width'),
495494
Attribute('pad_left'),
496495
Attribute('pad_right'),
497-
WeightAttribute('depthwise'),
496+
WeightAttribute('weight'),
498497
WeightAttribute('bias'),
499-
TypeAttribute('depthwise'),
498+
TypeAttribute('weight'),
500499
TypeAttribute('bias'),
501500
]
502501

hls4ml/model/optimizer/passes/seperable_to_dw_conv.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SeperableToDepthwiseAndConv(OptimizerPass):
3333
'data_format',
3434
'depthwise_data',
3535
'depthwise_quantizer',
36+
'padding',
3637
)
3738

3839
_pw_attributes = ('out_width', 'n_filt', 'dilation_width', 'out_height', 'dilation_height', 'data_format', 'use_bias')

test/pytest/test_sepconv2d.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
padds_options = ['same', 'valid']
1212
chans_options = ['channels_last']
13-
io_type_options = ['io_parallel', 'io_stream']
1413
strides_options = [(1, 1), (2, 2)]
1514
kernel_options = [(2, 2), (3, 3)]
1615
bias_options = [False]
@@ -50,7 +49,9 @@ def test_sepconv2d(chans, padds, strides, kernels, bias, io_type, backend):
5049
model.compile(optimizer='adam', loss='mse')
5150
X_input = np.random.rand(100, *input_shape)
5251
keras_prediction = model.predict(X_input)
53-
config = hls4ml.utils.config_from_keras_model(model, default_precision='ap_fixed<32,16>')
52+
config = hls4ml.utils.config_from_keras_model(
53+
model, default_precision='ap_fixed<32,16>', granularity="name", backend=backend
54+
)
5455
stride_cfg = str(strides).replace(', ', '_').replace('(', '').replace(')', '')
5556
kernel_cfg = str(kernels).replace(', ', '_').replace('(', '').replace(')', '')
5657
output_dir = str(

0 commit comments

Comments
 (0)