how to combine/append 2 dagnetworks/LayerGraphs: Add layer graph or network to layer graph or network
Show older comments
Hi,
I am trying to combine/append 2 complex dagnetworks. One is a downloaded pretrained CNN (googlenet). The other is a complex LSTM ([netLSTM,info] = trainNetwork(sequencesTrain,labelsTrain,lg,options)) which I have entered and trained.
I want to use the output of the CNN as the input to the LSTM, with approprite editing and connecting of the input and output layers.
>>netCNN=googlenet;
>>[netLSTM,info] = trainNetwork(sequencesTrain,labelsTrain,lg,options);
>>cnnLayers = layerGraph(netCNN);
>>lstmLayers = layerGraph(netLSTM);
When I use addLayers I get:
">> netest=addLayers(cnnLayers,lstmLayers)
Error using nnet.internal.cnn.util.validateLayersForLayerGraph (line 22)
Expected input to be one of these types:
nnet.cnn.layer.Layer
Instead its type was nnet.cnn.LayerGraph.
Error in nnet.cnn.LayerGraph>iValidateLayers (line 550)
larray = nnet.internal.cnn.util.validateLayersForLayerGraph(larray, existingLayers);
Error in nnet.cnn.LayerGraph/addLayers (line 184)
larray = iValidateLayers(larray, existingLayers);"
I have tried to use netest=addLayers(cnnLayers,lstmLayers.Layers) but that removes the branching that I have used in the lstmLayers dagnetwork/layerGraph. In addition the training weights and biases of the LSTM do not transfer.
In net2=addLayers(net1, larray) net1 may be a dagnetwork/layerGraph, but larray can only be layers connected sequentially, no branching allowed.
Thank you
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!