Error using deep learning custom recurrent layer: Illegal attribute 'State'.

1 回表示 (過去 30 日間)
Rebecca Plant
Rebecca Plant 2021 年 11 月 8 日
コメント済み: Rebecca Plant 2021 年 11 月 11 日
Hi everyone,
I'm facing an error with a custom intermediate layer using the Deep Learning Toolbox. The layer gets sequence input data, has two states and no learnable parameters. Its task is simply to output the difference between the current input and the input at the previous time step. I tried designing the layer according to the peephole LSTM example (https://de.mathworks.com/help/deeplearning/ug/define-custom-recurrent-deep-learning-layer.html). Unfortunately, when I try to construct the layer using
forwardDifferenceLayer(100,'Name','forward difference')
I get the error message:
Error using forwardDifferenceLayer
Illegal attribute 'State'.
Here's my code for the layer. Can anyone see what I'm doing wrong? Thanks a lot in advance.
classdef forwardDifferenceLayer < nnet.layer.Layer & nnet.layer.Formattable
properties
% (Optional) Layer properties.
NumHiddenUnits
end
properties (State)
% (Optional) Layer state parameters.
HiddenState
CellState
end
methods
function layer = forwardDifferenceLayer(numHiddenUnits, args)
% (Optional) Create a myLayer.
% This function must have the same name as the class.
arguments
numHiddenUnits
args.Name = '';
end
layer.Name = args.Name;
layer.NumHiddenUnits = numHiddenUnits;
end
function [Z,hiddenState,cellState] = predict(layer,X)
if isempty(layer.CellState)
hiddenState = zeros(size(X));
cellState = X;
else
hiddenState = X - layer.CellState;
cellState = X;
end
Z = dlarray(single(hiddenState));
end
function layer = resetState(layer)
% (Optional) Reset layer state.
layer.HiddenState = zeros(layer.NumHiddenUnits,1);
layer.CellState = zeros(layer.NumHiddenUnits,1);
end
end
end

採用された回答

Swatantra Mahato
Swatantra Mahato 2021 年 11 月 11 日
Hi Rebecca,
The feature to "Define stateful custom layers" used in the example "Define Custom Recurrent Deep Learning Layer" was added in MATLAB R2021b as mentioned in the release notes
Hence 'State' is not recognized as a legal attribute
Hope this helps
  1 件のコメント
Rebecca Plant
Rebecca Plant 2021 年 11 月 11 日
Hi Swatantra, thanks a lot for your answer. That totally makes sense. I'll update to 21b then.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBuild Deep Neural Networks についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by