Error occurs when I use importKerasNetwork function to import my LSTM RNN into MATLAB
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I was trying to import my trained model from python Keras to MATLAB, the input of the network is a 3 timesteps, 48 features matrix so each sample of my rnn is a (3,48,1) matrix, which is passed into a LSTM layer and then a Dense layer. this simple RNN works fine in python so I saved the trained model in.h5 file and tried to import it to MATLAB using importKerasNetwork function. However, an error occured.
the command I used is the following:
path = strcat('./data/','model','.h5');
importKerasNetwork(path)
the error shows:
Warning: File './Traffic_data/model_0_0.h5' was saved in Keras version '2.4.0'. Import of Keras versions newer
than '2.2.4' is not supported. The imported model may not exactly match the model saved in the Keras file.
Error using assembleNetwork (line 47)
Invalid network.
Error in nnet.internal.cnn.keras.importKerasNetwork (line 35)
Network = assembleNetwork(LayersOrGraph);
Error in importKerasNetwork (line 91)
Network = nnet.internal.cnn.keras.importKerasNetwork(modelfile, varargin{:});
Caused by:
Network: Incompatible layer types. The network contains layer types not supported with recurrent layers.
Detected recurrent layers:
layer 'lstm_5' (LSTM)
Detected incompatible layers:
layer 'lstm_5_input' (Image Input)
Layer 'lstm_5': Input size mismatch. LSTM layers must have scalar input size, but input size (3×48×1) was
received. Try using a flatten layer before the LSTM layer.
I wondering How could I fix it. If anyone could give some insight on this I would greatly appreciate it.
Thank you.
0 个评论
采纳的回答
Rishik Ramena
2020-12-2
You can try importing the layers of your model using the importKerasLayers function to import the model layerwise into MATLAB. You can then edit the layers prior to the lstm layer to fix this.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!