`PointwiseConv2D` and `ReuseFactor` synthesis error
Created by: leeziy
I am attempting to use hls4ml on a YOLOv2 network. I have the following network fragment:
network = layers.Conv2D(128, kernel_size=3, strides=1, padding="same")(network)
network = layers.BatchNormalization()(network)
network = layers.LeakyReLU()(network)
network = layers.Conv2D(64, kernel_size=1, strides=1, padding="same")(network)
network = layers.BatchNormalization()(network)
network = layers.LeakyReLU()(network)
Printed Network Structure:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) [(None, 104, 104, 64)] 0
conv2d_2 (Conv2D) (None, 104, 104, 128) 73856
batch_normalization_2 (Bat (None, 104, 104, 128) 512
chNormalization)
leaky_re_lu_2 (LeakyReLU) (None, 104, 104, 128) 0
conv2d_3 (Conv2D) (None, 104, 104, 64) 8256
batch_normalization_3 (Bat (None, 104, 104, 64) 256
chNormalization)
leaky_re_lu_3 (LeakyReLU) (None, 104, 104, 64) 0
=================================================================
Total params: 82880 (323.75 KB)
Trainable params: 82496 (322.25 KB)
Non-trainable params: 384 (1.50 KB)
_________________________________________________________________
hls4ml config:
hls_config = hls4ml.utils.config_from_keras_model(network, granularity='name')
hls_config['Model']['Precision'] = 'ap_fixed<32,8>'
hls_config['Model']['Strategy'] = 'resource'
for Layer in hls_config['LayerName'].keys():
hls_config['LayerName'][Layer]['Precision'] = 'ap_fixed<32,8>'
hls_config['LayerName'][Layer]['Strategy'] = 'resource'
try:
params_num = network.get_layer(Layer).count_params()
if (params_num >= 1) & (("conv2d" in network.get_layer(Layer).name)
| ("dense" in network.get_layer(Layer).name)):
reuse_factor = int(params_num / 1)
hls_config['LayerName'][Layer]['ReuseFactor'] = reuse_factor
except ValueError:
pass
hls_model = hls4ml.converters.convert_from_keras_model(network, io_type='io_stream', backend='Vivado',
output_dir='YOLOv2/kernel_1_HLS', project_name='kernel_1',
part='xcvu35p-fsvh2104-1-e', hls_config=hls_config)
hls_model.build(reset=False, csim=False, synth=False, cosim=False,
validation=False, export=False, vsynth=False, fifo_opt=False)
Building Log:
Creating HLS model
WARNING: Invalid ReuseFactor=73856 in layer "conv2d_2".Using ReuseFactor=73728 instead. Valid ReuseFactor(s): 1,2,3,4,6,8,9,12,16,18,24,32,36,48,64,72,96,144,192,288,576,1152,2304,4608,9216,18432,36864,73728.
WARNING: Invalid ReuseFactor=8256 in layer "conv2d_3".Using ReuseFactor=8192 instead. Valid ReuseFactor(s): 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192.
WARNING: Config parameter "trace" overwrites an existing attribute in layer "conv2d_3" (PointwiseConv2D)
WARNING: Config parameter "precision" overwrites an existing attribute in layer "conv2d_3" (PointwiseConv2D)
WARNING: Config parameter "strategy" overwrites an existing attribute in layer "conv2d_3" (PointwiseConv2D)
WARNING: Config parameter "reuse_factor" overwrites an existing attribute in layer "conv2d_3" (PointwiseConv2D)
Error Message during VivadoHLS C synthesis:
ERROR: [XFORM 203-103] Array 'w11.V' : partitioned elements number (8192) has exceeded the threshold (4096), which may cause long run-time.
ERROR: [HLS 200-70] Pre-synthesis failed.
73728 also far exceeds 4096, but there was no error reported. I guess the error only occurs with the PointwiseConv. I'm looking for guidance on how to resolve this issue. Any assistance would be greatly appreciated.