Hi,
I implemented the triplet loss and trained the model with the loss.
however, when I passed the three inputs to the model, the same error occurs.
The code is shown below, and the model is Resnet or EfficientNet.
whether I use the Pyotrch1.5 or 1.4,1.3, both of them are wrong. I don‘t know the reason.
Even I changed the ‘inplace operation’ in Resnet code, the error still exists in the running process.
def train(epoch):
model.train()  #
total_loss = 0.0
total_size = 0
for batch_idx, (data, target) in enumerate(train_loader):  # 一个batch
if args.cuda:
data[0], target[0] = data[0].cuda(), target[0].cuda()
data[1], target[1] = data[1].cuda(), target[1].cuda()
data[2], target[2] = data[2].cuda(), target[2].cuda()
        data[0], target[0] = Variable(data[0]), Variable(target[0])
        data[1], target[1] = Variable(data[1]), Variable(target[1])
        data[2], target[2] = Variable(data[2]), Variable(target[2])

        optimizer.zero_grad()

        anchor = model.forward(data[0])
        positive = model.forward(data[1])
        negative = model.forward(data[2])

        loss_cls_0 = criterion(anchor, target[0].long())
        loss_cls_1 = criterion(positive, target[1].long())
        loss_cls_2 = criterion(negative, target[2].long())
        loss_cls = loss_cls_0 + loss_cls_1 + loss_cls_2

        loss_tri = triplet_loss.forward(anchor, positive, negative)

        loss = loss_tri + loss_cls


        total_loss += loss.data.cpu()[0]
        total_size += data[0].size(0)

        loss.backward()
        optimizer.step()