Performs the avg pooling on the input. Each entry in `output` is the mean of the corresponding size `ksize` window in `value`. Args: input: Tensor of rank N+2, of shape `[batch_size] + input_spatial_shape + [num_channels]` if `data_format` does not start with "NC" (default), or
(input, ksize, strides, padding, data_format=None, name=None)
| 3578 | |
| 3579 | @tf_export("nn.avg_pool", v1=["nn.avg_pool_v2"]) |
| 3580 | def avg_pool_v2(input, ksize, strides, padding, data_format=None, name=None): # pylint: disable=redefined-builtin |
| 3581 | """Performs the avg pooling on the input. |
| 3582 | |
| 3583 | Each entry in `output` is the mean of the corresponding size `ksize` |
| 3584 | window in `value`. |
| 3585 | |
| 3586 | Args: |
| 3587 | input: Tensor of rank N+2, of shape `[batch_size] + input_spatial_shape + |
| 3588 | [num_channels]` if `data_format` does not start with "NC" (default), or |
| 3589 | `[batch_size, num_channels] + input_spatial_shape` if data_format starts |
| 3590 | with "NC". Pooling happens over the spatial dimensions only. |
| 3591 | ksize: An int or list of `ints` that has length `1`, `N` or `N+2`. The size |
| 3592 | of the window for each dimension of the input tensor. |
| 3593 | strides: An int or list of `ints` that has length `1`, `N` or `N+2`. The |
| 3594 | stride of the sliding window for each dimension of the input tensor. |
| 3595 | padding: A string, either `'VALID'` or `'SAME'`. The padding algorithm. See |
| 3596 | the "returns" section of `tf.nn.convolution` for details. |
| 3597 | data_format: A string. Specifies the channel dimension. For N=1 it can be |
| 3598 | either "NWC" (default) or "NCW", for N=2 it can be either "NHWC" (default) |
| 3599 | or "NCHW" and for N=3 either "NDHWC" (default) or "NCDHW". |
| 3600 | name: Optional name for the operation. |
| 3601 | |
| 3602 | Returns: |
| 3603 | A `Tensor` of format specified by `data_format`. |
| 3604 | The average pooled output tensor. |
| 3605 | """ |
| 3606 | if input.shape is not None: |
| 3607 | n = len(input.shape) - 2 |
| 3608 | elif data_format is not None: |
| 3609 | n = len(data_format) - 2 |
| 3610 | else: |
| 3611 | raise ValueError( |
| 3612 | "The input must have a rank or a data format must be given.") |
| 3613 | if not 1 <= n <= 3: |
| 3614 | raise ValueError( |
| 3615 | "Input tensor must be of rank 3, 4 or 5 but was {}.".format(n + 2)) |
| 3616 | |
| 3617 | if data_format is None: |
| 3618 | channel_index = n + 1 |
| 3619 | else: |
| 3620 | channel_index = 1 if data_format.startswith("NC") else n + 1 |
| 3621 | |
| 3622 | ksize = _get_sequence(ksize, n, channel_index, "ksize") |
| 3623 | strides = _get_sequence(strides, n, channel_index, "strides") |
| 3624 | |
| 3625 | avg_pooling_ops = { |
| 3626 | 1: avg_pool1d, |
| 3627 | 2: gen_nn_ops.avg_pool, |
| 3628 | 3: gen_nn_ops.avg_pool3d |
| 3629 | } |
| 3630 | |
| 3631 | op = avg_pooling_ops[n] |
| 3632 | return op( |
| 3633 | input, |
| 3634 | ksize=ksize, |
| 3635 | strides=strides, |
| 3636 | padding=padding, |
| 3637 | data_format=data_format, |
nothing calls this directly
no test coverage detected