Simulating neural network with code

2 views (last 30 days)
pter
pter on 1 May 2015
Commented: Greg Heath on 6 May 2015
I trained multiple neural networks in Matlab for head pose estimation. To implement the neural networks in a real-time setting I want to simulate the networks in another language, so I start writing code for Matlab first.
When I tested this code on the training set, I found out that my outputs (yaw and pitch angle) are slightly different from the outputs the training gave me. The differences are on average only one degree, but it should exactly be the same.
I already did pre- and postprocessing with mapminmax. Can anyone please tell me what I am missing here!?
My code:
target_train = target_train';
[~,outMapP] = mapminmax(target_train(1,:), -1, 1);
[~,outMapY] = mapminmax(target_train(2,:), -1, 1);
pitch = [];
yaw = [];
for i = 1:1568;
image = input_train(i,:);
%Map image between -1 and +1
[~, inMap] = mapminmax(image, -1, 1);
image = mapminmax('apply', image, inMap);
adder1 = image*IW';
layer1 = tansig(adder1'+b1);
adder2 = LW*layer1;
layer2 = purelin(adder2+b2);
out_pitch = layer2(1,1);
out_yaw = layer2(2,1);
pitch = [pitch; out_pitch];
yaw = [yaw; out_yaw];
end
%Remap the output to the right range
pitch = mapminmax('reverse', pitch, outMapP);
yaw = mapminmax('reverse', yaw, outMapY);
  1 Comment
Greg Heath
Greg Heath on 6 May 2015
MATLAB was invented to be a MATRIX based language to omit unnecessary loops.
Try using matrix equations instead of loops.
Greg

Sign in to comment.

Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!