How to add 2 or more hidden layer to the neural network?

1 view (last 30 days)
I have this code i need to add 2 hidden layer, can anyone please help me with that please. Here is the code
[J,grad] = netcost(nn_params,input_layer_size,hidden_layer_size,num_labels,X, y, lambda)
Theta1 = reshape(nn_params(1:hidden_layer_size * (input_layer_size + 1)), ... hidden_layer_size, (input_layer_size + 1));
Theta2 = reshape(nn_params((1 + (hidden_layer_size * (input_layer_size + 1))):end), ... num_labels, (hidden_layer_size + 1));
num_labels=2; 1 hidden layer; input neurons=2160,hidden layer neuron=20; I want to add totally 2 hidden layers, please can anyone help me with the code please
  9 Comments
Philip G
Philip G on 20 Apr 2017
Edited: Philip G on 20 Apr 2017
Just executing the command
net=feedforwardnet([200 200 200]);
Does not give any errors and will give you a network with 3 hidden layers of size 200 (see attached image). I am not sure what your error is. Also in the code above "netcost" is not a MATLAB function - so it is hard to say where your error comes from (especially this strange behavior that you can not create a network with a layer size bigger than 100).
Tousif Ahmed
Tousif Ahmed on 20 Apr 2017
i will post the code here. please have a look.
load latest.mat; trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
net.performFcn = 'mse'; %newly added
hiddenLayerSize = 10; %net = patternnet(hiddenLayerSize); net=feedforwardnet([50 10]);
view (net); net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100;
net.trainParam.epochs = 100;
[net,tr] = train(net,training,test); y = net(training); e = gsubtract(test,y); performance = perform(net,test,y) tind = vec2ind(test); yind = vec2ind(y); percentErrors = sum(tind ~= yind)/numel(tind);
net.IW{1,1}; net.b{1}; %net.LW {1};
% View the Network view(net)
I have attached the file named 'latest.mat'.It contains image file of size 27x18, 11 images for training and 2 images for test. I dont know whether the procedure i have followed to add the images for training and test are correct. Please correct me if i am wrong and please have a look

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!