Transfer learning FCN from Matconvnet
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have trained a fully convolutional network with 3 convolutional layers using Matconvnet. The FCN has been trained on 32x32 grayscale image patches and will be used to find defects in 2048x2048 grayscale images. It works as intended using Matconvnet, but for various reasons I want to try to implement it using Matlab's Neural Network toolbox. I've tried creating my network structure in Matlab and transferring weights and biases using the following code:
% Image input layer
inputLayer = imageInputLayer([2048 2048 1], 'Name', 'Input', ...
'Normalization', 'none');
% First layer
filterSize = [5 5];
numFilters = 32;
firstLayer = [
convolution2dLayer(filterSize, numFilters, 'Padding', 2, ...
'Name', 'Conv1')
maxPooling2dLayer(8, 'Stride', 4, 'Padding', 2, 'Name', 'Pool1')
reluLayer('Name', 'Relu1')
];
% Second layer
filterSize = [8 8];
numFilters = 32;
secondLayer = [
convolution2dLayer(filterSize, numFilters, 'Padding', 0, ...
'Name', 'Conv2')
reluLayer('Name', 'Relu2')
];
% Third (prediction) layer
filterSize = [1 1];
numFilters = 2;
predictionLayer = [
convolution2dLayer(filterSize, numFilters, 'Padding', 0, ...
'Name', 'Conv3')
softmaxLayer('Name', 'Softmax')
classificationLayer('Name', 'Classification')
];
layers = [
inputLayer
firstLayer
secondLayer
predictionLayer
];
% Import weights and biases from Matconvnet
layers(2).Weights = net.params(1).value;
layers(2).Bias = reshape(net.params(2).value, [1 1 32]);
layers(5).Weights = net.params(3).value;
layers(5).Bias = reshape(net.params(4).value, [1 1 32]);
layers(7).Weights = net.params(5).value;
layers(7).Bias = reshape(net.params(6).value, [1 1 2]);
matlabNet = SeriesNetwork(layers);
So my question. Are FCNs supported in Matlab and is this the correct approach to create one? I've tried using the matlabNet produced from the code but get errors concerning undefined OutputSize. I also tried training the net with trainNetwork but it complained about incorrectly sized output layers. Any ideas?
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!