Hi, how do I fix the error please? i would like to build model with both sequance and image input layers, thanks

1 visualizzazione (ultimi 30 giorni)
lgraph = layerGraph();
tempLayers = [
imageInputLayer([25 1 1],"Name","imageinput")
convolution2dLayer([3 1],32,"Name","conv_1","Padding","same")
convolution2dLayer([3 1],32,"Name","conv_2","Padding","same")
flattenLayer("Name","flatten")];
lgraph = addLayers(lgraph,tempLayers);
seqInput = sequenceInputLayer(1,'Name','sequance1');
lgraph = addLayers(lgraph,seqInput);
seqInput = [
concatenationLayer(1,2,"Name","concat")
fullyConnectedLayer(10,"Name","fc_1")
fullyConnectedLayer(10,"Name","fc_2")
fullyConnectedLayer(10,"Name","fc_3")
classificationLayer("Name","classoutput")];
lgraph = addLayers(lgraph,seqInput);
lgraph = connectLayers(lgraph,"sequance1","concat/in1");
lgraph = connectLayers(lgraph,"flatten","concat/in2");
plot(lgraph)
analyzeNetwork(lgraph)

Risposte (1)

Ben
Ben il 13 Mar 2023
Concatenation does not expand over dimensions, for example the following errors:
x = rand(1,10);
y = rand(1);
cat(1,x,y)
If you want to concatenate the output of flatten with the output of sequance1 you will need to define how to concatenate these two inputs with different dimensions.
One way might be to repeat the flatten output over the sequence dimension, then concatenate. You can do this repetition over the sequence dimension with a functionLayer:
repeatLayer = functionLayer(@(x,y) dlarray(repmat(x,[1,1,size(y,3)]),"CBT"),Formattable=true)
Connect flatten to the first input of repeatLayer and sequance1 to the 2nd input of repeatLayer. Then connect repeatLayer and sequance1 up to concat.
Note that this is only one way to define concatenating a sequence and non-sequence, you may want to implement a different way to concatenate using a functionLayer or custom layer.

Community Treasure Hunt

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

Start Hunting!

Translated by