r"""Applies Batch Normalization over a 5d input that is seen as a mini-batch of 4d inputs .. math:: y = \frac{x - mean[x]}{ \sqrt{Var[x] + \epsilon}} * gamma + beta This module differs from the built-in PyTorch BatchNorm3d as the mean and standard-deviation are reduced acr
| 266 | |
| 267 | |
| 268 | class SynchronizedBatchNorm3d(_SynchronizedBatchNorm): |
| 269 | r"""Applies Batch Normalization over a 5d input that is seen as a mini-batch |
| 270 | of 4d inputs |
| 271 | |
| 272 | .. math:: |
| 273 | |
| 274 | y = \frac{x - mean[x]}{ \sqrt{Var[x] + \epsilon}} * gamma + beta |
| 275 | |
| 276 | This module differs from the built-in PyTorch BatchNorm3d as the mean and |
| 277 | standard-deviation are reduced across all devices during training. |
| 278 | |
| 279 | For example, when one uses `nn.DataParallel` to wrap the network during |
| 280 | training, PyTorch's implementation normalize the tensor on each device using |
| 281 | the statistics only on that device, which accelerated the computation and |
| 282 | is also easy to implement, but the statistics might be inaccurate. |
| 283 | Instead, in this synchronized version, the statistics will be computed |
| 284 | over all training samples distributed on multiple devices. |
| 285 | |
| 286 | Note that, for one-GPU or CPU-only case, this module behaves exactly same |
| 287 | as the built-in PyTorch implementation. |
| 288 | |
| 289 | The mean and standard-deviation are calculated per-dimension over |
| 290 | the mini-batches and gamma and beta are learnable parameter vectors |
| 291 | of size C (where C is the input size). |
| 292 | |
| 293 | During training, this layer keeps a running estimate of its computed mean |
| 294 | and variance. The running sum is kept with a default momentum of 0.1. |
| 295 | |
| 296 | During evaluation, this running mean/variance is used for normalization. |
| 297 | |
| 298 | Because the BatchNorm is done over the `C` dimension, computing statistics |
| 299 | on `(N, D, H, W)` slices, it's common terminology to call this Volumetric BatchNorm |
| 300 | or Spatio-temporal BatchNorm |
| 301 | |
| 302 | Args: |
| 303 | num_features: num_features from an expected input of |
| 304 | size batch_size x num_features x depth x height x width |
| 305 | eps: a value added to the denominator for numerical stability. |
| 306 | Default: 1e-5 |
| 307 | momentum: the value used for the running_mean and running_var |
| 308 | computation. Default: 0.1 |
| 309 | affine: a boolean value that when set to ``True``, gives the layer learnable |
| 310 | affine parameters. Default: ``True`` |
| 311 | |
| 312 | Shape: |
| 313 | - Input: :math:`(N, C, D, H, W)` |
| 314 | - Output: :math:`(N, C, D, H, W)` (same shape as input) |
| 315 | |
| 316 | Examples: |
| 317 | >>> # With Learnable Parameters |
| 318 | >>> m = SynchronizedBatchNorm3d(100) |
| 319 | >>> # Without Learnable Parameters |
| 320 | >>> m = SynchronizedBatchNorm3d(100, affine=False) |
| 321 | >>> input = torch.autograd.Variable(torch.randn(20, 100, 35, 45, 10)) |
| 322 | >>> output = m(input) |
| 323 | """ |
| 324 | |
| 325 | def _check_input_dim(self, input): |
nothing calls this directly
no outgoing calls
no test coverage detected