在运行pytorch版SSD目标检测网络https://github.com/amdegroot/ssd.pytorch时遇到这个错误
使用Detect类创建对象self.detect执行检测,Detect类继承自Function类,在pytorch1.3及以后的版本需要规定forward方法为静态方法,所以在pytorch1.3以上的版本执行出错。
解决方法:加forward
if self.phase == "test":
# output = self.detect(loc.view(loc.size(0), -1, 4), # 将网络的位置预测表示为(-1,4)形式torch.Size([1, 8732, 4])
# self.softmax(conf.view(conf.size(0), -1,self.num_classes)), # 将网络的置信度预测表示为(-1,5)形式torch.Size([1, 8732, 5])
# self.priors.type(type(x.data)) # 先验anchor box,格式(x,y,w,h)
# )
##########################################################
output=self.detect.forward(loc.view(loc.size(0), -1, 4),
self.softmax(conf.view(conf.size(0),
-1,self.num_classes)),
self.priors.type(type(x.data)) )