% if you use another test/train set change number of classes and the% unlabeled index as well as number of iterations (needs to be equal to the test set size)gtPath = '/SegNet/Scripts/gt'; % path to your ground truth imagespredPath = '/SegNet/Scripts/predictions'; %path to your predictions (you get them after you implement saving images in the test_segmentation_camvid.py script - or you write your own)groundTruths = dir(gtPath);skip = 2; % first two are '.' and '..' so skip thempredictions = dir(predPath);iter = 233;numClasses = 11;unknown_class = 12;totalpoints = 0;cf = zeros(iter,numClasses,numClasses);globalacc = 0;for i = 1:iterdisplay(num2str(i));pred = imread(strcat(predPath, '/', predictions(i + skip).name)); % set this to iterate through your segnet prediction imagespred = pred + 1; % i added this cause i labeled my classes from 0 to 11annot = imread(strcat(gtPath, '/', groundTruths(i + skip).name)); % set this to iterate through your ground truth annotationsannot = annot + 1; % i added this cause i labeled my classes from 0 to 11 -> so in that case the next line will find every pixel labeled with unknown_class=12pixels_ignore = annot == unknown_class;pred(pixels_ignore) = 0;annot(pixels_ignore) = 0;totalpoints = totalpoints + sum(annot(:)>0);% global and class accuracy computationfor j = 1:numClassesfor k = 1:numClassesc1 = annot == j;c1p = pred == k;index = gather(c1 .* c1p);cf(i,j,k) = cf(i,j,k) + sum(index(:));endc1 = annot == j;c1p = pred == j;index = gather(c1 .* c1p);globalacc = globalacc + sum(index(:));endendcf = sum(cf,1);cf = squeeze(cf);% Compute confusion matrixconf = zeros(numClasses);for i = 1:numClassesif i ~= unknown_class && sum(cf(i,:)) > 0conf(i,:) = cf(i,:)/sum(cf(i,:));endendglobalacc = sum(globalacc)/sum(totalpoints);% Compute intersection over union for each class and its meanintoverunion = zeros(numClasses,1);for i = 1:numClassesif i ~= unknown_class && sum(conf(i,:)) > 0intoverunion(i) = (cf(i,i))/(sum(cf(i,:))+sum(cf(:,i))-cf(i,i));endenddisplay([' Global acc = ' num2str(globalacc) ' Class average acc = ' num2str(sum(diag(conf))/(numClasses)) ' Mean Int over Union = ' num2str(sum(intoverunion)/(numClasses))]);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。