Flatten layer creating a lot of logic
Due to #378, Keras Flatten
layers are now mapped to hls4ml Reshape
layers instead of being skipped. While harmless for io_parallel
implementations, for io_stream
, these result in the creation of repack_stream
through the ReshapeStream
optimizer which changes the depth of the hls::stream
being used.
The most common case I see this happening is for CNN classifiers with Conv2D -> Flatten -> Dense
. It seems this creates a lot of (unnecessary?) logic, as the same model works when skipping the optimizer and produces a lot less logic.
As an example, the TinyML Conv2D model with master gives (example here) :
+-----------------+---------+-------+--------+-------+-----+
| Name | BRAM_18K| DSP48E| FF | LUT | URAM|
+-----------------+---------+-------+--------+-------+-----+
|DSP | -| -| -| -| -|
|Expression | -| -| 0| 2| -|
|FIFO | 163| -| 16481| 54096| -|
|Instance | 100| 0| 47685| 79522| 0|
|Memory | -| -| -| -| -|
|Multiplexer | -| -| -| 9| -|
|Register | -| -| 1| -| -|
+-----------------+---------+-------+--------+-------+-----+
|Total | 263| 0| 64167| 133629| 0|
+-----------------+---------+-------+--------+-------+-----+
|Available | 280| 220| 106400| 53200| 0|
+-----------------+---------+-------+--------+-------+-----+
|Utilization (%) | 93| 0| 60| 251| 0|
+-----------------+---------+-------+--------+-------+-----+
while if we skip the optimizer we get (example here):
+-----------------+---------+-------+--------+-------+-----+
| Name | BRAM_18K| DSP48E| FF | LUT | URAM|
+-----------------+---------+-------+--------+-------+-----+
|DSP | -| -| -| -| -|
|Expression | -| -| 0| 2| -|
|FIFO | 163| -| 6241| 13136| -|
|Instance | 99| 0| 30015| 34856| 0|
|Memory | -| -| -| -| -|
|Multiplexer | -| -| -| 9| -|
|Register | -| -| 1| -| -|
+-----------------+---------+-------+--------+-------+-----+
|Total | 262| 0| 36257| 48003| 0|
+-----------------+---------+-------+--------+-------+-----+
|Available | 280| 220| 106400| 53200| 0|
+-----------------+---------+-------+--------+-------+-----+
|Utilization (%) | 93| 0| 34| 90| 0|
+-----------------+---------+-------+--------+-------+-----+