My Custom Deep learning Layer is giving me an error

5 views (last 30 days)
I am using CNN of time series data from 8 channels with 500 time samples. My Deep learning architecture consists of the following layers. In the First step i perform 1D convolution across the channels (input size [500 8 1 ])so I get 16, [500 x 1 ] arrays and the output size becomes [500 x 1 x 16].
I wrote a custom function to reshape its size to [500 x 16 ] but it gives me an error when i train the network.
please just see the pictures and help me out. I have tried my best to explain it as far as I can. Thanks
Picture1.png
When I Analyzed the network using analyzeNetwork(layers). It showed that my Architecture is correct Here are the results of it
Capture.JPG
But When I start training the Network It gives me the following error
Capture.JPG
Here is the code to the Reshape Layer which I wrote:
classdef reshapeLayer < nnet.layer.Layer
properties
end
methods
function layer = reshapeLayer(Name)
layer.Name = Name;
end
function [Z] = predict(layer, X)
sz = [size(X,1) size(X,2)*size(X,3) size(X,4)];
Z = reshape(X , sz);
end
function [dldx] = backward(layer,~,~,dldz,~)
sz = [size(dldz,1) , 1 , size(dldz,2) , size(dldz,3)];
dldx = reshape(dldz , sz);
end
end
end
  1 Comment
Paola HUMBERT
Paola HUMBERT on 8 Jun 2020
Hello,
Could you find the error in your code ? The answer would interest me.
Thank you.

Sign in to comment.

Answers (1)

Lucas Teng
Lucas Teng on 7 Aug 2020
Update your matlab version to at least 2020a and enter the following code into command:
edit(fullfile(matlabroot,'examples','nnet','main','projectAndReshapeLayer.m'))
You'll learn it.

Community Treasure Hunt

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

Start Hunting!