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
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!