CNN error; trainNetwork(XTrain, TTrain, layers, opts); Layer 11 is expected to have a different size

1 vue (au cours des 30 derniers jours)
Hello everyone I am trying to implement the following program taken from:
"Deep Learning for Computer Vision with MATLAB"
https://la.mathworks.com/matlabcentral/fileexchange/58030-example-files-for--deep-learning-for-computer-vision-with-matlab--webinar?s_tid=prof_contriblnk
There they use images of 32x32 but my images are of 720x480, my code is the following already adapted but I have problems in the part: "Define the architecture of CNN"
Code: -------------------------------------------------------------------------------------------------- %% inicio clc; % Clear the command window. close all; % Close all figures (except those of imtool.) clear; % Erase all existing variables. Or clearvars if you want. workspace; % Make sure the workspace panel is showing.
cd c:\[CNN]\
%% Load image Training dataset (720x480 colour images in 10 classes) imsetTrain = imageSet('VideoSalida','recursive');
%% Display Sampling of Image Data numClasses = size(imsetTrain,2); imagesPerClass = 5; imagesInMontage = cell(imagesPerClass,numClasses); for i = 1:size(imagesInMontage,2) imagesInMontage(:,i) = ... imsetTrain(i).ImageLocation(randi(imsetTrain(i).Count, 1, ... imagesPerClass)); end
montage({imagesInMontage{:}},'Size',[numClasses,imagesPerClass]); title('Ejemplo de imagenes de Entrenamiento Etiquetadas por el experto medico')
%% Prepare the data for Training % Read all images and store them in a 4D uint8 input array for training, % with its corresponding class
trainNames = {imsetTrain.Description}; XTrain = zeros(480,720,3,sum([imsetTrain.Count]),'uint8'); TTrain = categorical(discretize((1:sum([imsetTrain.Count]))',... [0,cumsum([imsetTrain.Count])],'categorical',trainNames));
j = 0; tic; for c = 1:length(imsetTrain) for i = 1:imsetTrain(c).Count XTrain(:,:,:,i+j) = read(imsetTrain(c),i); end j = j + imsetTrain(c).Count; end toc;
%% Define a CNN architecture conv1 = convolution2dLayer(5,32,'Padding',2,... 'BiasLearnRateFactor',2); conv1.Weights = gpuArray(single(randn([5 5 3 32])*0.0001)); fc1 = fullyConnectedLayer(1905,'BiasLearnRateFactor',2); fc1.Weights = gpuArray(single(randn([1905 955])*0.1)); fc2 = fullyConnectedLayer(7605,'BiasLearnRateFactor',2); fc2.Weights = gpuArray(single(randn([7605 3805])*0.1));
layers = [ ... imageInputLayer([480 720 3]); conv1; maxPooling2dLayer(3,'Stride',2); reluLayer(); convolution2dLayer(5,480,'Padding',2,'BiasLearnRateFactor',2); reluLayer(); averagePooling2dLayer(3,'Stride',2); convolution2dLayer(5,960,'Padding',2,'BiasLearnRateFactor',2); reluLayer(); averagePooling2dLayer(3,'Stride',2); fc1; reluLayer(); fc2; softmaxLayer() classificationLayer()];
% Define the training options. opts = trainingOptions('sgdm', ... 'InitialLearnRate', 0.001, ... 'LearnRateSchedule', 'piecewise', ... 'LearnRateDropFactor', 0.1, ... 'LearnRateDropPeriod', 8, ... 'L2Regularization', 0.004, ... 'MaxEpochs', 10, ... 'MiniBatchSize', 100, ... 'Verbose', true);
%% Training the CNN [net, info] = trainNetwork(XTrain, TTrain, layers, opts); -------------------------------------------------------------------------------------------------- The error that gives me is the following:
Error using trainNetwork (line 140) Layer 11 is expected to have a different size.
Error in CNN (line 85) [net, info] = trainNetwork(XTrain, TTrain, layers, opts);
Caused by: Error using nnet.internal.cnn.layer.util.inferParameters>iInferSize (line 82) Layer 11 is expected to have a different size.
Can anybody help me??
Thanks in advance Angel
  2 commentaires
Joss Knight
Joss Knight le 2 Juin 2018
Too difficult to follow. Please format your code using the formatting options available in the edit window.
Von Duesenberg
Von Duesenberg le 3 Juin 2018
A good place to start debugging your model is to use the Network analyzer from the file exchange.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Tags

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by