def forward(self, x, add_noise=False): h = x if self.blur_k is None: k = np.asarray([1, 2, 1]).astype('f') k = k[:, None] * k[None, :] k = k / np.sum(k) self.blur_k = self.xp.asarray(k)[None, None, :] if self.enable_blur: h = blur(upscale2x(h), self.blur_k) else: h = upscale2x(h) h = self.c0(h) # h should be (batch, ch, size, size) if add_noise: h = self.n0(h) h = F.leaky_relu(self.b0(h)) h = F.normalize(h) h = self.c1(h) if add_noise: h = self.n1(h) h = F.leaky_relu(self.b1(h)) h = F.normalize(h) return h
def __call__(self, w, x=None, add_noise=False): h = x batch_size, _ = w.shape if self.upsample: assert h is not None if self.blur_k is None: k = np.asarray([1, 2, 1]).astype('f') k = k[:, None] * k[None, :] k = k / np.sum(k) self.blur_k = self.xp.asarray(k)[None, None, :] if self.enable_blur: h = blur(upscale2x(h), self.blur_k) else: h = upscale2x(h) h = self.c0(h) else: h = F.broadcast_to(self.W, (batch_size, self.ch_in, 4, 4)) # h should be (batch, ch, size, size) if add_noise: h = self.n0(h) h = F.leaky_relu(self.b0(h)) h = self.s0(w, h) h = self.c1(h) if add_noise: h = self.n1(h) h = F.leaky_relu(self.b1(h)) h = self.s1(w, h) return h
def __call__(self, x): h = x h = F.leaky_relu((self.c0(h))) h = F.leaky_relu((self.c1(h))) if self.blur_k is None: k = np.asarray([1, 2, 1]).astype('f') k = k[:, None] * k[None, :] k = k / np.sum(k) self.blur_k = self.xp.asarray(k)[None, None, :] if self.enable_blur: h = blur(downscale2x(h), self.blur_k) else: h = downscale2x(h) return h
def forward(self, x): shortcut = self.c_sc(x) res = F.leaky_relu((self.c0(x))) h = F.leaky_relu((self.c1(res) + shortcut)) if self.blur_k is None: k = np.asarray([1, 2, 1]).astype('f') k = k[:, None] * k[None, :] k = k / np.sum(k) self.blur_k = self.xp.asarray(k)[None, None, :] if self.enable_blur: h = blur(downscale2x(h), self.blur_k) else: h = downscale2x(h) return h