Skip to content

Commit b3d3cc7

Browse files
authored
Merge branch 'main' into purge_dim_name
2 parents 95c774e + 71bf4ae commit b3d3cc7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

hls4ml/model/layers.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,47 @@ def initialize(self):
939939
self.add_output_variable(shape, dims, precision=inp.type.precision)
940940

941941

942+
class Cropping1D(Layer):
943+
_expected_attributes = [
944+
Attribute('in_width'),
945+
Attribute('out_width'),
946+
Attribute('n_chan'),
947+
Attribute('crop_left'),
948+
Attribute('crop_right'),
949+
]
950+
951+
def initialize(self):
952+
inp = self.get_input_variable()
953+
# no data_format attribute for Cropping1D
954+
shape = [self.attributes['out_width'], self.attributes['n_chan']]
955+
dims = [f'OUT_WIDTH_{self.index}', f'N_CHAN_{self.index}']
956+
self.add_output_variable(shape, dims, precision=inp.type.precision)
957+
958+
959+
class Cropping2D(Layer):
960+
_expected_attributes = [
961+
Attribute('in_height'),
962+
Attribute('in_width'),
963+
Attribute('out_height'),
964+
Attribute('out_width'),
965+
Attribute('n_chan'),
966+
Attribute('crop_top'),
967+
Attribute('crop_bottom'),
968+
Attribute('crop_left'),
969+
Attribute('crop_right'),
970+
]
971+
972+
def initialize(self):
973+
inp = self.get_input_variable()
974+
if self.get_attr('data_format') == 'channels_last':
975+
shape = [self.attributes['out_height'], self.attributes['out_width'], self.attributes['n_chan']]
976+
dims = [f'OUT_HEIGHT_{self.index}', f'OUT_WIDTH_{self.index}', f'N_CHAN_{self.index}']
977+
else:
978+
shape = [self.attributes['n_chan'], self.attributes['out_height'], self.attributes['out_width']]
979+
dims = [f'N_CHAN_{self.index}', f'OUT_HEIGHT_{self.index}', f'OUT_WIDTH_{self.index}']
980+
self.add_output_variable(shape, dims, precision=inp.type.precision)
981+
982+
942983
class Activation(Layer):
943984
_expected_attributes = [
944985
Attribute('n_in'),

0 commit comments

Comments
 (0)