Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/keras/src/layers/pooling/global_max_pooling3d.py: 73%

11 statements  

« 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"""Global max pooling 3D layer.""" 

16 

17 

18from keras.src import backend 

19from keras.src.layers.pooling.base_global_pooling3d import GlobalPooling3D 

20 

21# isort: off 

22from tensorflow.python.util.tf_export import keras_export 

23 

24 

25@keras_export("keras.layers.GlobalMaxPooling3D", "keras.layers.GlobalMaxPool3D") 

26class GlobalMaxPooling3D(GlobalPooling3D): 

27 """Global Max pooling operation for 3D data. 

28 

29 Args: 

30 data_format: A string, 

31 one of `channels_last` (default) or `channels_first`. 

32 The ordering of the dimensions in the inputs. 

33 `channels_last` corresponds to inputs with shape 

34 `(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)` 

35 while `channels_first` corresponds to inputs with shape 

36 `(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)`. 

37 It defaults to the `image_data_format` value found in your 

38 Keras config file at `~/.keras/keras.json`. 

39 If you never set it, then it will be "channels_last". 

40 keepdims: A boolean, whether to keep the spatial dimensions or not. 

41 If `keepdims` is `False` (default), the rank of the tensor is reduced 

42 for spatial dimensions. 

43 If `keepdims` is `True`, the spatial dimensions are retained with 

44 length 1. 

45 The behavior is the same as for `tf.reduce_max` or `np.max`. 

46 

47 Input shape: 

48 - If `data_format='channels_last'`: 

49 5D tensor with shape: 

50 `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)` 

51 - If `data_format='channels_first'`: 

52 5D tensor with shape: 

53 `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)` 

54 

55 Output shape: 

56 - If `keepdims`=False: 

57 2D tensor with shape `(batch_size, channels)`. 

58 - If `keepdims`=True: 

59 - If `data_format='channels_last'`: 

60 5D tensor with shape `(batch_size, 1, 1, 1, channels)` 

61 - If `data_format='channels_first'`: 

62 5D tensor with shape `(batch_size, channels, 1, 1, 1)` 

63 """ 

64 

65 def call(self, inputs): 

66 if self.data_format == "channels_last": 

67 return backend.max(inputs, axis=[1, 2, 3], keepdims=self.keepdims) 

68 else: 

69 return backend.max(inputs, axis=[2, 3, 4], keepdims=self.keepdims) 

70 

71 

72# Alias 

73 

74GlobalMaxPool3D = GlobalMaxPooling3D 

75