Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/keras/src/layers/merging/minimum.py: 64%

14 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"""Layer that computes the minimum (element-wise) of several inputs.""" 

16 

17 

18import tensorflow.compat.v2 as tf 

19 

20from keras.src.layers.merging.base_merge import _Merge 

21 

22# isort: off 

23from tensorflow.python.util.tf_export import keras_export 

24 

25 

26@keras_export("keras.layers.Minimum") 

27class Minimum(_Merge): 

28 """Layer that computes the minimum (element-wise) a list of inputs. 

29 

30 It takes as input a list of tensors, all of the same shape, and returns 

31 a single tensor (also of the same shape). 

32 

33 >>> tf.keras.layers.Minimum()([np.arange(5).reshape(5, 1), 

34 ... np.arange(5, 10).reshape(5, 1)]) 

35 <tf.Tensor: shape=(5, 1), dtype=int64, numpy= 

36 array([[0], 

37 [1], 

38 [2], 

39 [3], 

40 [4]])> 

41 

42 >>> x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2)) 

43 >>> x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2)) 

44 >>> minned = tf.keras.layers.Minimum()([x1, x2]) 

45 >>> minned.shape 

46 TensorShape([5, 8]) 

47 """ 

48 

49 def _merge_function(self, inputs): 

50 output = inputs[0] 

51 for i in range(1, len(inputs)): 

52 output = tf.minimum(output, inputs[i]) 

53 return output 

54 

55 

56@keras_export("keras.layers.minimum") 

57def minimum(inputs, **kwargs): 

58 """Functional interface to the `Minimum` layer. 

59 

60 Args: 

61 inputs: A list of input tensors. 

62 **kwargs: Standard layer keyword arguments. 

63 

64 Returns: 

65 A tensor, the element-wise minimum of the inputs. 

66 """ 

67 return Minimum(**kwargs)(inputs) 

68