I am trying to create a weithed LSTM to Sequence-to-sequence classification. So first I created de LSTM.
numFeatures = 1;numHiddenUnits = 200;numClasses = 11;layers = [ ...sequenceInputLayer(numFeatures)lstmLayer(numHiddenUnits,'OutputMode','sequence')fullyConnectedLayer(numClasses)softmaxLayerclassificationLayer('Name','classoutput')];
Then I created the weighted layer as I found in:
classdef weightedClassificationLayer < nnet.layer.ClassificationLayerproperties% (Optional) Layer properties.ClassWeightsendmethodsfunction layer = weightedClassificationLayer(classWeights,name)% layer = weightedClassificationLayer(classWeights) creates a% weighted cross entropy loss layer. classWeights is a row% vector of weights corresponding to the classes in the order% that they appear in the training data.%% layer = weightedClassificationLayer(classWeights, name)% additionally specifies the layer name.% Set class weightslayer.ClassWeights = classWeights;% Set layer nameif nargin == 2layer.Name = name;end% Set layer descriptionlayer.Description = 'Weighted cross entropy';endfunction loss = forwardLoss(layer, Y, T)% loss = forwardLoss(layer, Y, T) returns the weighted cross% entropy loss between the predictions Y and the training% targets T.% Find observation and sequence dimensions of Y[~, N, S] = size(Y);% Reshape ClassWeights to KxNxSW = repmat(layer.ClassWeights(:), 1, N, S);% Compute the lossloss = -sum( W(:).*T(:).*log(Y(:)) )/N;endfunction dLdY = backwardLoss(layer, Y, T)% dLdY = backwardLoss(layer, Y, T) returns the derivatives of% the weighted cross entropy loss with respect to the% predictions Y.% Find observation and sequence dimensions of Y[~, N, S] = size(Y);% Reshape ClassWeights to KxNxSW = repmat(layer.ClassWeights(:), 1, N, S);% Compute the derivativedLdY = -(W.*T./Y)/N;endendend
classWeights =[0.05 0.05 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1];wLayer = weightedClassificationLayer(classWeights);
But when I try to replace the classification layer following the CNN example:
layers = replaceLayer(layers,"classoutput",wLayer);
It appears the error:
Check for missing argument or incorrect argument data type in call to function 'replaceLayer'
Can anyone help me?