Variable changes unwantedly during repeated run

9 次查看(过去 30 天)
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