I found the reason, here is my network forward:
def forward(self, x):
d = super().forward_as_dict(x)
cam = self.fc8(d['conv6'])
n, c, h, w = d['conv6'].size()
f8_3 = self.f8_3(d['conv4'].detach())
f8_4 = self.f8_4(d['conv5'].detach())
x_s = F.interpolate(x, (h, w), mode='bilinear', align_corners=True)
f = torch.cat([x_s, f8_3, f8_4], dim=1)
x_att = self.PCM(d['conv6'], f)
cam_att = self.fc8(x_att)
self.featmap = cam + cam_att
_, _, h, w = cam.size()
pred = F.avg_pool2d(self.featmap[:, :-1], kernel_size=(h, w), padding=0)
pred = pred.view(pred.size(0), -1)
return self.featmap, pred,_
Here, ‘_’ is ‘int’,so I change the code:
def forward(self, x):
d = super().forward_as_dict(x)
cam = self.fc8(d['conv6'])
n, c, h, w = d['conv6'].size()
f8_3 = self.f8_3(d['conv4'].detach())
f8_4 = self.f8_4(d['conv5'].detach())
x_s = F.interpolate(x, (h, w), mode='bilinear', align_corners=True)
f = torch.cat([x_s, f8_3, f8_4], dim=1)
x_att = self.PCM(d['conv6'], f)
cam_att = self.fc8(x_att)
self.featmap = cam + cam_att
_, _, h, w = cam.size()
pred = F.avg_pool2d(self.featmap[:, :-1], kernel_size=(h, w), padding=0)
pred = pred.view(pred.size(0), -1)
return self.featmap, pred
Then it work, but I still don’t know why it can run in a single GPU.