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?
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!