How to replace imageInputLayer with sequenceInputLayer in imported Tensorflow Keras network

10 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Raunak Gupta
Raunak Gupta am 3 Okt. 2020
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 Kommentar
Paromita Kundu
Paromita Kundu am 1 Mär. 2024
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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by