Why is it said not enough input arguments at momentum1 = zeros(size(W1)); ?
function [W1, W5, Wo] = MnistConv(W1, W5, Wo, X, D)
alpha = 0.01;
beta = 0.95;
momentum1 = zeros(size(W1));
momentum5 = zeros(size(W5));
momentumo = zeros(size(Wo));
N = length(D);
bsize = 100;
blist = 1:bsize:(N-bsize+1);
for batch = 1:length(blist)
dW1 = zeros(size(W1));
dW5 = zeros(size(W5));
dWo = zeros(size(Wo));
begin = blist(batch);
for k = begin:begin+bsize-1
x = X(:, :, k);
y1 = Conv(x, W1);
y2 = ReLU(y1);
y3 = Pool(y2);
y4 = reshape(y3, [],1);
v5 = W5*y4;
y5 = ReLU(v5);
v = Wo*y5;
y = Softmax(v);
d = zeros(10, 1);
d(sub2ind(size(d), D(k), 1)) = 1;
e = d - y;
delta = e;
e5 = Wo' * delta;
delta5= (y5 > 0).* e5;
e4 = W5' * delta5;
e3 = reshape(e4, size(y3));
e2 = zeros(size(y2));
W3 = ones(size(y2)) / (2*2);
for c = 1:20
e2(:, :,c) = kron(e3(:, :, c), ones([2 2])) .*W3(:, :, c);
end
delta2 = (y2 > 0) .* e2;
delta1_x = zeros(size(W1));
for c = 1:20
delta1_x(:, :,c) = conv2(x(:, :), rot90(delta2(:, :,c), 2), 'valid');
end
dW1 = dW1 + delta1_x;
dW5 = dW5 + delta5*y4';
dWo = dWo + delta*y5';
end
dW1 = dW1 / bsize;
dW5 = dW5 / bsize;
dWo = dWo / bsize;
momentum1 = alpha*dW1 + beta*momentum1;
W1 = W1 + momentum1;
momentum5 = alpha*dW5 + beta*momentum5;
W5 = W5 + momentum5;
momentumo = alpha*dWo + beta*momentumo;
Wo = Wo + momentumo;
end
end

 采纳的回答

"Why is it said not enough input arguments at momentum1 = zeros(size(W1)); ?"
Because you called the function without any input arguments (probably by clicking the big greeen "Run" button).
You need to call your function (e.g. from the MATLAB command line) with five input arguments, e,g.:
W1 = 1;
W5 = 2;
Wo = 3;
X = 4;
D = 5;
[W1, W5, Wo] = MnistConv(W1, W5, Wo, X, D)
Of course you will need to define appropriate arrays and values to suit whatever task you are doing, not just copy 1, 2, 3, etc. from my answer. And in future ignore that big green button.

1 个评论

it's not test code. run test MnistConvcode then run Matlab.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by