How to replace imageInputLayer with sequenceInputLayer in imported Tensorflow Keras network

12 ビュー (過去 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 日 18:45
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 ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by