Input size mismatch with dlnetwork

2 Ansichten (letzte 30 Tage)
Travis Wiens
Travis Wiens am 29 Nov. 2019
Bearbeitet: Travis Wiens am 29 Nov. 2019
I'm trying to do some GAN tranfer learning and am getting some errors when I try to add layers before existing layers when I use a dlnetwork. Here's a minimal example:
%% make network 1
layers1=[imageInputLayer([8 1],'Normalization','none','Name','in1')
fullyConnectedLayer(20,'Name','FC1')
tanhLayer('Name','T1')
fullyConnectedLayer(1,'Name','Lout')
];
lgraph1 = layerGraph(layers1);
dlnet1 = dlnetwork(lgraph1);
%% optionally do some training on dlnet1
%% add layers in front of network 1
layersNew = [imageInputLayer([16 1],'Normalization','none','Name','in2');
fullyConnectedLayer( 8,'Name','FC2')
tanhLayer('Name','T2')
];
lgraph2 = layerGraph(dlnet1);
%lgraph2= lgraph1
lgraph2 = addLayers(lgraph2,layersNew);
lgraph2 = disconnectLayers(lgraph2,'in1','FC1');
lgraph2 = connectLayers(lgraph2,'T2','FC1');
lgraph2 = removeLayers(lgraph2,'in1');
dlnet2 = dlnetwork(lgraph2);
This results in the error
Error using dlnetwork (line 81)
Invalid network.
Error in minimum_error (line 24)
dlnet2 = dlnetwork(lgraph2);
Caused by:
Layer 'FC1': Input size mismatch. Size of input to this layer is
different from the expected input size.
Inputs to this layer:
from layer 'T2' (1×1×8 output)
Presumably this is because of the 1-D "image" I'm forced to use rather than a generic 1D vector input. T2 is giving a 1x1x8 output whereas FC is expecting 8x1 (or maybe 1x8) input. The weird thing is that if I uncomment the "lgraph2= lgraph1" line, there is no error. So there must be a matrix permutation happening in the layerGraph->dlnetwork->layerGraph conversion.
I can't find any way to permute or reshape the output of a layer to resolve this. Any workaround?

Antworten (0)

Kategorien

Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by