Variable changes unwantedly during repeated run

9 views (last 30 days)
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 Comments
Tarunbir Gambhir
Tarunbir Gambhir on 24 May 2021
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 on 24 May 2021
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.

Sign in to comment.

Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!