gensbi.models.core.patching#
Invertible 2D patchify/depatchify — pure einops reshapes (no learned state).
Moved out of recipes.utils so model/flow code can depend on it without pulling in the recipes package (which imports gensbi.models, creating a cycle).
Functions#
|
Inverse of |
|
Patchify a 2D image into a sequence of non-overlapping patches. |
Module Contents#
- gensbi.models.core.patching.depatchify_2d(x, size=2, grid=None)[source]#
Inverse of
patchify_2d().- Parameters:
x (Array) – Patchified tensor of shape
(B, h*w, C*size*size).size (int) – Patch edge length used by
patchify_2d().grid (tuple of int, optional) – The
(h, w)patch grid. The grid cannot be inferred from the token count alone, so it is required for non-square grids. IfNone, a square grid (h == w) is assumed.
- Returns:
Image of shape
(B, H, W, C)whereH = h * sizeandW = w * size.- Return type:
Array
- Raises:
ValueError – If
gridisNoneand the token count is not a perfect square.
- gensbi.models.core.patching.patchify_2d(x, size=2)[source]#
Patchify a 2D image into a sequence of non-overlapping patches.
Invertible 2D patchify via einops reshape. The inverse operation is
depatchify_2d().- Parameters:
x (Array) – Image of shape
(B, H, W, C).HandWmust each be divisible bysize.size (int, optional) – Patch edge length. Default is 2.
- Returns:
Token sequence of shape
(B, T, F)whereT = (H // size) * (W // size)andF = C * size * size. Tokens are in raster (row-major) order.- Return type:
Array