I working on capsule networks and I get this error once I go through the loss function :
AttributeError: ‘tuple’ object has no attribute ‘size’ the error comes form this line:
t = torch.zeros(lengths.size()).long()
I tired multiple ways to convert it to tuples but always has an issue with detach from the GPU
this is the loss function:
class MarginLoss(nn.Module):
def init(self, m_pos, m_neg, lambda_):
super(MarginLoss, self).init()
self.m_pos = m_pos
self.m_neg = m_neg
self.lambda_ = lambda_
def forward(self, lengths, targets, size_average=True):
t = torch.zeros(lengths.size()).long()
if targets.is_cuda:
t = t.cuda()
t = t.scatter_(1, targets.data.view(-1, 1), 1)
targets = Variable(t)
losses = targets.float() * F.relu(self.m_pos - lengths).pow(2) + \
self.lambda_ * (1. - targets.float()) * F.relu(lengths - self.m_neg).pow(2)
return losses.mean() if size_average else losses.sum()
Thanks in advance