How to replace imageInputLayer with sequenceInputLayer in imported Tensorflow Keras network

4 次查看(过去 30 天)
Hi,
I've imported a pre-trained network from tensorflow keras on MATLAB using importKerasLayers (importKerasNetwork didn't work as I've got 3 inputs). This network is made for sequence to sequence time series regression, hence I need a sequenceInputLayer in front of the network, however when I import the network an imageInputLayer is put in front of the network. Of course that layer is unsuitable for my use case, hence I tried replacing the imageInputLayer with a sequenceInputLayer but the error below is shown. The name of the imageInputLayer is 'lstm_10_input'.
Error using nnet.internal.cnn.util.validateLayersForLayerGraph>iAssertUniqueAndNonEmptyLayerNames (line 45)
Layer names in layer array must be nonempty.
Error in nnet.internal.cnn.util.validateLayersForLayerGraph (line 33)
iAssertUniqueAndNonEmptyLayerNames(larray, existingLayers);
Error in nnet.cnn.LayerGraph>iValidateLayers (line 556)
larray = nnet.internal.cnn.util.validateLayersForLayerGraph(larray, existingLayers);
Error in nnet.cnn.LayerGraph/replaceLayer (line 420)
larray = iValidateLayers(larray, existingLayers);
Error in keras_import (line 8)
lgraph = replaceLayer(lgraph,'lstm_10_input',inputLayer);
My code is as follows:
net = importKerasLayers('model.h5', 'ImportWeights', true);
lgraph = layerGraph(net);
inputLayer = sequenceInputLayer(3);
lgraph = replaceLayer(lgraph,'lstm_10_input',inputLayer); %This is where the error occurs

采纳的回答

Raunak Gupta
Raunak Gupta 2020-10-3
Hi Lucas,
From the error message it is evident that the inputLayer in your code must contain a valid name (any character array) so that it can be replaced with ‘lstm_10_input’ layer. Giving a name to inputLayer will clear out the error message.
inputLayer = sequenceInputLayer(3,'Name','sequence_10_input');
lgraph = replaceLayer(lgraph,'lstm_10_input',inputLayer);
  1 个评论
Paromita Kundu
Paromita Kundu 2024-3-1
This is my code.I am getting the same error.What could be the reason?
layers = [
sequenceInputLayer(inputSize,'Name','input')
sequenceFoldingLayer('Name','fold')
convolution2dLayer(filterSize,numFilters,'Padding','same')
batchNormalizationLayer('Name','BN_1')
reluLayer('Name','relu_1')
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(filterSize,numFilters,'Padding','same')
batchNormalizationLayer('Name','BN_1')
reluLayer('Name','relu_1')
maxPooling2dLayer([4 2],'Stride',[4 2])
convolution2dLayer(filterSize,2*numFilters,'Padding',"same")
batchNormalizationLayer('Name','BN_1')
reluLayer('Name','relu_1')
maxPooling2dLayer([4 2],'Stride',[4 2])
convolution2dLayer(filterSize,2*numFilters,'Padding',"same")
batchNormalizationLayer('Name','BN_1')
reluLayer('Name','relu_1')
maxPooling2dLayer([4 2],'Stride',[4 2])
sequenceUnfoldingLayer('Name','unfold')
flattenLayer
lstmLayer(numHiddenUnits,'OutputMode',"last")
fullyConnectedLayer(4)
softmaxLayer
classificationLayer
];
lgraph = layerGraph(layers)
Error using layerGraph (line 62)
Layer names in layer array must be nonempty.
Error in two_cnn_lstm_ (line 58)
lgraph = layerGraph(layers);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by