MCPcopy Create free account
hub / github.com/chenhaoxing/HDNet / forward

Method forward

models/normalize.py:17–31  ·  view source on GitHub ↗
(self, x, mask)

Source from the content-addressed store, hash-verified

15 self.eps = eps
16
17 def forward(self, x, mask):
18 mask = F.interpolate(mask.detach(), size=x.size()[2:], mode='nearest')
19
20 mean_back, std_back = self.get_foreground_mean_std(x * (1-mask), 1 - mask) # the background features
21 normalized = (x - mean_back) / std_back
22
23 normalized_background = (normalized * (1 + self.background_gamma[None, :, None, None]) +
24 self.background_beta[None, :, None, None]) * (1 - mask)
25
26 mean_fore, std_fore = self.get_foreground_mean_std(x * mask, mask) # the background features
27 normalized = (x - mean_fore) / std_fore * std_back + mean_back
28 normalized_foreground = (normalized * (1 + self.foreground_gamma[None, :, None, None]) +
29 self.foreground_beta[None, :, None, None]) * mask
30
31 return normalized_foreground + normalized_background
32
33 def get_foreground_mean_std(self, region, mask):
34 sum = torch.sum(region, dim=[2, 3]) # (B, C)

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected