统计图像分割训练集中的类别分布
2016-08-16 22:26
1036 查看
本系列文章由 @yhl_leo 出品,转载请注明出处。
文章链接: http://blog.csdn.net/yhl_leo/article/details/52225600
对于一个语义分割数据集,可以使用如下方法统计样本集ground truth的类别分布情况:
上述代码,主要统计了每一类别所包含的图像数量(
文章链接: http://blog.csdn.net/yhl_leo/article/details/52225600
对于一个语义分割数据集,可以使用如下方法统计样本集ground truth的类别分布情况:
import cv2, os import numpy as np #amount of classer CLASSES_NUM = 21 #find imagee in folder dir def 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 classes images_count = [0]*CLASSES_NUM # amount of pixels corresponding to each class class_pixels_count = [0]*CLASSES_NUM # amount of pixels corresponding to the images of each class image_pixels_count = [0]*CLASSES_NUM image_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 = images_count + 1 image_pixels_count = image_pixels_count + im_size print images_count print class_pixels_count print image_pixels_count
上述代码,主要统计了每一类别所包含的图像数量(
images_count),每一类别的像素数目(
class_pixels_count)和每一类别对应的图像的总像素数目(
image_pixels_count),有了这三组统计结果,就可以进一步计算训练时每一类别的
loss的
class_weight。
相关文章推荐
- 统计图像分割训练集中的类别分布
- 英伟达发布深度学习GPU训练系统DIGITS 5,自带图像分割与在线模型库
- 机器学习中的数据不平衡问题----通过随机采样比例大的类别使得训练集中大类的个数与小类相当,或者模型中加入惩罚项
- VC++ 黏连颗粒图像分割算法 尺寸统计
- 全卷积神经网络 图像语义分割实验:FCN数据集制作,网络模型定义,网络训练(提供数据集和模型文件,以供参考)
- 图像语义分割:从头开始训练deeplab v2系列之二【VOC2012数据集】
- 【图像分割】NVIDIA深度学习训练系统——实现图像分割与网络分割可视化
- SSD(Single Shot MultiBox Detector):因为数据集中图像通道数不对导致的训练异常
- 图像语义分割:从头开始训练deeplab v2系列之三【pascal-context数据集】
- windows下进行FCN图像训练分割
- 图像语义分割:从头开始训练deeplab v2系列之一【源码解析】
- 极少训练样本的人眼血管图像分割
- 全卷积神经网络 图像语义分割实验:FCN数据集制作,网络模型定义,网络训练(提供数据集和模型文件,以供参考)
- 图像处理 之 统计数组中连续0/1的个数
- sql分割字符串并分组统计数量
- 眼底图像血管增强与分割--(5)基于Hessian矩阵的Frangi滤波算法
- U-net使用, 图像分割(边缘检测)
- Github编程语言分布统计:JavaScri…
- 常用图像数据集大全(分类,跟踪,分割,检测等)
- 漫步数理统计二十四——伽玛、卡方与贝塔分布