fastmachinelearning / hls4ml

Machine learning on FPGAs using HLS
https://fastmachinelearning.org/hls4ml
Apache License 2.0
1.17k stars 387 forks source link

Fix profiling for Keras LSTM layers. #940

Closed Landay7 closed 6 months ago

Landay7 commented 6 months ago

Description

Before it for Keras LSTM it throws IndexError: list index out of range. I know, that there is a low chance that it will be run without the HLS model, but still would be good to set properly.

Type of change

Tests

import hls4ml
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Conv1D, Activation, MaxPooling1D, LSTM, Dense, Input

input = Input(shape = (600, 10 ), name = 'input')

x = Conv1D(
    filters = 4,
    kernel_size = 3,
    strides = 1,
    padding = 'valid',
    name = 'conv_1',
)(input)

x = Activation(
    'relu',
    name = 'conv_act_1'
)(x)
x = MaxPooling1D(
    pool_size = 3,
    padding = 'valid',
    name = 'pool_1'
)(x)
x = LSTM(16, name = 'lstm')(x)
x = Dense(10, name = 'dense')(x)

model = Model(inputs = input, outputs = x)
hls4ml.model.profiling.numerical(model = model, hls_model = None)

Checklist