import torch.nn.functional as F
output = F.softmax(output)
UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to
include dim=X as an argument.
这个警告的原因是softmax()
函数已经被弃用了,虽然程序还是可以运行成功,但是这个做法不被pytorch所赞成。这个写法在早期的pytorch版本是没有警告的,现在因为其他考虑,要加上有指明dim参数。
改成
F.softmax(output, dim=1)
tensor([[0.5193, 0.4807],
[0.6070, 0.3930],
[0.5254, 0.4746],
[0.5079, 0.4921],
[0.4623, 0.5377],
[0.4403, 0.5597],
[0.5240, 0.4760],
[0.4703, 0.5297],
[0.5091, 0.4909],
[0.4201, 0.5799],
[0.5543, 0.4457],
[0.5524, 0.4476],
[0.5861, 0.4139],
[0.5524, 0.4476],
[0.5112, 0.4888],
[0.4453, 0.5547]])
dim=某个数字,这个数字可以根据自己的需要更改。
Python-F.softmax(dim)中dim使用理解