Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save the second logsigmoid computation #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions coral_pytorch/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def coral_loss(logits, levels, importance_weights=None, reduction='mean'):
raise ValueError("Please ensure that logits (%s) has the same shape as levels (%s). "
% (logits.shape, levels.shape))

term1 = (F.logsigmoid(logits)*levels
+ (F.logsigmoid(logits) - logits)*(1-levels))
log_sigmoid = F.logsigmoid(logits)
term1 = (log_sigmoid*levels
+ (log_sigmoid - logits)*(1-levels))

if importance_weights is not None:
term1 *= importance_weights
Expand Down Expand Up @@ -146,8 +147,9 @@ def corn_loss(logits, y_train, num_classes):
num_examples += len(train_labels)
pred = logits[train_examples, task_index]

loss = -torch.sum(F.logsigmoid(pred)*train_labels
+ (F.logsigmoid(pred) - pred)*(1-train_labels))
log_sigmoid = F.logsigmoid(logits)
loss = -torch.sum(log_sigmoid*train_labels
+ (log_sigmoid - pred)*(1-train_labels))
losses += loss

return losses/num_examples
Expand Down