@@ -120,6 +120,40 @@ def __init__(
120120 super ().__init__ (tf .reduce_mean , output_size , data_format , ** kwargs )
121121
122122
123+ @tf .keras .utils .register_keras_serializable (package = "Addons" )
124+ class AdaptiveMaxPooling1D (AdaptivePooling1D ):
125+ """Max Pooling with adaptive kernel size.
126+
127+ Arguments:
128+ output_size: An integer or tuple/list of a single integer, specifying pooled_features.
129+ The new size of output channels.
130+ data_format: A string,
131+ one of `channels_last` (default) or `channels_first`.
132+ The ordering of the dimensions in the inputs.
133+ `channels_last` corresponds to inputs with shape
134+ `(batch, steps, channels)` while `channels_first`
135+ corresponds to inputs with shape `(batch, channels, steps)`.
136+
137+ Input shape:
138+ - If `data_format='channels_last'`:
139+ 3D tensor with shape `(batch, steps, channels)`.
140+ - If `data_format='channels_first'`:
141+ 3D tensor with shape `(batch, channels, steps)`.
142+
143+ Output shape:
144+ - If `data_format='channels_last'`:
145+ 3D tensor with shape `(batch_size, pooled_steps, channels)`.
146+ - If `data_format='channels_first'`:
147+ 3D tensor with shape `(batch_size, channels, pooled_steps)`.
148+ """
149+
150+ @typechecked
151+ def __init__ (
152+ self , output_size : Union [int , Iterable [int ]], data_format = None , ** kwargs
153+ ):
154+ super ().__init__ (tf .reduce_max , output_size , data_format , ** kwargs )
155+
156+
123157class AdaptivePooling2D (tf .keras .layers .Layer ):
124158 """Parent class for 2D pooling layers with adaptive kernel size.
125159
@@ -234,6 +268,40 @@ def __init__(
234268 super ().__init__ (tf .reduce_mean , output_size , data_format , ** kwargs )
235269
236270
271+ @tf .keras .utils .register_keras_serializable (package = "Addons" )
272+ class AdaptiveMaxPooling2D (AdaptivePooling2D ):
273+ """Max Pooling with adaptive kernel size.
274+
275+ Arguments:
276+ output_size: Tuple of integers specifying (pooled_rows, pooled_cols).
277+ The new size of output channels.
278+ data_format: A string,
279+ one of `channels_last` (default) or `channels_first`.
280+ The ordering of the dimensions in the inputs.
281+ `channels_last` corresponds to inputs with shape
282+ `(batch, height, width, channels)` while `channels_first`
283+ corresponds to inputs with shape `(batch, channels, height, width)`.
284+
285+ Input shape:
286+ - If `data_format='channels_last'`:
287+ 4D tensor with shape `(batch_size, height, width, channels)`.
288+ - If `data_format='channels_first'`:
289+ 4D tensor with shape `(batch_size, channels, height, width)`.
290+
291+ Output shape:
292+ - If `data_format='channels_last'`:
293+ 4D tensor with shape `(batch_size, pooled_rows, pooled_cols, channels)`.
294+ - If `data_format='channels_first'`:
295+ 4D tensor with shape `(batch_size, channels, pooled_rows, pooled_cols)`.
296+ """
297+
298+ @typechecked
299+ def __init__ (
300+ self , output_size : Union [int , Iterable [int ]], data_format = None , ** kwargs
301+ ):
302+ super ().__init__ (tf .reduce_max , output_size , data_format , ** kwargs )
303+
304+
237305class AdaptivePooling3D (tf .keras .layers .Layer ):
238306 """Parent class for 3D pooling layers with adaptive kernel size.
239307
@@ -353,3 +421,37 @@ def __init__(
353421 self , output_size : Union [int , Iterable [int ]], data_format = None , ** kwargs
354422 ):
355423 super ().__init__ (tf .reduce_mean , output_size , data_format , ** kwargs )
424+
425+
426+ @tf .keras .utils .register_keras_serializable (package = "Addons" )
427+ class AdaptiveMaxPooling3D (AdaptivePooling3D ):
428+ """Max Pooling with adaptive kernel size.
429+
430+ Arguments:
431+ output_size: An integer or tuple/list of 3 integers specifying (pooled_depth, pooled_height, pooled_width).
432+ The new size of output channels.
433+ data_format: A string,
434+ one of `channels_last` (default) or `channels_first`.
435+ The ordering of the dimensions in the inputs.
436+ `channels_last` corresponds to inputs with shape
437+ `(batch, height, width, channels)` while `channels_first`
438+ corresponds to inputs with shape `(batch, channels, height, width)`.
439+
440+ Input shape:
441+ - If `data_format='channels_last'`:
442+ 5D tensor with shape `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)`.
443+ - If `data_format='channels_first'`:
444+ 5D tensor with shape `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.
445+
446+ Output shape:
447+ - If `data_format='channels_last'`:
448+ 5D tensor with shape `(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)`.
449+ - If `data_format='channels_first'`:
450+ 5D tensor with shape `(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)`.
451+ """
452+
453+ @typechecked
454+ def __init__ (
455+ self , output_size : Union [int , Iterable [int ]], data_format = None , ** kwargs
456+ ):
457+ super ().__init__ (tf .reduce_max , output_size , data_format , ** kwargs )
0 commit comments