Can we connect the fullyconnected layer of the Vgg19 pretrained model with the TCN block so that the Vgg19 and TCN can be combined? I have 2 Errors and I need to be solved
2 views (last 30 days)
Show older comments
net = vgg19;
lgraphUpdated = layerGraph(net);
lgraphUpdated = removeLayers(lgraphUpdated,'output');
lgraphUpdated = removeLayers(lgraphUpdated,'prob');
% Replace the fullyconnected with 1000 class with fullyconnected with 2
% clases
newFCLayer = fullyConnectedLayer(numClasses,'Name','new_fc','WeightLearnRateFactor',10,'BiasLearnRateFactor',10);
lgraphUpdated = replaceLayer(lgraphUpdated,'fc8',newFCLayer);
% add a flatten layer after the fullyconnected layer
newadd = flattenLayer('Name','f1');
lgraphUpdated = addLayers(lgraphUpdated,newadd);
% TCN Model % start the TCN model with the flatten layer of the Vgg19
% then pass the output of the flatten layer to 1D convolution dilated
% casual layer
numFeatures = 2;
numFilters = 64;
filterSize = 5;
dropoutFactor = 0.005;
numBlocks = 4;
lgraph = lgraphUpdated.Layers;
lgraph = layerGraph(lgraph);
outputName = 'f1';
for i = 1:numBlocks
dilationFactor = 2^(i-1);
layers = [
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal",Name="conv11_"+i)
layerNormalizationLayer
dropoutLayer(dropoutFactor)
convolution1dLayer(filterSize,numFilters,DilationFactor=dilationFactor,Padding="causal")
layerNormalizationLayer
reluLayer
dropoutLayer(dropoutFactor)
additionLayer(2,Name="add_"+i)];
% Add and connect layers.
lgraph = addLayers(lgraph,layers);
lgraph = connectLayers(lgraph,outputName,"conv11_"+i);
% Skip connection.
if i == 1
% Include convolution in first skip connection.
layer = convolution1dLayer(1,numFilters,Name="convSkip");
lgraph = addLayers(lgraph,layer);
lgraph = connectLayers(lgraph,outputName,"convSkip");
lgraph = connectLayers(lgraph,"convSkip","add_" + i + "/in2");
else
lgraph = connectLayers(lgraph,outputName,"add_" + i + "/in2");
end
% Update layer output name.
outputName = "add_" + i;
end
layers = [
fullyConnectedLayer(numClasses,Name="fc")
softmaxLayer
classificationLayer];
lgraph = addLayers(lgraph,layers);
lgraph = connectLayers(lgraph,outputName,"fc");
analyzeNetwork(lgraph);
x = 0;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1249222/image.png)
0 Comments
Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!