'int' object is not iterable

When running on a single GPU, it works fine, but when running on multiple GPUs with DataParallel, it reports an error: ‘int’ object is not iterable.

It doesn’t seem to tell me where to report an error.
‘int’ object is not iterable
File “.py”, line 326, in train_eps
cam, pred, _ = model(img)
File “.py”, line 548, in
train_eps(train_loader, model, optimizer, max_step, Q_model, eval_, args)

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.

1 Like