View source on GitHub
|
2D convolution layer.
Inherits From: Layer, Operation
tf.keras.layers.Conv2D(
filters,
kernel_size,
strides=(1, 1),
padding='valid',
data_format=None,
dilation_rate=(1, 1),
groups=1,
activation=None,
use_bias=True,
kernel_initializer='glorot_uniform',
bias_initializer='zeros',
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs
)
Used in the notebooks
| Used in the guide | Used in the tutorials |
|---|---|
This layer creates a convolution kernel that is convolved with the layer
input over a 2D spatial (or temporal) dimension (height and width) to
produce a tensor of outputs. If use_bias is True, a bias vector is created
and added to the outputs. Finally, if activation is not None, it is
applied to the outputs as well.
Note on numerical precision: While in general Keras operation execution
results are identical across backends up to 1e-7 precision in float32,
Conv2D operations may show larger variations. Due to the large
number of element-wise multiplications and additions in convolution
operations, especially with large inputs or kernel sizes, accumulated
floating-point differences can exceed this 1e-7 threshold. These variations
are particularly noticeable when using different backends (e.g., TensorFlow
vs JAX) or different hardware.
Input shape:
- If
data_format="channels_last": A 4D tensor with shape:(batch_size, height, width, channels) - If
data_format="channels_first": A 4D tensor with shape:(batch_size, channels, height, width)
Output shape:
- If
data_format="channels_last": A 4D tensor with shape:(batch_size, new_height, new_width, filters) - If
data_format="channels_first": A 4D tensor with shape:(batch_size, filters, new_height, new_width)
Returns | |
|---|---|
A 4D tensor representing activation(conv2d(inputs, kernel) + bias).
|
Raises | |
|---|---|
ValueError
|
when both strides > 1 and dilation_rate > 1.
|
Example:
x = np.random.rand(4, 10, 10, 128)y = keras.layers.Conv2D(32, 3, activation='relu')(x)print(y.shape)(4, 8, 8, 32)
Methods
convolution_op
convolution_op(
inputs, kernel
)
enable_lora
enable_lora(
rank,
lora_alpha=None,
a_initializer='he_uniform',
b_initializer='zeros'
)
from_config
@classmethodfrom_config( config )
Creates an operation from its config.
This method is the reverse of get_config, capable of instantiating the
same operation from the config dictionary.
if "dtype" in config and isinstance(config["dtype"], dict):
policy = dtype_policies.deserialize(config["dtype"])
| Args | |
|---|---|
config
|
A Python dictionary, typically the output of get_config.
|
| Returns | |
|---|---|
| An operation instance. |
View source on GitHub