tf.keras.ops.fold
Stay organized with collections
Save and categorize content based on your preferences.
Combines an array of sliding local blocks into a large containing tensor (reverses unfold).
tf.keras.ops.fold(
x, output_size, kernel_size, dilation=1, padding=0, stride=1
)
This operation is known as col2im when used with convolution.
It takes a 3-D tensor of flattened patches and reconstructs a 4-D
image tensor by summing overlapping patches.
Args |
x
|
A 3-D tensor of shape (N, C * kH * kW, L) where L is
the total number of blocks.
|
output_size
|
int or tuple of two ints (oH, oW), the spatial
shape of the output tensor.
|
kernel_size
|
int or tuple of two ints, the size of the sliding
window (kH, kW). If a single int is given, it is used
for both dimensions.
|
dilation
|
int or tuple of two ints, the spacing between kernel
points. Default: 1.
|
padding
|
int or tuple of two ints, the amount of zero-padding
that was applied to the input of unfold. Default: 0.
|
stride
|
int or tuple of two ints, the step size of the sliding
window. Default: 1.
|
Returns |
A 4-D tensor of shape (N, C, oH, oW).
|
Example:
x = keras.ops.ones((1, 2, 4, 4))
patches = keras.ops.unfold(x, kernel_size=2, stride=2)
patches.shape
(1, 8, 4)
y = keras.ops.fold(patches, output_size=(4, 4),
kernel_size=2, stride=2)
y.shape
(1, 2, 4, 4)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]