pytorch语义分割计算mIoU

版本:python3
pred为模型预测的label,像素0表示背景,像素1表示类别1,像素2表示类别2,以此类推。
target为groundtruth,这里读入格式为PIL image,格式不一样的请自行修改
这里的n_classes是目标物类别数。比如,对于只有背景和一个检测物类别的二分类问题,n_classes=1
因为pythonfor循环的range(a,b),范围其实为[a,b),所以循环终点为n_classes+1

import numpy as np
import torch

def iou_mean(pred, target, n_classes = 1):
#n_classes :the number of classes in your dataset,not including background
# for mask and ground-truth label, not probability map
  ious = []
  iousSum = 0
  pred = torch.from_numpy(pred
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值