
セマンティックセグメンテーション評価方法
7 views (last 30 days)
Show older comments
セマンティックセグメンテーションで画像ごとにConfusionMatrixを出力する方法をご教授いただきたいです
例でいうとこんな感じです。
triangle background
________ __________
triangle 4730 0
background 9601 88069
これを全体ではなく画像ごとの結果が見たいです。
お願いします。
0 Comments
Accepted Answer
Kenta
on 20 Jan 2020
こんにちは、semanticseg関数で推論させたものと、pxdsTruthのデータストアから読みとったものを合わせて
confusionchart関数に入力すればできると思います。複数の場合はそれをループ内ですればよいです。
コードは以下のリンクのものをベースにしています。
既定の方法で、ConfusionMatrixを作った場合と、今回の1枚ずつ作成する場合を比べました。
1枚ずつ作成し、それらの要素数をすべて足し合わせると、既定の方法でまとめて一気にやった場合の値と一致していることを以下のコードで確認してください。
値が一致していて正しそうだったので、12枚、順番にとりだし、confusionMatrixを作ったのが、下の画像です。
下のコードで正しいと思うんですが、1枚ずつやったことはなく、ご自身で確認されてからお使いください。
お役に立てれば幸いです。よろしくお願いいたします。

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 Comments
More Answers (0)
See Also
Categories
Find more on イメージのセグメンテーション in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!