MATLAB Answers

Ben Hur

how to use multiple input layers in DAG net as shown in the figure

Asked by Ben Hur
on 26 Nov 2017
Latest activity Edited by Yuze Zou on 24 Jun 2019
I have DAG graph with two paths of layers inside it.
I am planning to feed this DAG with two types of data (D1, D2) but I can't do it as the DAG in matlab accept just one input layer.
I need to form a layer such as:
I noticed that there is a custom network that can provide a network with multiple inputs but how can I connect between this network and DAG graph? or how could I use DAG with two inputs?


Ben Hur
2017 年 11 月 26 日
Guys I really confused with how to use two inputs data with Dag graph, Any idea?
Ben Hur
2017 年 11 月 27 日
Ville Laukkanen 2017 年 12 月 5 日
This would be nice to have an answer to.
I have a similar situation with three image + three float-variables regression case. We're trying to estimate the output of an industrial process with images of material flows in from three different lines and their respective line-speed (float). I get the true output result much later. Would like to train the whole image regression thing together.
Maybe some modified version of LSTM would work or perhaps some funny layer which would decompose the input to six different layergraph-lines, but I can't find a way to do this in MatLab.
On Python Tensorflow there is the node structure and inputs given in dictionary (matlabs' struct). Would there be a way to do this in Matlab? - Input to several points in an layer graph.

Sign in to comment.

4 Answers

回答者: Mahmoud Afifi 2019 年 2 月 10 日

One idea is to feed the network with concatenated inputs (e.g., image1;image2) then create splitter layers that split each input. The problem here is that you have to feed the network with .mat files, not image paths. Another idea is to store your images as tiff files which can hold 4 channels. In this case, you can store a colored image (3 channel) and a grayscale one. Have a look at this example .. see twoStream.m file.


2019 年 4 月 30 日
Can you give the code of splitter layer? Or how it can be implemented?
Mahmoud Afifi 2019 年 4 月 30 日
Here is an example
%assume your input has 6 channels (i.e., two images stacked together
channels = 6;
inputSize = [224,224,channels]; %change it as you want
lgraph = layerGraph;
input_layer = imageInputLayer(inputSize,'Name','Input_Layer');
lgraph = addLayers(lgraph,input_layer);
for i = 1 : channels
eval(sprintf('ch_%d_splitter = convolution2dLayer(1,1,''Name'',''channel_%d_splitter'',''WeightLearnRateFactor'',0,''BiasLearnRateFactor'',0,''WeightL2Factor'',0,''BiasL2Factor'',0);',i,i));
eval(sprintf('ch_%d_splitter.Weights = zeros(1,1,channels,1);',i));
eval(sprintf('ch_%d_splitter.Weights(1,1,%d,1) = 1;',i,i));
eval(sprintf('ch_%d_splitter.Bias = zeros(1,1,1,1);',i));
eval(sprintf('lgraph = addLayers(lgraph,ch_%d_splitter);',i));
eval(sprintf('lgraph = connectLayers(lgraph,''Input_Layer'',''channel_%d_splitter'');',i));
%Here, let's assume you want to use the first three layers as input for
%the first stream and the last three layers as input for second stream
input_stream_1 = depthConcatenationLayer(3,'Name','input_stream_1');
lgraph = addLayers(lgraph,input_stream_1);
input_stream_2 = depthConcatenationLayer(3,'Name','input_stream_2');
lgraph = addLayers(lgraph,input_stream_2);
lgraph = connectLayers(lgraph,'channel_1_splitter','input_stream_1/in1');
lgraph = connectLayers(lgraph,'channel_2_splitter','input_stream_1/in2');
lgraph = connectLayers(lgraph,'channel_3_splitter','input_stream_1/in3');
lgraph = connectLayers(lgraph,'channel_4_splitter','input_stream_2/in1');
lgraph = connectLayers(lgraph,'channel_5_splitter','input_stream_2/in2');
lgraph = connectLayers(lgraph,'channel_6_splitter','input_stream_2/in3');
%now you can continue building your two-stream network. The first input
%will come from input_stream_1 and the second input will come from
Yuze Zou
2019 年 6 月 24 日
Thank you so much! Haha, maybe you can put more illustration on the codes. It's a nice trick to split the input layer using convolution2dLayer with preset weights and bias. The WeightLearnRateFactor=0 and etc. settings keep the added layers unchanged during the learning process.

Sign in to comment.

回答者: Shounak Mitra 2018 年 10 月 8 日

Hi Marcello and Arjun,
Support for multiple Input layers are not supported as of the 18b release. We are working on it and it should be available soon.
Thanks Shounak


abir zendagui 2019 年 1 月 6 日
Is the multiple input layers are really supported now (In 18b)? if it' is the case ,how this is done please?
Bodo Rosenhahn 2019 年 5 月 16 日
are multiple input /output layers for DAG networks supported in 19a ? Can you provide an example ?

Sign in to comment.

回答者: Bernhard Suhm
2017 年 12 月 12 日

Modeling DAG graphs with multiple inputs and/or outputs is currently not supported in our deep learning framework, but we are working on it. So hold your breath for one of the next releases.


Bernhard Suhm
2017 年 12 月 29 日
It's our policy to not officially commit to functionality prior to the release date, but more support for DAG is planned for 18a.
Arjun Desai 2018 年 6 月 30 日
Is it supported now?
Marcello Venzi 2018 年 9 月 20 日
Hello, can you please comment if multiple input layers are now supported (as of maltab 2018b)? I could not find this option in the documentation.

Sign in to comment.

回答者: Yanhui Guo 2018 年 10 月 24 日

In the DAGNetwork file, I found the property: InputLayerIndices. In the fasterrcnn, I also found two input for this network. I am wondering if matlab2018b has an indirect way to support multiple inputs? Thanks.


Sign in to comment.