博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
统计图像分割训练集中的类别分布
阅读量:7076 次
发布时间:2019-06-28

本文共 1718 字,大约阅读时间需要 5 分钟。

本系列文章由
@yhl_leo
出品,转载请注明出处。
文章链接:


对于一个语义分割数据集,可以使用如下方法统计样本集ground truth的类别分布情况:

import cv2, osimport numpy as np#amount of classerCLASSES_NUM = 21#find imagee in folder dirdef findImages(dir,topdown=True):    im_list = []    if not os.path.exists(dir):        print "Path for {} not exist!".format(dir)        raise    else:        for root, dirs, files in os.walk(dir, topdown):            for fl in files:                im_list.append(fl)    return im_list# amount of images corresponding to each classesimages_count = [0]*CLASSES_NUM# amount of pixels corresponding to each classclass_pixels_count = [0]*CLASSES_NUM# amount of pixels corresponding to the images of each classimage_pixels_count = [0]*CLASSES_NUMimage_folder = '../data/gt'im_list = findImages(image_folder) for im in im_list:    print im    cv_img = cv2.imread(os.path.join(image_folder, im), cv2.IMREAD_UNCHANGED)    size_img = cv_img.shape    colors = set([])    for i in range(size_img[0]):        for j in range(size_img[1]):            p_value = cv_img.item(i,j)            if not p_value < CLASSES_NUM: # check                print p_value            else:                class_pixels_count[p_value] = class_pixels_count[p_value] + 1                colors.add(p_value)    im_size = size_img[0]*size_img[1]    for n in range(CLASSES_NUM):        if n in colors:            images_count[n] = images_count[n] + 1            image_pixels_count[n] = image_pixels_count[n] + im_sizeprint images_countprint class_pixels_countprint image_pixels_count

上述代码,主要统计了每一类别所包含的图像数量(images_count),每一类别的像素数目(class_pixels_count)和每一类别对应的图像的总像素数目(image_pixels_count),有了这三组统计结果,就可以进一步计算训练时每一类别的lossclass_weight

转载于:https://www.cnblogs.com/hehehaha/p/6332113.html

你可能感兴趣的文章
Windows8/Silverlight/WPF/WP7/HTML5周学习导读(1月28日-2月3日)
查看>>
/tmp分区满,把oracle rac弄死了
查看>>
深入浅出linux系统umask值及其对应的文件权限讲解
查看>>
企业生产一线管理应找怎样的好帮手?
查看>>
MySQL数据库常用基本命令应用分享01
查看>>
实现线上高性能接口方案nginx负载tornado后端lua数据
查看>>
IT项目中存储设备的选型
查看>>
zabbix proxy配置文件不能把DBhost设置成远程数据库?
查看>>
疯狂ios之疯狂打飞机游戏(3)
查看>>
我的友情链接
查看>>
AWS的十年发展之路-永远前行
查看>>
Windows 2008 R2之三十六ADCS实现跨森林注册(二)
查看>>
最全团队管理手册
查看>>
浅谈在Linux中磁盘超出2T的管理方式
查看>>
安装Office 2010时1402错误的处理
查看>>
个人笔记ORA-32017 ORA-16179
查看>>
MSDE2000与SQLExpress2005共存时如何远程访问
查看>>
跨域组播---BGP+MSDP
查看>>
Microsoft Dynamics CRM server 2015 开发 之 安装visual studio 2012
查看>>
监控利器Nagios之二:Nagios的细致介绍和监控外部服务器的私有信息
查看>>