- Define a set of layers with the first set of inputs and create a network using the “layerGraph” function.
- Create a set of layers for the next set of inputs and then add these layers to the first branch’s “layerGraph” using the “addLayers” function.
- Connect Layers of the network using “connectLayers” function.
Feed inputs to inner layers of a neural network (custom structure)
3 次查看(过去 30 天)
显示 更早的评论
I was wondering if Matlab allows to feed the inputs of a neural network to inner layers in a custom structure (meaning not only to the first input layer).
Here is an example of what I mean:

In this example two inputs are fed to the first block (input layer x1-x2, hidden layer, output layer u1);
Then the second block is fed with the output of the first block and other 2 inputs (input layer u1-x3-x4, hidden layer, output layer y);
Then the final output is predicted.
Is there a way to create this kind of structure with a single model?
I tried to create it using the dlnetworks command, but it obviously didn't work because multiple input layers are not supported.
(And I wouldn't even know how the training command should be written at this point)
net = dlnetwork(layers);
layers = [
%First block
sequenceInputLayer(2,"Name","Block1") %x1, x2
fullyConnectedLayer(3,"Name","fc_11")
fullyConnectedLayer(1,"Name","fc_12")
regressionLayer("Name","u1") %u1
%Second block
sequenceInputLayer(3,"Name","Block2") %u1, x3, x4
fullyConnectedLayer(3,"Name","fc_21")
fullyConnectedLayer(1,"Name","fc_22")
regressionLayer("Name","Y") %y
];
There is a lot of documentation about custom structures and custom training loops, but I feel kind of lost and I do not know where I should have a look at.
0 个评论
回答(1 个)
T.Nikhil kumar
2023-9-29
Hello,
I understand that you want to feed inputs to a custom network at different levels i.e. at the inner layers of the network.
It is possible to create networks that can take multiple inputs and process them at different stages or layers of the network. This can be done by creating separate branches for each set of inputs and then connecting them to form the final network. But note that a network can have at most one sequence input layer. Hence, you cannot create the structure you wish with 2 sequence input layers.
You can try using other types of Input Layers for this purpose.
Please find below the procedure to create a network with multiple image inputs at inner layers using “imageInputLayer”:
You can refer to the following documentation to understand more about “addLayers” and “connectLayers” layers in MATLAB.
You can refer to the following question where an example of a network having multiple inputs is implemented.
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!