How to visualize the predicted values of segmentation from softmax output?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Raza Ali
am 11 Sep. 2020
Kommentiert: Mahesh Taparia
am 16 Sep. 2020
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?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/359218/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/359218/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Mahesh Taparia
am 15 Sep. 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!