torch. nn.Softmax() dim的含义

dim实际上是对不同维度进行求对数均值
例如下面这个是(3,2)的一个变量,dim = 0 实际上是对第一维的3个变量进行对数化,而dim = 1是对第二维进行操作

a = torch.Tensor([[1,1],[2,2],[3,3]])
a.size()
Out[89]: torch.Size([3, 2])
b = torch.nn.Softmax(dim=0)(a)
b
Out[91]: 
tensor([[0.0900, 0.0900],
        [0.2447, 0.2447],
        [0.6652, 0.6652]])
b = torch.nn.Softmax(dim=1)(a)
b
Out[93]: 
tensor([[0.5000, 0.5000],
        [0.5000, 0.5000],
        [0.5000, 0.5000]])
发布了59 篇原创文章 · 获赞 19 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43914889/article/details/104505512