how to combine two different lgraph and create a new network
12 次查看(过去 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 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!