ner 评估指标_图像分割-手把手系列1:评价指标

本文介绍了深度学习语义分割的评估指标,包括像素精度、平均精度、平均IoU和频率加权IoU,并提供了Python代码实现。通过加载预训练模型,对图像进行分割并计算相应指标。
摘要由CSDN通过智能技术生成

图像分割-手把手系列1:评价指标

发布时间:2018-04-24 15:18,

浏览次数:1095

目标检测与语义分割交流群:

1群:371315462

2群:935621769

原文连接:https://blog.csdn.net/majinlei121/article/details/78965435

度量标准(准确度)(pixel accuracy, mean accuracy, mean IU, frequency weighted IU)

原文讲解的非常好,转载过来备份一下。

深度学习之语义分割中的度量标准(准确度)(pixel accuracy, mean accuracy, mean IU, frequency

weighted IU)

关键部分来了,如何变成代码呢,有以下两种方案:

(1)参考这个连接:https://github.com/martinkersner/py_img_seg_eval 【已验证,好用】

(2)使用下方原博文的代码【未验证】

下面是根据全卷积语义分割的准确度程序编写

import _init_paths import os import numpy as np from PIL import Image import

matplotlib.pyplot as plt from skimage import io from timer import Timer import

cv2 from datetime import datetime import caffe test_file = 'test.txt'

file_path_img = 'JPEGImages' file_path_label = 'SegmentationClass' save_path =

'output/results' test_prototxt = 'Models/test.prototxt' weight =

'Training/Seg_iter_10000.caffemodel' layer = 'conv_seg' save_dir = False # True

if save_dir: save_dir = save_path else: save_dir = False # load net net =

caffe.Net(test_prototxt, weight, caffe.TEST) # load test.txt test_img =

np.loadtxt(test_file, dtype=str) def fast_hist(a, b, n): k = (a >= 0) & (a < n)

return np.bincount(n * a[k].astype(int) + b[k], minlength=n**2).reshape(n, n) #

seg test print '>>>', datetime.now(), 'Begin seg tests' n_cl =

net.blobs[layer].channels hist = np.zeros((n_cl, n_cl)) # timers _t = {'im_seg'

: Timer()} # load image and label i = 0 for img_name in test_img:

_t['im_seg'].tic() img = Image.open(os.path.join(file_path_img, img_name +

'.jpg')) img = img.resize((512, 384), Image.ANTIALIAS) in_ = np.array(img,

dtype=np.float32) in_ = in_[:,:,::-1] # rgb to bgr in_ -= np.array([[[68.2117,

78.2288, 75.4916]]])#数据集平均值,根据需要修改 in_ = in_.transpose((2,0,1)) label =

Image.open(os.path.join(file_path_label, img_name + '.png')) label =

label.resize((512, 384), Image.ANTIALIAS)#图像大小(宽,高),根据需要修改 label =

np.array(label, dtype=np.uint8) # shape for input (data blob is N x C x H x W),

set data net.blobs['data'].reshape(1, *in_.shape) net.blobs['data'].data[...] =

in_ net.forward() _t['im_seg'].toc() print 'im_seg: {:d}/{:d} {:.3f}s' \

.format(i + 1, len(test_img), _t['im_seg'].average_time) i += 1 hist +=

fast_hist(label.flatten(), net.blobs[layer].data[0].argmax(0).flatten(), n_cl)

if save_dir: seg = net.blobs[layer].data[0].argmax(axis=0) result =

np.array(img, dtype=np.uint8) index = np.where(seg == 1) for i in

xrange(len(index[0])): result[index[0][i], index[1][i], 0] = 255

result[index[0][i], index[1][i], 1] = 0 result[index[0][i], index[1][i], 2] = 0

result = Image.fromarray(result.astype(np.uint8))

result.save(os.path.join(save_dir, img_name + '.jpg')) iter = len(test_img) #

overall accuracy acc = np.diag(hist).sum() / hist.sum() print '>>>',

datetime.now(), 'Iteration', iter, 'overall accuracy', acc # per-class accuracy

acc = np.diag(hist) / hist.sum(1) print '>>>', datetime.now(), 'Iteration',

iter, 'mean accuracy', np.nanmean(acc) # per-class IU iu = np.diag(hist) /

(hist.sum(1) + hist.sum(0) - np.diag(hist)) print '>>>', datetime.now(),

'Iteration', iter, 'mean IU', np.nanmean(iu) freq = hist.sum(1) / hist.sum()

print '>>>', datetime.now(), 'Iteration', iter, 'fwavacc', \ (freq[freq > 0] *

iu[freq > 0]).sum()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值