beuve / DmyT

Dummy Triplet Loss for Deepfake Detection
3 stars 2 forks source link

Calculation of accuracy #2

Open XALEX-123 opened 1 day ago

XALEX-123 commented 1 day ago
         else:
            model.train()
            optimizer.zero_grad()
            output = model.forward(data)
            loss = criterion(output, target.argmax(dim=1))
            loss.backward()
            if criterion.name == 'DmyT':
                output = get_dummy_prediction(output, criterion._loss.dummies,
                                              device)
            elif criterion.name == 'Triplet':
                output = torch.zeros((target.size(0))).to(device)
            else:
                output = output.argmax(dim=1)
            optimizer.step()

        accuracy = (output == target.argmax(dim=1)).float().mean()

Why is torch.zeros used in the output of Triplet? Is the accuracy calculated this way meaningful?

beuve commented 1 day ago

I couldn't compute an accuracy from the triplet loss output since there is no prediction. The torch.zeros only ensures that the last line (accuracy = (output == target.argmax(dim=1)).float().mean()) doesn't return an error, but the displayed accuracy is meaningless.