def _get_moments(self, x): mean = mean_dim(x.clone(), dim=[0, 2, 3], keepdims=True) var = mean_dim((x.clone() - mean)**2, dim=[0, 2, 3], keepdims=True) log_std = torch.log( 1. / (var.sqrt() + self.eps) / self.log_scale) * self.log_scale return mean, log_std
def initialize_parameters(self, x): if not self.training: return with torch.no_grad(): bias = -mean_dim(x.clone(), dim=[0, 2, 3], keepdims=True) v = mean_dim((x.clone() + bias) ** 2, dim=[0, 2, 3], keepdims=True) logs = (self.scale / (v.sqrt() + self.eps)).log() self.bias.data.copy_(bias.data) self.logs.data.copy_(logs.data) self.is_initialized += 1.
def _get_moments(self, x): mean = mean_dim(x.clone(), dim=[0, 2, 3], keepdims=True) var = mean_dim((x.clone() - mean) ** 2, dim=[0, 2, 3], keepdims=True) inv_std = 1. / (var.sqrt() + self.eps) return mean, inv_std