how to combine two different lgraph and create a new network
10 ビュー (過去 30 日間)
古いコメントを表示
Hi All
I would like to combine two trained networks. in order to do that I convert each trained network to lgraph, but I don't find how to combine the 2 lgraph.
I use the following code to create the lgraph:
lgraph1 = layerGraph(net1);
lgraph2 = layerGraph(net2);
I tried connectLayers, and replaceLayer, but those function working when need to connect or replace layer in lgraph with other layer (not lgraph to lgraph).
do you have any suggestion how to overcome this issue, or any suggestion how combine 2 tarined networks when net1 is input to net2.
Basically I would like to create a new network unified network which is the combination of the 2 trained network, and use the predict function on the new unified network.
Thanks alot
0 件のコメント
採用された回答
Tomaso Cetto
2021 年 6 月 2 日
Hey Avi!
I think the addLayers function is what you're after here.
You're right in saying that these functions can't work with two layer graphs - however, what you can do is access the underlying layers of a layerGraph object, and use those when stitching up your two networks. Hopefully the code below will explain what I mean:
% Define both layer graphs
net1 = layerGraph(layers1)
net2 = layerGraph(layers2);
% Add the layers from net2 to net1
net1 = addLayers(net1, net2.Layers);
% Connect the last layer of net1 with the first layer of net2
net1 = connectLayers(net1, 'lastLayerOfNet1', 'firstLayerOfNet2');
% Call assembleNetwork to ensure your new network is ready for prediction
% and does not have any issues
net1 = assembleNetwork(net1);
Let me know if this works for you!
Tomaso
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Build Deep Neural Networks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!