def forward(self, input): axis = _check_axis(self.dim, input.shape) if isinstance(axis, list) and len(axis) == 0: return flow.experimental.zeros(size=input.shape) else: return flow.experimental.sub( flow.experimental.mean(flow.experimental.square(input), axis, self.keepdim), flow.experimental.square( flow.experimental.mean(input, axis, self.keepdim)), )
def forward(self, input): axis_checked = _check_axis(self.axis, input.shape) if len(axis_checked) == 0: return input reduce_sum = flow.experimental.sum(input, dim=self.axis, keepdim=self.keepdims) reduce_count = 1 if len(self.axes) == 0: for dim in input.shape: reduce_count *= dim else: for i in self.axes: reduce_count *= input.shape[i] return flow.experimental.mul(reduce_sum, 1.0 / reduce_count)
def forward(self, x): self.axis = _check_axis(self.dim, x.shape) if isinstance(self.axis, list) and len(self.axis) == 0: return flow.experimental.zeros(size=x.shape) else: if len(self.axis) == 0: self.reduce_count = x.nelement() else: for i in self.axis: self.reduce_count *= x.shape[i] sum = Sum(self.axis, self.keepdim)( self.square_op(x)) / self.reduce_count square = self.square_op( Sum(self.axis, self.keepdim)(x) / self.reduce_count) subtract = self.subtract_op(sum, square) res = self.sqrt_op(subtract) return res
def forward(self, input): axis_checked = _check_axis(self.axis, input.shape) if len(axis_checked) == 0: return input return self._op(input, axis=axis_checked)[0]