MCPcopy Create free account
hub / github.com/cure-lab/deep-active-learning / LossNet

Class LossNet

models/lossnet.py:10–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9# https://github.com/Mephisto405/Learning-Loss-for-Active-Learning
10class LossNet(nn.Module):
11 def __init__(self, feature_sizes=[32, 16, 8, 4],
12 num_channels=[64, 128, 256, 512], interm_dim=128):
13 super(LossNet, self).__init__()
14
15 self.GAP1 = nn.AvgPool2d(feature_sizes[0])
16 self.GAP2 = nn.AvgPool2d(feature_sizes[1])
17 self.GAP3 = nn.AvgPool2d(feature_sizes[2])
18 self.GAP4 = nn.AvgPool2d(feature_sizes[3])
19
20 self.FC1 = nn.Linear(num_channels[0], interm_dim)
21 self.FC2 = nn.Linear(num_channels[1], interm_dim)
22 self.FC3 = nn.Linear(num_channels[2], interm_dim)
23 self.FC4 = nn.Linear(num_channels[3], interm_dim)
24
25 self.linear = nn.Linear(4 * interm_dim, 1)
26
27 def forward(self, features,intermediate=False):
28 out1 = self.GAP1(features[0])
29 out1 = out1.view(out1.size(0), -1)
30 out1 = F.relu(self.FC1(out1))
31
32 out2 = self.GAP2(features[1])
33 out2 = out2.view(out2.size(0), -1)
34 out2 = F.relu(self.FC2(out2))
35
36 out3 = self.GAP3(features[2])
37 out3 = out3.view(out3.size(0), -1)
38 out3 = F.relu(self.FC3(out3))
39
40 out4 = self.GAP4(features[3])
41 out4 = out4.view(out4.size(0), -1)
42 out4 = F.relu(self.FC4(out4))
43
44 out = self.linear(torch.cat((out1, out2, out3, out4), 1))
45 if intermediate:
46 return out,torch.cat((out1, out2, out3, out4),1),[out1, out2, out3, out4]
47 else:
48 return out,torch.cat((out1, out2, out3, out4),1)
49

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected