Borrar filtros
Borrar filtros

Error using * in dotprod.apply when training custom network with train

2 visualizaciones (últimos 30 días)
Hi everyone,
I have a neural network that is initiated with the following code:
close all
clear all %#ok<CLALL>
clc
load iris_dataset; % Load iris dataset
% Modify irisTargets to include a fourth output that is always zero. This
% makes it compatible with a network that has two output 2x2 layers.
irisTargets=[irisTargets; zeros(1,length(irisTargets))];
net=network; % Generate network
net.numInputs=4; % 4 inputs
net.inputs{:}.size=1; % Input size of 1
net.numlayers=6; % 6 total layers
net.layers{1:4}.size=1; % First 4 layers are hidden, and
% have one neuron each.
net.layers{5:6}.size=2; % Last 2 layers are output layers,
% and have two neurons each.
net.inputconnect(1:2,1:2)=1; % First 4 layers are fully
% connected with 2 of the 4
% inputs. Simulates 2x2
% network, and can be 'split'
% later on.
net.inputconnect(3:4,3:4)=1; % Last 2 layers are fully connected
% with 2 of the 4 hidden
% layers.
net.inputweights{1:2,1:2}.initfcn='initzero'; % Initialize input weights to 0
net.inputweights{3:4,3:4}.initfcn='initzero';
net.inputweights{1:2,1:2}.learnfcn='learnp'; % Learn with input weights > 0 ?
net.inputweights{3:4,3:4}.learnfcn='learnp';
net.layerconnect(5,1:2:3)=1; % Connect layers 1 and 3 to
% layer 5
net.layerconnect(6,2:2:4)=1; % Connect layers 2 and 4 to
% layer 6
net.layers{1:4}.transferfcn='poslin'; % ReLU activation function
net.layers{5:6}.transferfcn='hardlim'; % Step activation function
net.layerweights{5,1:2:3}.initfcn='initzero'; % Initialize layer weights to 0
net.layerweights{6,2:2:4}.initfcn='initzero';
net.layerweights{5,1:2:3}.learnfcn='learnp'; % Learn withh layer weights > 0 ?
net.layerweights{6,2:2:4}.learnfcn='learnp';
net.outputconnect(5:6)=1; % Connect layers 5 and 6 to outputs
net.initfcn='initlay';
net.trainfcn='trainc';
net.performfcn='mae';
view(net)
net=train(net, irisInputs, irisTargets); % Train network with iris
% dataset inputs and
% modified iris dataset
% outputs. This is where
% the error occurs.
It generates the following output from view(net):
However, when the code reaches the last line, it generates the following error:
Error using *
Inner matrix dimensions must agree.
Error in dotprod.apply (line 6)
z = w*p;
Error in nn7.y_all
Error in nn7.perf_all (line 5)
data = nn7.y_all(net,data,fcns);
Error in nn7.perf_sig_grad (line 7)
[perf,data] = nn7.perf_all(net,data,fcns);
Error in trainc>train_network (line 198)
[dperf,divData,gB,gIW,gLW,gA] = nn7.perf_sig_grad(net,divData,needGradient,fcns);
Error in trainc (line 55)
[out1,out2] = train_network(varargin{2:end});
Error in network/train (line 353)
[net,tr] = feval(net.trainFcn,'apply',net,tr,data,calcMode.options,hints,net.trainParam);
Error in mynn (line 58)
net=train(net, irisInputs, irisTargets); % Train network with iris
I have done as much digging as I can, considering the limited access I have to the files, and I found that, at some point, the "p" input to "dotprod.apply" became empty. That said, I cannot figure out why, since the file that calls "dotprod.apply" has restricted access. I did make sure to double check the matrix calculations that should be going on before actually running the code, so I am really confused. Any help with this would be greatly appreciated!
Cheers!

Respuestas (0)

Categorías

Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by