My Custom Deep learning Layer is giving me an error

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

Lucas Teng
Lucas Teng 2020-8-7
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.

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by