# python-utils **Repository Path**: yuchende/python-utils ## Basic Information - **Project Name**: python-utils - **Description**: 本仓库用来存储,作者自己打包的工具包 - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2020-06-15 - **Last Updated**: 2021-04-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # python-utils #### Introduction this repository use to calculate the metric of Semantic Segmentation #### Installation pip install git+https://gitee.com/yuchende/python-utils.git@master #### Example import metric import metric.calMetric as mc import torch # init train_acc = 0 train_miou = 0 train_class_acc = 0 train_pixel_accuracy = 0 calmc = mc.CalMetricUtils(5) # 语义分割中对应着5个分类,mask分别是 0,1,2,3,4 # you net such as unet ,fcn8s ....... out = net(train_image) # out 为 tensorSize([2,5,4,4]) prelabel = out.max(1)[1].data.cpu().numpy()# prelabel shape = 2 * 1 * 4 * 4 prelabel = [i for i in prelabel] # prelabel shape = 2 * 4 * 4 truelabel = imglabel.data.cpu().numpy() # imglabel 为 tensorSize([2,1,4,4]) truelabel = [i for i in truelabel] # truelabel shape = 2 * 4 * 4 # begin to calculate resultMetric = calmc(pre_label,true_label) # train_acc += resultMetric['mean_class_accuracy'] train_miou += resultMetric['miou'] train_class_acc += resultMetric['class_accuracy'] train_pixel_accuracy += resultMetric['pixel_accuracy'] # 说明 # 当前计算的是一个批次的准确率,如果有n个批次,迭代之后,准确率计算如下 # eg: # train_acc / n