How to visualize the predicted values of segmentation from softmax output?

조회 수: 3 (최근 30일)
I want to know (visualize) what value, network has predicted during training.
i used Dice pixel classfication layer to observe this but instead of predicted value it shows the original image. Its written that T is target which means T is ground truth and Y is predicted which means predicted pixels.
Code:
classdef dicePixelClassificationLayer < nnet.layer.ClassificationLayer
% This layer implements the generalized Dice loss function for training
% semantic segmentation networks.
properties(Constant)
% Small constant to prevent division by zero.
Epsilon = 1e-8;
end
methods
function layer = dicePixelClassificationLayer(name)
% layer = dicePixelClassificationLayer(name) creates a Dice
% pixel classification layer with the specified name.
% Set layer name.
layer.Name = name;
% Set layer description.
layer.Description = 'Dice loss';
end
function loss = forwardLoss(layer, Y, T)
% loss = forwardLoss(layer, Y, T) returns the Dice loss between
% the predictions Y and the training targets T.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
code used to visualize the predictions Y and the training targets T
T1=T(:,:,1);
Y1=Y(:,:,1);
subplot(1,2,1)
imshow(T1)
subplot(1,2,2)
imshow(Y1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Weights by inverse of region size.
W = 1 ./ sum(sum(T,1),2).^2;
intersection = sum(sum(Y.*T,1),2);
union = sum(sum(Y.^2 + T.^2, 1),2);
numer = 2*sum(W.*intersection,3) + layer.Epsilon;
denom = sum(W.*union,3) + layer.Epsilon;
% Compute Dice score.
dice = numer./denom;
% Return average Dice loss.
N = size(Y,4);
loss = sum((1-dice))/N;
end
function dLdY = backwardLoss(layer, Y, T)
% dLdY = backwardLoss(layer, Y, T) returns the derivatives of
% the Dice loss with respect to the predictions Y.
% Weights by inverse of region size.
W = 1 ./ sum(sum(T,1),2).^2;
intersection = sum(sum(Y.*T,1),2);
union = sum(sum(Y.^2 + T.^2, 1),2);
numer = 2*sum(W.*intersection,3) + layer.Epsilon;
denom = sum(W.*union,3) + layer.Epsilon;
N = size(Y,4);
dLdY = (2*W.*Y.*numer./denom.^2 - 2*W.*T./denom)./N;
end
end
end
left is groundtruth and right side is origianl image, which supoosed to be predicted one. now how can i see the predicted one?

채택된 답변

Mahesh Taparia
Mahesh Taparia 2020년 9월 15일
Hi
The softmax layer gives the probability of the predicted class. To get the segmented result from that, you can put the probabilistic threshold of 0.5. For example:
P=T1(:,:,1)>0.5;
Else, in order to evaluate the segmented result, you can use the 'semanticseg' function. For more information, you can refer this documentation. Hope it wil help!
  댓글 수: 2
Raza Ali
Raza Ali 2020년 9월 16일
Thank you for the answer.
What is Y and T?
defined in loss fucntion? Are they ground truth (T) and predicted values (Y)?
Mahesh Taparia
Mahesh Taparia 2020년 9월 16일
Yes, they are ground truth (T) and predicted values (Y).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by