Skip to content
Snippets Groups Projects
Commit ed48b672 authored by umlauf's avatar umlauf
Browse files

try cel

parent eff41a04
No related branches found
No related tags found
No related merge requests found
......@@ -140,9 +140,19 @@ def train(model, name, seed,gradient_accumulation_steps,mixup, threshold, lambda
return evaluation_test, evaluation_train
# def cross_entropy(logits, target):
# log_q = torch.log_softmax(logits, dim=1)
# return -torch.sum(log_q[range(log_q.shape[0]), target])
def cross_entropy(logits, target):
# Calculate log_q
log_q = torch.log_softmax(logits, dim=1)
return -torch.sum(log_q[range(log_q.shape[0]), target])
#define classes/options
target_class = (target == 0).float()
target_class2 = (target == 1).float()
target = target.float()
# calculate sum of losses of batch size
return -(target_class * log_q[:, 0] + target_class2 * log_q[:, 1] + (1 - target_class - target_class2) * (target * log_q[:, 1] + (1 - target) * log_q[:, 0]))
def mixup_function(batch_of_matrices, batch_of_labels, l, t):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment