Variable changes unwantedly during repeated run

조회 수: 8 (최근 30일)
Gianluca Fuwa
Gianluca Fuwa 2021년 5월 21일
댓글: Gianluca Fuwa 2021년 5월 24일
Hello,
I am currently trying to build a custom Neural Network using the Deep Network Designer and was getting an error message for one of my custom layers.
In said layer I want to multiply its input + bias with the weight matrix, but for some reason after a couple cycles the input vector changes its size so that the product can't be calculated.
The layer is the following
classdef weightedAdditionLayer < nnet.layer.Layer
% Example custom weighted addition layer.
properties
inputsize
outputsize
end
properties (Learnable)
Weights
end
methods
function layer = weightedAdditionLayer(a,b,name)
% Set layer name.
layer.Name = name;
% Set layer description.
layer.Description = "Weighted addition of inputs";
layer.inputsize = a;
layer.outputsize = b;
% Initialize layer weights.
layer.Weights = rand(layer.inputsize,layer.outputsize);
end
function Z = predict(layer, X)
Z = layer.Weights.' * [1;X(:)];
end
end
end
The vector that changes size is [1;X(:)], which goes from the wanted (201 x 1) to (12513 x 1) after approx. 6 cycles every time.
Could there be any reason in and/or outside of the code that causes this behaviour?
  댓글 수: 4
Tarunbir Gambhir
Tarunbir Gambhir 2021년 5월 24일
Can you try training your network using a dlarray with correct data format. You can convert your training data to dlarray and specify the data format, then use this dlarray for network training.
Gianluca Fuwa
Gianluca Fuwa 2021년 5월 24일
So, I figured out that the problem was the mini-batch size in my training options which caused an input to become size (98 x 1 x 1 x 128) because the mini batch size was 128.
After changing it to 1 everything worked fine.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by