Enginius/Python&TensorFlow

TensorFlow-trained network in MATLAB

해리s 2017. 1. 10. 12:49

TensorFlow Code


MATLAB Code

main.m

ccc
%% LOAD TENSORFLOW WEIGHTS
ccc

% LOAD TRAINED NETWORK PARAMETERS
l = load('data/mlp.mat');

% MLP FORWARD PATH
out = mlp(l.testimg, l.w1, l.w2, l.wout ...
    , l.b1, l.b2, l.bout);
[~, pred] = max(out, [], 2);
[~, answ] = max(l.testlabel, [], 2);

% CHECK TEST ACCUARACY
iseq = (answ == pred);
acc = mean(iseq);
fprintf('TEST ACCURACY IS %.2f%% \n', acc*100);


mlp.m

function out = mlp(x, w1, w2, wout, b1, b2, bout)
% MLP FORWARD PATH

n   = size(x, 1);
l1  = sigmoid(x*w1 + repmat(b1, n, 1));
l2  = sigmoid(l1*w2 + repmat(b2, n, 1));
out = l2*wout + repmat(bout, n, 1);

function out = sigmoid(in)
% SIGMOID FUNCTION
out = 1./ (1+exp(-in));