MCPcopy Create free account
hub / github.com/deepbrainai-research/float / forward

Method forward

models/float/styledecoder.py:234–268  ·  view source on GitHub ↗
(self, input, style)

Source from the content-addressed store, hash-verified

232 )
233
234 def forward(self, input, style):
235 batch, in_channel, height, width = input.shape
236
237 style = self.modulation(style).view(batch, 1, in_channel, 1, 1)
238 weight = self.scale * self.weight * style
239
240 if self.demodulate:
241 demod = torch.rsqrt(weight.pow(2).sum([2, 3, 4]) + 1e-8)
242 weight = weight * demod.view(batch, self.out_channel, 1, 1, 1)
243
244 weight = weight.view(batch * self.out_channel, in_channel, self.kernel_size, self.kernel_size)
245
246 if self.upsample:
247 input = input.view(1, batch * in_channel, height, width)
248 weight = weight.view(batch, self.out_channel, in_channel, self.kernel_size, self.kernel_size)
249 weight = weight.transpose(1, 2).reshape(batch * in_channel, self.out_channel, self.kernel_size,
250 self.kernel_size)
251 out = F.conv_transpose2d(input, weight, padding=0, stride=2, groups=batch)
252 _, _, height, width = out.shape
253 out = out.view(batch, self.out_channel, height, width)
254 out = self.blur(out)
255 elif self.downsample:
256 input = self.blur(input)
257 _, _, height, width = input.shape
258 input = input.view(1, batch * in_channel, height, width)
259 out = F.conv2d(input, weight, padding=0, stride=2, groups=batch)
260 _, _, height, width = out.shape
261 out = out.view(batch, self.out_channel, height, width)
262 else:
263 input = input.view(1, batch * in_channel, height, width)
264 out = F.conv2d(input, weight, padding=self.padding, groups=batch)
265 _, _, height, width = out.shape
266 out = out.view(batch, self.out_channel, height, width)
267
268 return out
269
270
271class NoiseInjection(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected