I want to get the weights between the last hidden layer and output layer from the deep neural network designed using matlab codes.
I have tried with net.LW but it is returning the weights between 2 hidden layers.
CodePudding user response:
You can use net.LW to pass in two indices to get the weights between two layers.
net.LW{i,j}
Use numel(net.layers) to get the number of layers. This will be the index of the output layer. One less is the index of the last hidden layer.
j = numel(net.layers)
i = numel(net.layers) - 1
net.LW{i,j}
You can update with variables for your app.
MATLAB Answers Reference: https://www.mathworks.com/matlabcentral/answers/499607-set-a-specific-weight-for-a-connection-in-neural-networks