MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / batch_normalization

Function batch_normalization

tensorflow/python/ops/nn_impl.py:1474–1533  ·  view source on GitHub ↗

r"""Batch normalization. Normalizes a tensor by `mean` and `variance`, and applies (optionally) a `scale` \\(\gamma\\) to it, as well as an `offset` \\(\beta\\): \\(\frac{\gamma(x-\mu)}{\sigma}+\beta\\) `mean`, `variance`, `offset` and `scale` are all expected to be of one of two shapes

(x,
                        mean,
                        variance,
                        offset,
                        scale,
                        variance_epsilon,
                        name=None)

Source from the content-addressed store, hash-verified

1472
1473@tf_export("nn.batch_normalization")
1474def batch_normalization(x,
1475 mean,
1476 variance,
1477 offset,
1478 scale,
1479 variance_epsilon,
1480 name=None):
1481 r"""Batch normalization.
1482
1483 Normalizes a tensor by `mean` and `variance`, and applies (optionally) a
1484 `scale` \\(\gamma\\) to it, as well as an `offset` \\(\beta\\):
1485
1486 \\(\frac{\gamma(x-\mu)}{\sigma}+\beta\\)
1487
1488 `mean`, `variance`, `offset` and `scale` are all expected to be of one of two
1489 shapes:
1490
1491 * In all generality, they can have the same number of dimensions as the
1492 input `x`, with identical sizes as `x` for the dimensions that are not
1493 normalized over (the 'depth' dimension(s)), and dimension 1 for the
1494 others which are being normalized over.
1495 `mean` and `variance` in this case would typically be the outputs of
1496 `tf.nn.moments(..., keep_dims=True)` during training, or running averages
1497 thereof during inference.
1498 * In the common case where the 'depth' dimension is the last dimension in
1499 the input tensor `x`, they may be one dimensional tensors of the same
1500 size as the 'depth' dimension.
1501 This is the case for example for the common `[batch, depth]` layout of
1502 fully-connected layers, and `[batch, height, width, depth]` for
1503 convolutions.
1504 `mean` and `variance` in this case would typically be the outputs of
1505 `tf.nn.moments(..., keep_dims=False)` during training, or running averages
1506 thereof during inference.
1507
1508 See Source: [Batch Normalization: Accelerating Deep Network Training by
1509 Reducing Internal Covariate Shift; S. Ioffe, C. Szegedy]
1510 (http://arxiv.org/abs/1502.03167).
1511
1512 Args:
1513 x: Input `Tensor` of arbitrary dimensionality.
1514 mean: A mean `Tensor`.
1515 variance: A variance `Tensor`.
1516 offset: An offset `Tensor`, often denoted \\(\beta\\) in equations, or
1517 None. If present, will be added to the normalized tensor.
1518 scale: A scale `Tensor`, often denoted \\(\gamma\\) in equations, or
1519 `None`. If present, the scale is applied to the normalized tensor.
1520 variance_epsilon: A small float number to avoid dividing by 0.
1521 name: A name for this operation (optional).
1522
1523 Returns:
1524 the normalized, scaled, offset tensor.
1525 """
1526 with ops.name_scope(name, "batchnorm", [x, mean, variance, scale, offset]):
1527 inv = math_ops.rsqrt(variance + variance_epsilon)
1528 if scale is not None:
1529 inv *= scale
1530 # Note: tensorflow/contrib/quantize/python/fold_batch_norms.py depends on
1531 # the precise order of ops that are generated by the expression below.

Callers 1

Calls 2

name_scopeMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected