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
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!