UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
源程序大概是这样的:
import torch.nn as nn
.......
class gan(object):
def __init__(self,opt,dataloader=None):
......
self.sf = nn.Softmax
......
def test(self):
self.x = self.sf(self.y)
运行,报错:
/home/liuming/weilanlan/DL/lib/model.py:420: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
self.gt2_pre_labels_tmp[i*self.opt.batchsize : i*self.opt.batchsize+error.size(0)] = torch.argmax(self.smax(self.latent_i_rs), dim = 1)
Segmentation fault (core dumped)
根据报错,添加了dim的信息,self.x = self.sf(self.y,dim=1),运行依然报错
self.gt2_pre_labels_tmp[i*self.opt.batchsize : i*self.opt.batchsize+error.size(0)] = torch.argmax(self.smax(self.latent_i_rs, dim=1), dim = 1)
File "/home/liuming/.local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'dim'
excuse me????我以为是什么内部问题,后来看到这篇文章https://discuss.pytorch.org/t/hypocritical-error-messages-re-softmax/27206,才发现是我把dim位置放错了
于是按照提示修改了dim的位置,
self.sf =nn.Softmax(dim=1)
成功的解决了这个问题!
解决这个问题花费了我两个小时的时间,希望以后有人在遇到类似的问题可以快速解决这个问题!!
欢迎各位不吝赐教。