当前位置: 首页 > news >正文

孙俪做的网站广告中国新闻社山西分社

孙俪做的网站广告,中国新闻社山西分社,山东省工程建设招标信息网站,电子商务网站建设总结报告目录 1. 介绍 2. dice 和 iou 的联系 3. 代码实现 3.1 dice 3.2 iou 3.3 test 3.4 dice 和 iou 的关系曲线 4. 代码 1. 介绍 dice 和 iou 都是衡量两个集合之间相似性的度量 dice计算公式: iou计算公式: iou的集合理解: iou 其实就…

目录

1. 介绍

2. dice 和 iou 的联系

3. 代码实现

3.1 dice

3.2 iou

3.3 test

3.4 dice 和 iou 的关系曲线

4. 代码


1. 介绍

dice 和 iou 都是衡量两个集合之间相似性的度量

dice计算公式:

iou计算公式:

iou的集合理解:

 

iou 其实就是两个区域的 overlap 部分和 union 部分的比值,也就是两个集合的交集 / 并集

dice 的分母不是并集,因为dice的分母是两个区域的和,A+B = A + B - A∩B,所以dice的分母其实是少减去了一个 A∩B,所以就让分子的 A∩B(交集) 扩大2倍

2. dice 和 iou 的联系

如果将两个集合间的关系划分的更细一点,即这种形式:

那么 A∩B = TP , A∪B = FN + TP + FP ,A+B = FN + TP +TP + FP 

dice : 

 

iou : 

 

那么根据变形,可以得出:

 

3. 代码实现

|A ∩ B| = A * B 的 和 = 两个区域乘积的和

|A| + |B|  = A + B 的和 = 两个区域相加的总和

|A∪B| = |A| + |B| - |A ∩ B| = 两个区域相交的总和 - 两个区域相乘的和

3.1 dice

dice 的实现

# Dice
def Dice(pred,true):intersection = pred * true          # 计算交集  pred ∩ truetemp = pred + true                  # pred + truesmooth = 1e-8                       # 防止分母为 0dice_score = 2*intersection.sum() / (temp.sum() + smooth)return dice_score

intersection 为两个区域的交集,即两个区域的乘积

temp 为两个区域的和,(注:这里不是并集,因为没有减去相交的部分)

3.2 iou

iou 的实现

# Iou
def Iou(pred,true):intersection = pred * true          # 计算交集  pred ∩ truetemp = pred + true                  # pred + trueunion = temp - intersection         # 计算并集:A ∪ B = A + B - A ∩ Bsmooth = 1e-8                       # 防止分母为 0iou_score = intersection.sum() / (union.sum() + smooth)return iou_score

intersection 为两个区域的交集,即两个区域的乘积

temp 为两个区域的和,(注:这里不是并集,因为没有减去相交的部分)

union 为两个区域的并集

3.3 test

预测:

# prediction
predict = torch.tensor([0.01,0.03,0.02,0.02,0.05,0.12,0.09,0.07,0.89,0.85,0.88,0.91,0.99,0.97,0.95,0.97]).reshape(1,1,4,4)
'''
tensor([[[[0.0100, 0.0300, 0.0200, 0.0200],[0.0500, 0.1200, 0.0900, 0.0700],[0.8900, 0.8500, 0.8800, 0.9100],[0.9900, 0.9700, 0.9500, 0.9700]]]])
'''

label:

# label
label = torch.tensor([0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1]).reshape(1,1,4,4)
'''
tensor([[[[0, 0, 0, 0],[0, 0, 0, 0],[1, 1, 1, 1],[1, 1, 1, 1]]]])
'''

计算结果:

 

公式可知,dice和iou的关系为:

验证可知:

注:有些细微的差异是smooth所导致

3.4 dice 和 iou 的关系曲线

有公式可知,dice 和 iou 的关系公式如下:

关系曲线如图:

 

4. 代码

import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'import torch
import numpy as np
import matplotlib.pyplot as plt# prediction
predict = torch.tensor([0.01,0.03,0.02,0.02,0.05,0.12,0.09,0.07,0.89,0.85,0.88,0.91,0.99,0.97,0.95,0.97]).reshape(1,1,4,4)
'''
tensor([[[[0.0100, 0.0300, 0.0200, 0.0200],[0.0500, 0.1200, 0.0900, 0.0700],[0.8900, 0.8500, 0.8800, 0.9100],[0.9900, 0.9700, 0.9500, 0.9700]]]])
'''# label
label = torch.tensor([0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1]).reshape(1,1,4,4)
'''
tensor([[[[0, 0, 0, 0],[0, 0, 0, 0],[1, 1, 1, 1],[1, 1, 1, 1]]]])
'''# Dice
def Dice(pred,true):intersection = pred * true          # 计算交集  pred ∩ truetemp = pred + true                  # pred + truesmooth = 1e-8                       # 防止分母为 0dice_score = 2*intersection.sum() / (temp.sum() + smooth)return dice_score# Iou
def Iou(pred,true):intersection = pred * true          # 计算交集  pred ∩ truetemp = pred + true                  # pred + trueunion = temp - intersection         # 计算并集:A ∪ B = A + B - A ∩ Bsmooth = 1e-8                       # 防止分母为 0iou_score = intersection.sum() / (union.sum() + smooth)return iou_score# dice 和 iou 的换算
def dice_and_iou(x):y = x / (2 - x)return ydice = np.arange(0,1,0.001)
iou = dice_and_iou(dice)plt.plot(dice,iou)
plt.xlabel('dice')
plt.ylabel('iou')
plt.show()

http://www.yayakq.cn/news/644331/

相关文章:

  • 网站做百度小程序改造的好处wordpress 评论提醒邮件插件
  • 如何收集网站建设资料简单设置网站首页
  • 惠州网站建设开发团队苏州高端网站开发
  • wordpress安装2个网站吗西安百度关键词推广
  • 甘肃住房和城乡建设厅网站首页php能区别电脑网站和手机网站吗怎么嵌入到phpcms
  • 什么公司需要网站建设应该如何使用网络营销策略
  • 苏州免费自助建站网站建设搜索引擎快速排名推广
  • 网站建设要学哪些软件有哪些方面安卓软件开发公司收入
  • 官方网站搭建要多少钱aspx网站做app
  • php网站开发专业介绍内部网站建设软件下载
  • 外贸网站搜索引擎优化方法erp软件有哪些品牌
  • 网站建设制作有那些郑州制作网站推荐
  • 怎么知道网站哪家公司做的徽石网站建设
  • 文交所网站建设方案陕西汽车网站建设
  • 如何介绍设计的网站模板推广链接让别人点击
  • 企业的网站建设制作平台wordpress页面缓慢
  • 网站建设云技术公司推荐学校网站代码模板
  • dw做的网站上传昆明餐饮网站建设
  • 坪山附近公司做网站建设哪家效益快兰州网站开发公司
  • 怎么做网站图片链接做网站要遵守的基本原则
  • 做php网站用什么软件广州软件开发工资怎么样
  • 中国做跨境电商出口的网站嵌入式软件开发工程师简历
  • ps网站设计概述高唐建筑公司网站
  • 织梦网站入侵软件开发服务平台
  • 网站模板怎样发布网页游戏开服表好吗
  • 佛冈网站建设网站开发工程师是做什么的
  • 网站开发质量控制计划书传媒公司主要做什么
  • 栾川网站建设专业搜索引擎seo服务商
  • 网站图片模板源码简述制作网站的步骤和过程
  • 做外贸去哪个网站找客户网站文章内容排版要求