Efficient spatial feature extraction
Image classification models
Keras · Class
SeparableConv2D applies a depthwise spatial convolution followed by a pointwise channel-mixing convolution. It optionally adds bias and applies an activation.
SeparableConv2D first applies a spatial depthwise convolution independently to each input channel, then a pointwise convolution combines those intermediate channels into the requested number of filters. It can add a bias and apply an activation after the convolution.
keras.layers.SeparableConv2D(filters, kernel_size, strides=(1, 1), padding="valid", data_format=None, dilation_rate=(1, 1), depth_multiplier=1, activation=None, use_bias=True, depthwise_initializer="glorot_uniform", pointwise_initializer="glorot_uniform", bias_initializer="zeros", depthwise_regularizer=None, pointwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, pointwise_constraint=None, bias_constraint=None, **kwargs)| Name | Type | Description |
|---|---|---|
filters | int | Number of filters in the pointwise convolution and therefore the output channels. |
kernel_size | int or tuple/list of 2 integers | Height and width of the depthwise convolution window; an integer or a pair of integers. |
strides | int or tuple/list of 2 integers | Depthwise convolution stride; an integer or a pair of integers. |
padding | string | Padding mode, typically "valid" or "same". |
data_format | string or None | Input and output channel layout. |
dilation_rate | int or tuple/list of 2 integers | Dilation factor for the depthwise convolution. |
depth_multiplier | int | Number of depthwise output channels generated per input channel. |
activation | string, callable, or None | Optional activation function. |
use_bias | bool | Whether to add a bias vector. |
depthwise_initializer | string or initializer | Initializer for the depthwise kernel. |
pointwise_initializer | string or initializer | Initializer for the pointwise kernel. |
bias_initializer | string or initializer | Initializer for the bias. |
A rank-4 tensor representing activation(separable_conv2d(inputs, kernel) + bias); its channel axis depends on data_format.
use_bias.filters sets the number of output channels produced by the pointwise stage.kernel_size determines the height and width of the depthwise spatial window.import keras
from keras import layers
inputs = keras.Input(shape=(32, 32, 3))
x = layers.SeparableConv2D(32, 3, padding="same", activation="relu")(inputs)
outputs = layers.GlobalAveragePooling2D()(x)
model = keras.Model(inputs, outputs)
model.summary()Creates a model whose separable convolution preserves the spatial dimensions while producing 32 output channels.
Image classification models
Convolutional blocks with limited compute or parameters
Vision models requiring channel mixing after per-channel spatial filtering
It splits convolution into two operations: depthwise convolution processes channels independently, and pointwise convolution mixes the resulting channels. This reduces the structure of a standard convolution while still producing the requested number of output filters.
Follow-up: What controls depthwise expansion? The depth_multiplier sets how many depthwise output channels are generated for each input channel.
filters and kernel_size control?filters determines the output channel count because it is the dimensionality of the pointwise convolution's output space. kernel_size specifies the two-dimensional depthwise window.
Follow-up: How would you preserve height and width? Use padding="same" with the usual unit strides, subject to the layer's padding and shape rules.
With channels-last data, the result is a rank-4 tensor shaped (batch_size, new_height, new_width, filters). With channels-first data, the result is (batch_size, filters, new_height, new_width).
Follow-up: What does the layer return conceptually? It returns the activation applied to the separable convolution result plus bias when bias is enabled.
SeparableConv1DDepthwiseConv2DConv2Dkeras.ops.separable_conv