-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.py
26 lines (22 loc) · 893 Bytes
/
model.py
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
from torch import nn
class Net(nn.Module):
def __init__(self, arch, return_feats=False):
super(Net, self).__init__()
self.arch = arch
self.return_feats = return_feats
if 'EfficientNet' in str(arch.__class__):
self.arch._fc = nn.Linear(in_features=self.arch._fc.in_features, out_features=500, bias=True)
else:
self.arch.fc = nn.Linear(in_features=arch.fc.in_features, out_features=500, bias=True)
self.ouput = nn.Linear(500, 1)
def forward(self, images):
"""
No sigmoid in forward because we are going to use BCEWithLogitsLoss
Which applies sigmoid for us when calculating a loss
"""
x = images
features = self.arch(x)
output = self.ouput(features)
if self.return_feats:
return features
return output