Help in next error: Undefined variable "net" or class "net.Layers". instruction: montage(ma​t2gray(gat​her(net.La​yers(2).We​ights)));

1 view (last 30 days)
Hello Greetings to all, I'm new to MatLab, I'm trying to emulate a CNN code but I have an error, could someone help me?
My development environment is: Win 10 in 64 bits MatLab 2017b
if true
% start
clc;clear;
%%Arquitectura de la red CNN sin dropout
tamImg=227;
layers2 = [ ...
% data augmentation para conseguir mas imagenes
imageInputLayer([tamImg tamImg 3],'DataAugmentation','randcrop');
convolution2dLayer(11,96,'Padding',0,'Stride',4);
reluLayer();
crossChannelNormalizationLayer(5);
maxPooling2dLayer(3,'Stride',2); % filtros de 3x3 y saltos(stride) de 2 en 2
convolution2dLayer(5,256,'Padding',2,'Stride',1);
reluLayer(); % Rectificador Lineal --> Genera valores 0 y 1
crossChannelNormalizationLayer(5);
maxPooling2dLayer(3,'Stride',2);
convolution2dLayer(3,384,'Padding',1,'Stride',1);
reluLayer();
convolution2dLayer(3,384,'Padding',1,'Stride',1);
reluLayer();
convolution2dLayer(3,256,'Padding',1,'Stride',1);
reluLayer();
maxPooling2dLayer(3,'Stride',2);
fullyConnectedLayer(4096);
reluLayer();
fullyConnectedLayer(4096);
reluLayer();
fullyConnectedLayer(10);
softmaxLayer();
classificationLayer()];
%%Opciones del solver
opts = trainingOptions('sgdm', ...
'Momentum', 0.9, ...
'InitialLearnRate', 0.001, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.1, ...
'LearnRateDropPeriod',5, ...
'L2Regularization', 0.004, ...
'MaxEpochs', 50, ...
'MiniBatchSize', 16, ...
'Verbose', true);
%%Preparar imagenes de entrenamiento en conjuntos con el mismo numero
CarpetaRaiz = 'c:\imgs\';
categorias = {'Arterio_arterial','Arterio_venosa','Borde_placentario',...
'Capilar','Insercion_donante', 'Insercion_receptor',...
'Membrana_interfetal','Normal','Veno_arterial','Veno_venosa'};
imds = imageDatastore(fullfile(CarpetaRaiz, categorias),...
'LabelSource', 'foldernames');
% contamos imagenes
numImagenes = countEachLabel(imds);
minimo = min(numImagenes{:,2});
% usamos el metodo splitEachLabel para recortar el conjunto.
% imds = splitEachLabel(imds, minimo, 'randomize');
% Contamos despues de recortar
% countEachLabel(imds)
%%Entrenar la CNN
tic; [net4clas23, info4clas23] = trainNetwork(imds, layers2, opts); toc;
%%Visualizar los filtros aprendidos en la primera capa de convolución
figure;
% gather transfiere desde GPU hacia Workspace
montage(mat2gray(gather(net.Layers(2).Weights)));
title('Pesos primera capa');
end
The error that it sends is the following: montage(mat2gray(gather(net.Layers(2).Weights)));
Error: " Undefined variable "net" or class "net.Layers".
Error in CNN_AlexNet_Fetoscopy (line 107) montage(mat2gray(gather(net.Layers(2).Weights))); "
thks in advanced for help
Best regarts
Angel lerma

Answers (1)

Joss Knight
Joss Knight on 28 Jun 2018
Well, you've called your network net4clas23, not net, so no variable of that name exists.

Categories

Find more on Predictive Maintenance Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!