Skip to content

Commit

Permalink
Fix loss logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Böhm committed Dec 13, 2024
1 parent e242f47 commit 817fb28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions tsimcne/losses/infonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def forward(self, features, backbone_features=None, labels=None):
raw_uniformity = logsumexp_1 + logsumexp_2

loss = -(self.exaggeration * tempered_alignment - raw_uniformity / 2)
return loss
return dict(
loss=loss,
ta=-tempered_alignment,
ru=raw_uniformity / 2,
)


class InfoNCEGaussian(InfoNCECauchy):
Expand Down Expand Up @@ -111,7 +115,11 @@ def forward(self, features, backbone_features=None, labels=None):
raw_uniformity = logsumexp_1 + logsumexp_2

loss = -(tempered_alignment - raw_uniformity / 2)
return loss
return dict(
loss=loss,
ta=-tempered_alignment,
ru=raw_uniformity / 2,
)


class InfoNCELoss(LossBase):
Expand Down
4 changes: 2 additions & 2 deletions tsimcne/tsimcne.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ def validation_step(self, batch, batch_idx, dataloader_idx=0):
features, backbone_features = self(batch)

# backbone_features are unused in infonce loss
loss = self.loss(features)
lossd = self.loss(features)

return dict(loss=loss)
return lossd

elif dataloader_idx == 1:
features, backbone_features = self(batch)
Expand Down

0 comments on commit 817fb28

Please sign in to comment.