-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlosses.py
More file actions
38 lines (22 loc) 路 764 Bytes
/
Copy pathlosses.py
File metadata and controls
38 lines (22 loc) 路 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import torch
import torch.nn as nn
class CustomBCELoss(nn.Module):
def __init__(self):
super(CustomBCELoss, self).__init__()
self.loss = nn.BCELoss()
def forward(self, y_hat, y):
y_hat = y_hat.view(-1)
y = y.view(-1)
y_hat = y_hat[y > -0.5]
y = y[y > -0.5]
return self.loss(y_hat, y)
class CustomBCEWithLogitsLoss(nn.Module):
def __init__(self):
super(CustomBCEWithLogitsLoss, self).__init__()
self.loss = nn.BCEWithLogitsLoss()
def forward(self, y_hat, y):
y_hat = y_hat.view(-1)
y = y.view(-1)
y_hat = y_hat[y > -0.5]
y = y[y > -0.5]
return self.loss(y_hat, y)