how to combine two different lgraph and create a new network

11 ビュー (過去 30 日間)
Avi Sulimarski
Avi Sulimarski 2021 年 5 月 26 日
コメント済み: Avi Sulimarski 2021 年 6 月 2 日
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

採用された回答

Tomaso Cetto
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
  1 件のコメント
Avi Sulimarski
Avi Sulimarski 2021 年 6 月 2 日
Hi Tomaso
your answer was very helpful. I tried its and it working perfectly.
Thanks and best Regards
Avi

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBuild Deep Neural Networks についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by