Help me: AttributeError: 'tuple' object has no attribute 'cpu'

Hi, can someone help me please:

I’m try to run the code below, but I got this issues:

rend = rend.cpu().data.numpy().transpose((0, 2, 3, 1))
AttributeError: ‘tuple’ object has no attribute ‘cpu’

I also printed the shape of this turple:

torch.Size([1, 3, 244, 244])
torch.Size([1, 244, 244])
torch.Size([1, 244, 244])

I’ve tried a lot of ways to solve this, but I got other issues… :expressionless:

1 Like

You cannot call cpu() on a Python tuple, as this is a method of PyTorch’s tensors.
If you want to move all internal tuples to the CPU, you would have to call it on each of them:

x = (torch.randn([1, 3, 244, 244]).cuda(),
     torch.randn([1, 244, 244]).cuda(),
     torch.randn([1, 244, 244]).cuda())

x.cpu() # error

y = tuple(t.cpu() for t in x)
print(y)
1 Like

Works. Thank you :smiley: