Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/keras/src/layers/pooling/max_pooling3d.py: 89%
9 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Max pooling 3D layer."""
18import tensorflow.compat.v2 as tf
20from keras.src.layers.pooling.base_pooling3d import Pooling3D
22# isort: off
23from tensorflow.python.util.tf_export import keras_export
26@keras_export("keras.layers.MaxPooling3D", "keras.layers.MaxPool3D")
27class MaxPooling3D(Pooling3D):
28 """Max pooling operation for 3D data (spatial or spatio-temporal).
30 Downsamples the input along its spatial dimensions (depth, height, and
31 width) by taking the maximum value over an input window (of size defined by
32 `pool_size`) for each channel of the input. The window is shifted by
33 `strides` along each dimension.
35 Args:
36 pool_size: Tuple of 3 integers,
37 factors by which to downscale (dim1, dim2, dim3).
38 `(2, 2, 2)` will halve the size of the 3D input in each dimension.
39 strides: tuple of 3 integers, or None. Strides values.
40 padding: One of `"valid"` or `"same"` (case-insensitive).
41 `"valid"` means no padding. `"same"` results in padding evenly to
42 the left/right or up/down of the input such that output has the same
43 height/width dimension as the input.
44 data_format: A string,
45 one of `channels_last` (default) or `channels_first`.
46 The ordering of the dimensions in the inputs.
47 `channels_last` corresponds to inputs with shape
48 `(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)`
49 while `channels_first` corresponds to inputs with shape
50 `(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.
51 It defaults to the `image_data_format` value found in your
52 Keras config file at `~/.keras/keras.json`.
53 If you never set it, then it will be "channels_last".
55 Input shape:
56 - If `data_format='channels_last'`:
57 5D tensor with shape:
58 `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)`
59 - If `data_format='channels_first'`:
60 5D tensor with shape:
61 `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`
63 Output shape:
64 - If `data_format='channels_last'`:
65 5D tensor with shape:
66 `(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)`
67 - If `data_format='channels_first'`:
68 5D tensor with shape:
69 `(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)`
71 Example:
73 ```python
74 depth = 30
75 height = 30
76 width = 30
77 input_channels = 3
79 inputs = tf.keras.Input(shape=(depth, height, width, input_channels))
80 layer = tf.keras.layers.MaxPooling3D(pool_size=3)
81 outputs = layer(inputs) # Shape: (batch_size, 10, 10, 10, 3)
82 ```
83 """
85 def __init__(
86 self,
87 pool_size=(2, 2, 2),
88 strides=None,
89 padding="valid",
90 data_format=None,
91 **kwargs
92 ):
93 super().__init__(
94 tf.nn.max_pool3d,
95 pool_size=pool_size,
96 strides=strides,
97 padding=padding,
98 data_format=data_format,
99 **kwargs
100 )
103# Alias
105MaxPool3D = MaxPooling3D