How to define a custom loss function using SSIM

조회 수: 4 (최근 30일)
Bin Wang
Bin Wang 2020년 5월 17일
편집: Bin Wang 2020년 5월 17일
Hi All -- I'm relatively new to deep learning. I want to define and reconst a loss function.
I have study how to define the MAE loss function through define-custom-deep-learning-layers (https://www.mathworks.com/help/deeplearning/ug/define-custom-deep-learning-layers.html).
However, those methods are based on the computation of pixels to pixels.
I want to use the ssim as the loss function and write the code. But it does not work. Could you help me? Thank you!
function loss = forwardLoss(layer, Y, T)
% loss = forwardLoss(layer, Y, T) returns the SSIM loss between
% the predictions Y and the training targets T.
[m n R N] = size(Y);
all_loss = zeros(R,N);
for j = 1:N
for i = 1:R
temp1 = (Y(:,:,i,j));
temp2 = (T(:,:,i,j));
all_loss(i,j) = ssim(temp1,temp2); % The ssim() is to calculate the structure similarity of two gray images.
end
end
loss = 1 - mean(all_loss,'all');
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Display Point Clouds에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by