softmax 先exp,再在上面求总和的百分比
解决了负数相互抵消的问题。
if __name__ == '__main__':
import torch
import torch.nn.functional as F
input = torch.randn(2, 2)
print(input)
b = torch.softmax(input, dim=0) # 按列SoftMax,列和为1
print(b)
b = torch.max(input, dim=0) # 按列Max
print(b)
可以筛选第3维最大,也可以筛选第2维最大的:
import torch
anch_ious = torch.Tensor([[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]]])
print('b shape',anch_ious.shape)
b = torch.max(anch_ious, 2)
print(b[0])
print(b[1])
b = b[1].squeeze(1)
print(b)
print(anch_ious[list(range(anch_ious.size(0))),list(range(anch_ious.size(1))), b])