insertion of equation in classification layer of deep neural network for semantic segmetnation.

1 次查看(过去 30 天)
I need to implement the following equation in the classification layer.
Equation:
d(t,x) is Euclidean distance between x and t.
code for classfication layer
%%%%%%%%%%%%%%%
classdef ClassificationLayer < nnet.layer.ClassificationLayer
properties
%
end
methods
function layer = ClassificationLayer(name)
% l
l
% Set layer name.
layer.Name = name;
end
% Set layer description
layer.Description = ' cross entropy loss';
end
function loss = forwardLoss(layer, Y, T)
% loss = forwardLoss(layer, Y, T) returns the cross entropy loss between the predictions Y and the training targets T.
N = size(Y,4);
Y = squeeze(Y);
T = squeeze(T);
prod = T.*log(Y));
loss = -sum(prod(:))/N;
end
function dLdY = backwardLoss(layer, Y, T)
% dLdX = backwardLoss(layer, Y, T) returns the derivatives of the cross entropy loss with respect to the predictions Y.
Y = squeeze(Y);
T = squeeze(T);
dLdY = -(T./Y)/N;
end
end
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by