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 Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!