MCPcopy Create free account
hub / github.com/HobbitLong/PyContrast / forward

Method forward

pycontrast/networks/resnest.py:52–84  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

50 self.dropblock = DropBlock2D(dropblock_prob, 3)
51
52 def forward(self, x):
53 x = self.conv(x)
54 if self.use_bn:
55 x = self.bn0(x)
56 if self.dropblock_prob > 0.0:
57 x = self.dropblock(x)
58 x = self.relu(x)
59
60 batch, channel = x.shape[:2]
61 if self.radix > 1:
62 splited = torch.split(x, channel//self.radix, dim=1)
63 gap = sum(splited)
64 else:
65 gap = x
66 gap = F.adaptive_avg_pool2d(gap, 1)
67 gap = self.fc1(gap)
68
69 if self.use_bn:
70 gap = self.bn1(gap)
71 gap = self.relu(gap)
72
73 atten = self.fc2(gap).view((batch, self.radix, self.channels))
74 if self.radix > 1:
75 atten = F.softmax(atten, dim=1).view(batch, -1, 1, 1)
76 else:
77 atten = F.sigmoid(atten, dim=1).view(batch, -1, 1, 1)
78
79 if self.radix > 1:
80 atten = torch.split(atten, channel//self.radix, dim=1)
81 out = sum([att*split for (att, split) in zip(atten, splited)])
82 else:
83 out = atten * x
84 return out.contiguous()
85
86
87class GlobalAvgPool2d(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected