-
Notifications
You must be signed in to change notification settings - Fork 1
/
cnnParamsToStack.m
33 lines (26 loc) · 1011 Bytes
/
cnnParamsToStack.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function [Wc, bc, thetaFC] = cnnParamsToStack(theta,filterDim,...
numFilters,lengthParams)
% Converts unrolled parameters for a single layer convolutional neural
% network followed by a softmax layer into structured weight
% tensors/matrices and corresponding biases
%
% Parameters:
% theta - unrolled parameter vectore
% filterDim - dimension of convolutional filter
% numFilters - number of convolutional filters
% numClasses - number of classes to predict
%
%
% Returns:
% Wc - filterDim x filterDim x numFilters parameter matrix
% bc - bias for convolution layer of size numFilters x 1
% thetaFc - unrolled parameter vector of Fully Connected parameters
%% Reshape theta
thetaFC = theta(end-lengthParams+1:end);
indS = 1;
indE = filterDim^2*numFilters;
Wc = reshape(theta(indS:indE),filterDim,filterDim,numFilters);
indS = indE+1;
indE = indE+numFilters;
bc = theta(indS:indE);
end