Split a channel-first image batch of shape (batch, channels, height, width) into non-overlapping rectangular patches. Patch-grid order is row first, then column. Within each patch, flatten by channel, local row, then local column.
Coordinates contain zero-based patch-grid positions, not pixel positions: each row is [grid row, grid column] in the same order as the tokens. The patch count is the number of patch rows multiplied by the number of patch columns; these coordinates are shared across the batch.
Return a Python dictionary of PyTorch tensors: tokens has shape (batch, patch_count, channels * patch_height * patch_width) and preserves the image dtype; coordinates has shape (patch_count, 2) and int64 dtype. Both outputs stay on the image device.
Input: images = [[[[0,1,2,3],[4,5,6,7]]]], patch_height = 1, patch_width = 2
Output: {"tokens":[[[0,1],[2,3],[4,5],[6,7]]],"coordinates":[[0,0],[0,1],[1,0],[1,1]]}
Explanation: The 2 by 4 image contains four row-major patches of shape 1 by 2.
Input: images = [[[[1,2],[3,4]],[[5,6],[7,8]]]], patch_height = 2, patch_width = 1
Output: {"tokens":[[[1,3,5,7],[2,4,6,8]]],"coordinates":[[0,0],[0,1]]}
Input: images = [[[[0,1,2],[3,4,5]]]], patch_height = 2, patch_width = 3
Output: {"tokens":[[[0,1,2,3,4,5]]],"coordinates":[[0,0]]}
Tensor.reshape can separate grid dimensions from within-patch dimensions.
Tensor.permute reorders tensor axes.
torch.meshgrid supports matrix-style row and column indexing.
Accepts: array
Accepts: number
Accepts: number
Split a channel-first image batch of shape (batch, channels, height, width) into non-overlapping rectangular patches. Patch-grid order is row first, then column. Within each patch, flatten by channel, local row, then local column.
Coordinates contain zero-based patch-grid positions, not pixel positions: each row is [grid row, grid column] in the same order as the tokens. The patch count is the number of patch rows multiplied by the number of patch columns; these coordinates are shared across the batch.
Return a Python dictionary of PyTorch tensors: tokens has shape (batch, patch_count, channels * patch_height * patch_width) and preserves the image dtype; coordinates has shape (patch_count, 2) and int64 dtype. Both outputs stay on the image device.
Input: images = [[[[0,1,2,3],[4,5,6,7]]]], patch_height = 1, patch_width = 2
Output: {"tokens":[[[0,1],[2,3],[4,5],[6,7]]],"coordinates":[[0,0],[0,1],[1,0],[1,1]]}
Explanation: The 2 by 4 image contains four row-major patches of shape 1 by 2.
Input: images = [[[[1,2],[3,4]],[[5,6],[7,8]]]], patch_height = 2, patch_width = 1
Output: {"tokens":[[[1,3,5,7],[2,4,6,8]]],"coordinates":[[0,0],[0,1]]}
Input: images = [[[[0,1,2],[3,4,5]]]], patch_height = 2, patch_width = 3
Output: {"tokens":[[[0,1,2,3,4,5]]],"coordinates":[[0,0]]}
Tensor.reshape can separate grid dimensions from within-patch dimensions.
Tensor.permute reorders tensor axes.
torch.meshgrid supports matrix-style row and column indexing.
Accepts: array
Accepts: number
Accepts: number