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
def __call__(self, x, stage): ''' for alpha in [0, 1), and 2*k+2 + alpha < self.max_stage (-1 <= k <= ...): stage 0 + alpha : p <- block[0] <- in[0] * 1 stage 2*k+1 + alpha : p <- ... <- block[k] <- (up <- in[k]) * (1 - alpha) .................... <- (block[k+1] <- in[k+1]) * (alpha) stage 2*k+2 + alpha : p <- ............... <- (block[k+1] <- in[k+1]) * 1 over flow stages continues. ''' stage = min(stage, self.max_stage - 1e-8) alpha = stage - math.floor(stage) stage = math.floor(stage) h = x if stage % 2 == 0: k = (stage - 2) // 2 h = F.leaky_relu(self.ins[k + 1](h)) for i in reversed(range(0, (k + 1) + 1)): # k+1 .. 0 h = self.blocks[i](h) else: k = (stage - 1) // 2 h_0 = F.leaky_relu(self.ins[k](downscale2x(h))) h_1 = self.blocks[k + 1](F.leaky_relu(self.ins[k + 1](x))) assert 0. <= alpha < 1. h = (1.0 - alpha) * h_0 + alpha * h_1 for i in reversed(range(0, k + 1)): # k .. 0 h = self.blocks[i](h) return h
def forward(self, x, stage): ''' for alpha in [0, 1), and 2*k+2 + alpha < self.max_stage (-1 <= k <= ...): stage 0 + alpha : p <- block[0] <- in[0] * 1 stage 2*k+1 + alpha : p <- ... <- block[k] <- (up <- in[k]) * (1 - alpha) .................... <- (block[k+1] <- in[k+1]) * (alpha) stage 2*k+2 + alpha : p <- ............... <- (block[k+1] <- in[k+1]) * 1 over flow stages continues. ''' stage = min(stage, self.max_stage - 1e-8) alpha = stage - math.floor(stage) stage = math.floor(stage) h = x if stage % 2 == 0: k = (stage - 2) // 2 h = F.leaky_relu(self.ins[k + 1](h)) for i in reversed(range(0, k)): # k+1 .. 0 h = self.shared_blocks[i](h) else: k = (stage - 1) // 2 h_0 = F.leaky_relu(self.ins[k](downscale2x(h))) h_1 = self.shared_blocks[k - 1](F.leaky_relu(self.ins[k + 1](x))) assert 0. <= alpha < 1. h = (1.0 - alpha) * h_0 + alpha * h_1 for i in reversed(range(0, k - 1)): # k .. 0 h = self.shared_blocks[i](h) estimated_camera_parameter = self.camera_parameter_blocks(h) estimated_z = self.z_regression_blocks(h) h = self.discriminator_blocks(h) return h, estimated_camera_parameter, estimated_z
def forward(self, x, stage): ''' for alpha in [0, 1), and 2*k+2 + alpha < self.max_stage (-1 <= k <= ...): stage 0 + alpha : p <- block[0] <- in[0] * 1 stage 2*k+1 + alpha : p <- ... <- block[k] <- (up <- in[k]) * (1 - alpha) .................... <- (block[k+1] <- in[k+1]) * (alpha) stage 2*k+2 + alpha : p <- ............... <- (block[k+1] <- in[k+1]) * 1 over flow stages continues. ''' stage = min(stage, self.max_stage - 1e-8) alpha = stage - math.floor(stage) stage = math.floor(stage) h = x if stage % 2 == 0: k = (stage - 2) // 2 h = F.leaky_relu(self.ins[k + 1](h)) for i in reversed(range(0, (k + 1) + 1)): # k+1 .. 0 h = self.blocks[i](h) else: k = (stage - 1) // 2 h_0 = F.leaky_relu(self.ins[k](downscale2x(h))) h_1 = self.blocks[k + 1](F.leaky_relu(self.ins[k + 1](x))) assert 0. <= alpha < 1. h = (1.0 - alpha) * h_0 + alpha * h_1 for i in reversed(range(0, k + 1)): # k .. 0 h = self.blocks[i](h) inv_norm = F.rsqrt( F.square(h[:, -9:-6]) + F.square(h[:, -6:-3]) + 1e-8) camera_param = F.concat( [h[:, -9:-6] * inv_norm, h[:, -6:-3] * inv_norm, h[:, -3:]]) return h[:, :-9], camera_param
def forward(self, x, stage, return_hidden=False): ''' for alpha in [0, 1), and 2*k+2 + alpha < self.max_stage (-1 <= k <= ...): stage 0 + alpha : p <- block[0] <- in[0] * 1 stage 2*k+1 + alpha : p <- ... <- block[k] <- (up <- in[k]) * (1 - alpha) .................... <- (block[k+1] <- in[k+1]) * (alpha) stage 2*k+2 + alpha : p <- ............... <- (block[k+1] <- in[k+1]) * 1 over flow stages continues. ''' stage = min(stage, self.max_stage - 1e-8) alpha = stage - math.floor(stage) stage = math.floor(stage) h = x if stage % 2 == 0: k = (stage - 2) // 2 h = F.leaky_relu(self.ins[k + 1](h)) for i in reversed(range(0, (k + 1) + 1)): # k+1 .. 0 if i == 3: feat = h # for adversarial 3D consistency loss h = self.blocks[i](h) else: k = (stage - 1) // 2 h_0 = F.leaky_relu(self.ins[k](downscale2x(h))) h_1 = self.blocks[k + 1](F.leaky_relu(self.ins[k + 1](x))) assert 0. <= alpha < 1. h = (1.0 - alpha) * h_0 + alpha * h_1 for i in reversed(range(0, k + 1)): # k .. 0 if i == 3: feat = h # for adversarial 3D consistency loss h = self.blocks[i](h) if return_hidden: return h, feat return h