セマンティックセグメンテーション評価方法

セマンティックセグメンテーションで画像ごとにConfusionMatrixを出力する方法をご教授いただきたいです
例でいうとこんな感じです。
triangle background
  ________ __________
triangle 4730 0
background 9601 88069
これを全体ではなく画像ごとの結果が見たいです。
お願いします。

 采纳的回答

Kenta
Kenta 2020-1-20

1 个投票

こんにちは、semanticseg関数で推論させたものと、pxdsTruthのデータストアから読みとったものを合わせて
confusionchart関数に入力すればできると思います。複数の場合はそれをループ内ですればよいです。
コードは以下のリンクのものをベースにしています。
既定の方法で、ConfusionMatrixを作った場合と、今回の1枚ずつ作成する場合を比べました。
1枚ずつ作成し、それらの要素数をすべて足し合わせると、既定の方法でまとめて一気にやった場合の値と一致していることを以下のコードで確認してください。
値が一致していて正しそうだったので、12枚、順番にとりだし、confusionMatrixを作ったのが、下の画像です。
下のコードで正しいと思うんですが、1枚ずつやったことはなく、ご自身で確認されてからお使いください。
お役に立てれば幸いです。よろしくお願いいたします。
result.PNG
close all;clear;clc
dataSetDir = fullfile(toolboxdir('vision'),'visiondata','triangleImages');
testImagesDir = fullfile(dataSetDir,'testImages');
testLabelsDir = fullfile(dataSetDir,'testLabels');
imds = imageDatastore(testImagesDir);
classNames = ["triangle","background"];
labelIDs = [255 0];
pxdsTruth = pixelLabelDatastore(testLabelsDir,classNames,labelIDs);
net = load('triangleSegmentationNetwork');
net = net.net;
% ここから変更部分
% 1枚ずつ、画像を読み込み、推論させる
% 確認のため、それぞれの要素数を記録しておく
% 最後に、既定の方法でやった場合と数値が一致するかを確認する
accm=zeros(2,2);
for i=1:100
Results = semanticseg(readimage(imds,i),net);
Truth=readimage(pxdsTruth,i);
C=confusionchart(Truth(:),Results(:));
accm=accm+C.NormalizedValues;
end
accm
% 確認のため、既定の方法で計算したconfusion matを計算(すべてのデータ)
pxdsResults = semanticseg(imds,net,"WriteLocation",tempdir);
metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTruth);
metrics.ConfusionMatrix
% 12個のデータを読み取って、confusion matを表示させる
f=figure;
for i=1:12
Results = semanticseg(readimage(imds,i),net);
Truth=readimage(pxdsTruth,i);
subplot(3,4,i)
confusionchart(Truth(:),Results(:));
end
f.WindowState='maximized';

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 入門 的更多信息

产品

版本

R2019b

Community Treasure Hunt

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

Start Hunting!