cvg / glue-factory

Training library for local feature detection and matching
Apache License 2.0
722 stars 90 forks source link

Whether to reuse the Sigmoid function in the confidence loss calculation code? #89

Open EATMustard opened 3 months ago

EATMustard commented 3 months ago

Pytorch.BCEWithLogitsLoss performs the Sigmoid operation, but the Sigmoid is reused in the model code. Is this a bug?

class TokenConfidence(nn.Module):

def __init__(self, dim: int) -> None:

    super().__init__()

    self.token = nn.Sequential(nn.Linear(dim, 1), nn.Sigmoid())  # sigmoid once

    self.loss_fn = nn.BCEWithLogitsLoss(reduction="none")  # sigmoid twice 
noahzn commented 1 month ago

I think this is a bug, I tried removing nn.Sigmoid in self.token and adding torch.sigmoid in forward(), but the results are almost the same. Have you tried?