首页 > 技术文章 > pytorch警告:UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.

foghorn 2021-09-13 20:58 原文

当我们单独使用nn.Softmax()函数时,会显示上述警告,原因是softmax()函数已经被弃用了,虽然程序还是可以运行成功,但是这个做法不被pytorch所赞成。这个写法在早期的pytorch版本是没有警告的,现在因为其他考虑,要加上有指明dim参数。
例如:

m = nn.Softmax(dim=1)  # 加上 dim=1
input = torch.randn(2, 3)
output = m(input)

推荐阅读