Skip to content

Conversation

@CielAl
Copy link

@CielAl CielAl commented Sep 27, 2023

@sthalles @alessiamarcolini @butyuhao
Hi,

as mentioned in #32 , the current implementation of info_nce_loss may not properly work if n_views > 2 due to the additional positive pairs. Herein I attempt to fix it by duplicate the negative pairs for additional positive ones, if I understand the mechanism of your current implementation correctly:

        positives = similarity_matrix[labels.bool()].view(labels.shape[0] * (n_views - 1), -1)

        # select only the negatives
        # change: copy if n_views > 2 for other positive pairs of img
        negatives = similarity_matrix[~labels.bool()].view(similarity_matrix.shape[0], -1).repeat(n_views - 1, 1)

        logits = torch.cat([positives, negatives], dim=1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant