How to define a custom loss function using SSIM
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!