当前位置:网站首页>torch.histc
torch.histc
2022-07-01 03:15:00 【是七叔呀】
torch.histc
在跑小样本分割ASGNet的时候,计算mIOU的时候,在intersectionAndUnionGPU(output, target, K, ignore_index=255)中,使用到了torch.histc计算直方图:
def intersectionAndUnionGPU(output, target, K, ignore_index=255):
# 'K' classes, output and target sizes are N or N * L or N * H * W, each value in range 0 to K - 1.
assert (output.dim() in [1, 2, 3])
assert output.shape == target.shape
output = output.view(-1)
target = target.view(-1)
output[target == ignore_index] = ignore_index
intersection = output[output == target]
area_intersection = torch.histc(intersection, bins=K, min=0, max=K-1)
area_output = torch.histc(output, bins=K, min=0, max=K-1)
area_target = torch.histc(target, bins=K, min=0, max=K-1)
area_union = area_output + area_target - area_intersection
return area_intersection, area_union, area_target
torch.histc的API:
torch.histc(input, bins=100, min=0, max=0, *, out=None) → Tensor
计算张量的直方图。
元素被分类为 min 和 max 之间相等宽度的单元格。如果 min 和 max 均为零,则使用数据的最小值和最大值。
小于最小值和高于最大值的元素将被忽略。
Parameters:
input(Tensor)–输入 张 量 \color{red}{张量} 张量。bins(int)–直方图箱数min(int)–范围的下限(包括)max(int)–范围的上限(包括)
Returns
output:直方图用 张 量 \color{red}{张量} 张量Tensor输出表示
示例:
>>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)
输出:tensor([ 0., 2., 1., 0.])
解释:直方图箱为0、1、2、3;
其中
- 0的数量为0
- 1的数量为2
- 2的数量为1
- 3的数量为0
所以输出tensor([0, 2, 1, 0])
边栏推荐
- pytorch训练深度学习网络设置cuda指定的GPU可见
- How to achieve 0 error (s) and 0 warning (s) in keil5
- 10、Scanner.next() 无法读取空格/indexOf -1
- Nacos
- [linear DP] shortest editing distance
- [QT] add knowledge supplement of third-party database
- Elk elegant management server log
- Ultimate dolls 2.0 | encapsulation of cloud native delivery
- Include() of array
- Golang multi graph generation gif
猜你喜欢
随机推荐
Analyze datahub, a new generation metadata platform of 4.7K star
C#实现基于广度优先BFS求解无权图最短路径----完整程序展示
Feign remote call and getaway gateway
gcc使用、Makefile总结
Filter
Basic concept and classification of sorting
雪崩问题以及sentinel的使用
实战 ELK 优雅管理服务器日志
How to achieve 0 error (s) and 0 warning (s) in keil5
ES6解构语法详解
数据交换 JSON
后台系统右边内容如何出现滚动条和解决双滚动条的问题
EDLines: A real-time line segment detector with a false detection control翻译
JUC learning
Common interview questions for performance test
不用加减乘除实现加法
数据库DDL(Data Definition Language,数据定义语言)知识点
HTB-Lame
Keil5中如何做到 0 Error(s), 0 Warning(s).
shell脚本使用两个横杠接收外部参数









