Gradient for Mean.
(op, grad)
| 233 | |
| 234 | @ops.RegisterGradient("Mean") |
| 235 | def _MeanGrad(op, grad): |
| 236 | """Gradient for Mean.""" |
| 237 | sum_grad = _SumGrad(op, grad)[0] |
| 238 | input_shape = op.inputs[0]._shape_tuple() # pylint: disable=protected-access |
| 239 | output_shape = op.outputs[0]._shape_tuple() # pylint: disable=protected-access |
| 240 | if (input_shape is not None and output_shape is not None and |
| 241 | None not in input_shape and None not in output_shape): |
| 242 | input_size = np.prod(input_shape) |
| 243 | output_size = np.prod(output_shape) |
| 244 | factor = input_size // max(output_size, 1) |
| 245 | factor = constant_op.constant(factor, dtype=sum_grad.dtype) |
| 246 | else: |
| 247 | input_shape = array_ops.shape(op.inputs[0]) |
| 248 | output_shape = array_ops.shape(op.outputs[0]) |
| 249 | factor = _safe_shape_div( |
| 250 | math_ops.reduce_prod(input_shape), math_ops.reduce_prod(output_shape)) |
| 251 | return math_ops.truediv(sum_grad, math_ops.cast(factor, sum_grad.dtype)), None |
| 252 | |
| 253 | |
| 254 | @ops.RegisterGradient("Prod") |
nothing calls this directly
no test coverage detected