MinimumPooling in Keras
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Keras includes MaxPooling and AveragePooling, but it does not ship a built-in MinimumPooling layer. When you need the smallest value from each spatial window, the practical solution is to build the behavior yourself from TensorFlow primitives rather than looking for a missing high-level layer.
Core Sections
What minimum pooling actually computes
Pooling reduces a feature map by summarizing local neighborhoods. Max pooling keeps the largest activation in each window. Average pooling keeps the mean. Minimum pooling keeps the smallest value.
For a 2 x 2 window like this:
minimum pooling returns 2.
That makes it useful only in fairly specific cases. In standard vision models, max pooling is far more common because it preserves strong activations. Minimum pooling emphasizes local low responses, so it is better suited to specialized signal-processing tasks, conservative mask reductions, or morphology-like operations.
The simplest implementation uses negative max pooling
The key identity is straightforward: the minimum of a set is the negative of the maximum of the negated set. In other words:
- '
min(x)equals-max(-x)'
That means you can implement minimum pooling with TensorFlow’s existing max-pooling operation.
This is the core idea behind most custom Keras solutions. It works because tf.nn.max_pool2d already handles efficient window traversal and supports gradient propagation.
Wrap it in a custom Keras layer
If the operation will appear in more than one place, a custom layer is cleaner than repeating a helper function. It also integrates better with model summaries and configuration.
The get_config method matters if you plan to save and reload the model. Without it, serializing the layer becomes harder.
Using the layer inside a model
Once wrapped, the layer behaves like any other Keras component.
This works because the custom layer is still composed of differentiable TensorFlow ops. Training, backpropagation, and model export all continue to function normally.
Shapes, padding, and where this layer fits
Output shape rules are exactly the same as for max pooling because the underlying operation is still tf.nn.max_pool2d. pool_size, strides, and padding control the result dimensions.
The design question is not shape compatibility but whether minimum pooling makes semantic sense for the model. In image classification, it often suppresses the strongest features and hurts performance. In tasks where low local values carry meaning, it can be useful.
A quick rule is this: if max pooling helps capture the presence of features, minimum pooling helps capture the presence of low-valued regions. Those are not interchangeable goals.
Common Pitfalls
- Looking for a built-in
tf.keras.layers.MinPooling2Dwastes time because Keras does not provide one. - Forgetting the double negation produces ordinary max pooling instead of minimum pooling.
- Omitting
get_configin a reusable custom layer makes serialization and reload workflows harder. - Using minimum pooling in a vision model without a data-driven reason often degrades accuracy because it preserves the weakest activation in each window.
- Passing inconsistent
padding,pool_size, orstridesvalues causes the same shape issues you would see with any other pooling layer.
Summary
- Keras has no native minimum-pooling layer, but TensorFlow primitives are enough to build one.
- The standard implementation is negative max pooling on negated inputs.
- A custom
Layerclass is the cleanest approach for reusable models. - Output shape behavior follows the same rules as max pooling.
- Minimum pooling is specialized and should be chosen because the data semantics require it, not as a generic alternative to max pooling.
Related reading
- MirroredStrategy doesn't use GPUs
- Mismatch in the calculated and the actual values of Output of the Softmax Activation Function in the Output Layer
- mlflow How to save a sklearn pipeline with custom transformer?
- MLPReLu stops learning after few iterations. Tensor Flow
- Mixing feed forward layers and recurrent layers in Tensorflow?
- mnist CNN ValueError expected min_ndim4, found ndim3. Full shape received 32, 28, 28
- Missing categorical data should be encoded with an all-zero one-hot vector
- Missing values in scikits machine learning
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.