How to replace imageInputLayer with sequenceInputLayer in imported Tensorflow Keras network
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lucas Ferreira-Correia
le 1 Oct 2020
Commenté : Paromita Kundu
le 1 Mar 2024
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
0 commentaires
Réponse acceptée
Raunak Gupta
le 3 Oct 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 commentaire
Paromita Kundu
le 1 Mar 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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!